Skip to content

Commit a531272

Browse files
Core Commands: Add Dashboard option for post and site editors only
1 parent 185cc42 commit a531272

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

packages/core-commands/src/admin-navigation-commands.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,38 @@ const getAdminBasicNavigationCommands = () =>
131131
};
132132
};
133133

134-
export function useAdminNavigationCommands() {
135-
useCommand( {
136-
name: 'core/dashboard',
137-
label: __( 'Dashboard' ),
138-
icon: dashboard,
139-
callback: () => {
140-
document.location.assign( 'index.php' );
141-
},
142-
} );
134+
const getDashboardCommand = () =>
135+
function useDashboardCommand() {
136+
const isSiteEditor = getPath( window.location.href )?.includes(
137+
'site-editor.php'
138+
);
139+
const isPostEditor =
140+
getPath( window.location.href )?.includes( 'post.php' ) ||
141+
getPath( window.location.href )?.includes( 'post-new.php' );
143142

143+
const commands = useMemo( () => {
144+
if ( isSiteEditor || isPostEditor ) {
145+
return [
146+
{
147+
name: 'core/dashboard',
148+
label: __( 'Dashboard' ),
149+
icon: dashboard,
150+
callback: () => {
151+
document.location.assign( 'index.php' );
152+
},
153+
},
154+
];
155+
}
156+
return [];
157+
}, [ isSiteEditor, isPostEditor ] );
158+
159+
return {
160+
isLoading: false,
161+
commands,
162+
};
163+
};
164+
165+
export function useAdminNavigationCommands() {
144166
useCommand( {
145167
name: 'core/add-new-post',
146168
label: __( 'Add Post' ),
@@ -150,6 +172,11 @@ export function useAdminNavigationCommands() {
150172
},
151173
} );
152174

175+
useCommandLoader( {
176+
name: 'core/dashboard',
177+
hook: getDashboardCommand(),
178+
} );
179+
153180
useCommandLoader( {
154181
name: 'core/add-new-page',
155182
hook: getAddNewPageCommand(),

0 commit comments

Comments
 (0)