Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command: Manage categories while Editing a category template #67029

Open
wants to merge 29 commits into
base: trunk
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4b0bd79
Add command: Manage categories
karthick-murugan Nov 15, 2024
c42b7ef
Update Label
karthick-murugan Nov 15, 2024
63f81c1
Image size fix in lightbox
karthick-murugan Dec 3, 2024
0e19583
Revert "Image size fix in lightbox"
karthick-murugan Dec 3, 2024
f226ae0
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 4, 2024
d074ba9
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 5, 2024
4d847ca
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 5, 2024
c9115b2
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 5, 2024
b81e6ff
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 6, 2024
efe57e5
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 9, 2024
228e924
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 10, 2024
c448a21
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 11, 2024
05bb54c
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 12, 2024
619fed3
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 12, 2024
301d70f
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 18, 2024
c80640f
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 19, 2024
6ed9ff3
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 20, 2024
09b4cf2
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 20, 2024
27e4bbc
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 20, 2024
52f809e
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 23, 2024
e7679f1
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Dec 24, 2024
190b44e
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 2, 2025
26aafe7
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 6, 2025
fe1916c
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 8, 2025
58dddf5
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 9, 2025
ff6f5e1
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 20, 2025
c239ca4
Merge branch 'WordPress:trunk' into trunk
karthick-murugan Jan 21, 2025
5a15f6d
Merge branch 'trunk' of github.com:karthick-murugan/gutenberg into ad…
karthick-murugan Feb 27, 2025
17bd708
Feedback Changes updated
karthick-murugan Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
layout,
rotateRight,
rotateLeft,
category,
} from '@wordpress/icons';
import { useCommandLoader } from '@wordpress/commands';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -278,6 +279,53 @@ const getEditorCommandLoader = () =>
};
};

const getSiteEditorCategoryCommands = () =>
function useSiteEditorCategoryCommands() {
// Fetch the current template
const templateSlug = useSelect( ( select ) => {
const { getCurrentPost } = select( editorStore );
const currentTemplate = getCurrentPost();
return currentTemplate?.type === 'wp_template'
? currentTemplate.slug
: null;
}, [] );

const commands = [];

// Check if we are in the Site Editor and editing a category-related template
const isSiteEditor = window.location.href.includes( 'site-editor.php' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karthick-murugan I don't believe this is the correct way to determine if we are in the Site Editor.
When I search the code base, the common method I see is:

const isSiteEditor = getPath( window.location.href )?.includes(
	'site-editor.php'
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carolinan - Updated the common method as per your advice. Thanks.

if ( isSiteEditor && templateSlug ) {
const isCategoryTemplate =
templateSlug.includes( 'category' ) ||
templateSlug.includes( 'tag' ) ||
templateSlug.includes( 'archive' );

if ( isCategoryTemplate ) {
const taxonomy = templateSlug.includes( 'tag' )
? 'post_tag'
: 'category';
const label =
taxonomy === 'post_tag'
? __( 'Manage Tags' )
: __( 'Manage Categories' );

commands.push( {
name: 'core/manage-categories',
label,
icon: category,
callback: ( { close } ) => {
close();
// Redirect to the categories management page
window.location.href = `${ window.location.origin }/wp-admin/edit-tags.php?taxonomy=${ taxonomy }`;
},
isDefault: true, // Ensure it shows up by default
} );
}
}

return { isLoading: false, commands };
};

const getEditedEntityContextualCommands = () =>
function useEditedEntityContextualCommands() {
const { postType } = useSelect( ( select ) => {
Expand Down Expand Up @@ -444,6 +492,12 @@ export default function useCommands() {
hook: getEditorCommandLoader(),
} );

useCommandLoader( {
name: 'core/editor/category-commands',
hook: getSiteEditorCategoryCommands(),
context: 'entity-edit',
} );

useCommandLoader( {
name: 'core/editor/contextual-commands',
hook: getEditedEntityContextualCommands(),
Expand Down
Loading