-
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
Template Parts: Fix loading issue #28088
Changes from 1 commit
97f7636
18dd3d5
dd37f48
0957e1c
b3b4af6
d7cec12
00dc839
893ca0c
c04828e
6c7dc0a
2f50732
3639d46
a2ef1a3
52f61bf
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 |
---|---|---|
|
@@ -5,6 +5,39 @@ | |
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Parses wp_template content and injects the current theme's | ||
* stylesheet as a theme attribute into each wp_template_part | ||
* | ||
* @param string $template_content serialized wp_template content. | ||
* | ||
* @return string Updated wp_template content. | ||
*/ | ||
function _remove_theme_attribute_from_content( $template_content ) { | ||
jeyip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$has_updated_content = false; | ||
$new_content = ''; | ||
$template_blocks = parse_blocks( $template_content ); | ||
|
||
foreach ( $template_blocks as $key => $block ) { | ||
if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { | ||
jeyip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// phpcs:ignore | ||
unset( $template_blocks[$key]['attrs']['theme'] ); | ||
jeyip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$has_updated_content = true; | ||
} | ||
} | ||
|
||
if ( $has_updated_content ) { | ||
foreach ( $template_blocks as $block ) { | ||
$new_content = $new_content . serialize_block( $block ); | ||
} | ||
|
||
return $new_content; | ||
} else { | ||
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. Same as above. 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. Yep. Sounds good 👍 |
||
return $template_content; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Output a ZIP file with an export of the current templates | ||
* and template parts from the site editor, and close the connection. | ||
|
@@ -24,6 +57,9 @@ function gutenberg_edit_site_export() { | |
// Load templates into the zip file. | ||
$templates = gutenberg_get_block_templates(); | ||
foreach ( $templates as $template ) { | ||
$updated_content = _remove_theme_attribute_from_content( $template['content'] ); | ||
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. No need for declaring
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. 👍 |
||
$template->content = $updated_content; | ||
|
||
$zip->addFromString( | ||
'theme/block-templates/' . $template->slug . '.html', | ||
$template->content | ||
|
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.
Would a more accurate description here be that it removes the theme attribute, instead of stating that it injects a new one?
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.
Good catch. I agree.