-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Classic Theme: Expose new Patterns page and remove Template Parts submenu #61080
Changes from all commits
058d832
584d157
5eb3d61
93f0fcf
1cef7df
a0e4add
6261d02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* WordPress 6.6 compatibility functions. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Change the Patterns submenu link and remove the Template Parts submenu for | ||
* the Classic theme. This function should not be backported to core, and should be | ||
* removed when the required WP core version for Gutenberg is >= 6.6.0. | ||
* | ||
* @global array $submenu | ||
*/ | ||
function gutenberg_change_patterns_link_and_remove_template_parts_submenu_item() { | ||
if ( ! wp_is_block_theme() ) { | ||
global $submenu; | ||
foreach ( $submenu['themes.php'] as $key => $item ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The index of the Template Parts submenu varies depending on the core version. So we need to explore the submenu with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that this line produces PHP warnings.
|
||
if ( 'edit.php?post_type=wp_block' === $item[2] ) { | ||
$submenu['themes.php'][ $key ][2] = 'site-editor.php?path=/patterns'; | ||
} elseif ( 'site-editor.php?path=/wp_template_part/all' === $item[2] ) { | ||
unset( $submenu['themes.php'][ $key ] ); | ||
} | ||
} | ||
} | ||
} | ||
add_action( 'admin_init', 'gutenberg_change_patterns_link_and_remove_template_parts_submenu_item' ); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -10,15 +10,14 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; | |||||||
/** | ||||||||
* Internal dependencies | ||||||||
*/ | ||||||||
import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks'; | ||||||||
import { useIsTemplatesAccessible } from './hooks'; | ||||||||
import { unlock } from './lock-unlock'; | ||||||||
|
||||||||
const { useHistory } = unlock( routerPrivateApis ); | ||||||||
|
||||||||
export function useAdminNavigationCommands() { | ||||||||
const history = useHistory(); | ||||||||
const isTemplatesAccessible = useIsTemplatesAccessible(); | ||||||||
const isBlockBasedTheme = useIsBlockBasedTheme(); | ||||||||
|
||||||||
const isSiteEditor = getPath( window.location.href )?.includes( | ||||||||
'site-editor.php' | ||||||||
|
@@ -45,7 +44,11 @@ export function useAdminNavigationCommands() { | |||||||
label: __( 'Patterns' ), | ||||||||
icon: symbol, | ||||||||
callback: ( { close } ) => { | ||||||||
if ( isTemplatesAccessible && isBlockBasedTheme ) { | ||||||||
// The site editor and templates both check whether the user | ||||||||
// can read templates. We can leverage that here and this | ||||||||
// command links to the classic dashboard manage patterns page | ||||||||
// if the user can't access it. | ||||||||
if ( isTemplatesAccessible ) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate this PR is only removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I just reused this comment: gutenberg/packages/patterns/src/components/patterns-manage-button.js Lines 38 to 40 in 08a8156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure that comment captures the situation here. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated it with a0e4add, but I'm not sure if I'm communicating it well 😅 |
||||||||
const args = { | ||||||||
path: '/patterns', | ||||||||
}; | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,20 +110,12 @@ function CategoriesGroup( { | |
); | ||
} | ||
|
||
const EMPTY_ARRAY = []; | ||
export default function SidebarNavigationScreenPatterns() { | ||
const { | ||
params: { categoryType, categoryId, path }, | ||
} = useLocation(); | ||
const isTemplatePartsPath = path === '/wp_template_part/all'; | ||
const currentCategory = | ||
categoryId || | ||
( isTemplatePartsPath | ||
? TEMPLATE_PART_ALL_AREAS_CATEGORY | ||
: PATTERN_DEFAULT_CATEGORY ); | ||
const currentType = | ||
categoryType || | ||
( isTemplatePartsPath ? TEMPLATE_PART_POST_TYPE : PATTERN_TYPES.theme ); | ||
const currentCategory = categoryId || PATTERN_DEFAULT_CATEGORY; | ||
const currentType = categoryType || PATTERN_TYPES.theme; | ||
|
||
const { templatePartAreas, hasTemplateParts, isLoading } = | ||
useTemplatePartAreas(); | ||
|
@@ -148,28 +140,11 @@ export default function SidebarNavigationScreenPatterns() { | |
return ( | ||
<SidebarNavigationScreen | ||
isRoot={ ! isBlockBasedTheme } | ||
title={ | ||
isTemplatePartsPath | ||
? __( 'Manage template parts' ) | ||
: __( 'Patterns' ) | ||
} | ||
description={ | ||
isTemplatePartsPath | ||
? __( | ||
'Create new template parts, or reset any customizations made to the template parts supplied by your theme.' | ||
) | ||
: __( | ||
'Manage what patterns are available when editing the site.' | ||
) | ||
} | ||
actions={ | ||
( isBlockBasedTheme || ! isTemplatePartsPath ) && ( | ||
<AddNewPattern | ||
canCreateParts={ isBlockBasedTheme } | ||
canCreatePatterns={ ! isTemplatePartsPath } | ||
/> | ||
) | ||
} | ||
title={ __( 'Patterns' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just above this return statement, there's a reference to the |
||
description={ __( | ||
'Manage what patterns are available when editing the site.' | ||
) } | ||
actions={ <AddNewPattern /> } | ||
content={ | ||
<> | ||
{ isLoading && __( 'Loading items…' ) } | ||
|
@@ -183,11 +158,7 @@ export default function SidebarNavigationScreenPatterns() { | |
<CategoriesGroup | ||
path={ path } | ||
templatePartAreas={ templatePartAreas } | ||
patternCategories={ | ||
isTemplatePartsPath | ||
? EMPTY_ARRAY | ||
: patternCategories | ||
} | ||
patternCategories={ patternCategories } | ||
currentCategory={ currentCategory } | ||
currentType={ currentType } | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,10 +226,6 @@ function useResolveEditedEntityAndContext( { path, postId, postType } ) { | |
return { isReady: true, postType: 'wp_template', postId, context }; | ||
} | ||
|
||
if ( path === '/wp_template_part/all' && postId ) { | ||
return { isReady: true, postType: 'wp_template_part', postId, context }; | ||
} | ||
Comment on lines
-229
to
-231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was added when DataViews was introduced to the Template Parts List page, so I think it's safe to remove it now (See #57952). |
||
|
||
if ( postTypesWithoutParentTemplate.includes( postType ) ) { | ||
return { isReady: true, postType, postId, context }; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have the
wordpress-develop
PR available, it might be handy to add a link to it here in this comment.