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

do_shortcode in Block template loader functions #19278

Closed
smileBeda opened this issue Dec 20, 2019 · 11 comments
Closed

do_shortcode in Block template loader functions #19278

smileBeda opened this issue Dec 20, 2019 · 11 comments

Comments

@smileBeda
Copy link

smileBeda commented Dec 20, 2019

Problem
The experimental feature of Gutenberg Block (plugin) "Full Site Editing" allows us to create Theme templates. However, when those templates are rendered, in gutenberg_render_the_template, it seems either intentionally or by accident, ShortCodes are not considered when building the $content.

As a result, if our Custom Template built with Gutenberg holds ShortCodes of any kind those won't execute but print as bare shortcodes on the front end.

Suggestion
I suggest, unless I miss something obvious, to $content = do_shortcode($content); before echoing it (or $content = apply_filters('the_content',$content);), around line 237 of /gutenberg/lib/template-loader.php function gutenberg_render_the_template()

There are (still) several cases when our templates (even if built with blocks) could contain ShortCodes.

Maybe I miss something obvious here, I am happy to stand corrected :)

@smileBeda smileBeda changed the title Apply do_shortcode in Block template loader functions do_shortcode in Block template loader functions Dec 20, 2019
@talldan talldan added [Feature] Full Site Editing Needs Testing Needs further testing to be confirmed. labels Feb 4, 2020
@carlomanf
Copy link

related: #21397

Isn't the shortcode meant to be processed through do_blocks anyway? I think it's a bug not an oversight.

@smileBeda
Copy link
Author

smileBeda commented Apr 16, 2020

Looks definitely like the same issue, yes.
Either way, currently, ShortCodes in Full site editing ain't working :)

I thought this might be by design, given the fully new experience maybe shortcodes now are seen as defunct :) and hence created a request instead of bug report.

Feel free to obsolete this here if #21397 will be addressing the same!

@talldan
Copy link
Contributor

talldan commented Aug 18, 2020

I've closed #21397 as a duplicate, though it has some testing instructions, which may be useful.

@TukuToi @carlomanf are you still experiencing the issue?

We discussed it in a triage session on slack (https://wordpress.slack.com/archives/C02QB2JS7/p1597727370199700), though I have to say none of us attending were particularly familiar with the process of setting up a template.

One person mentioned that it seemed to work ok when updating an existing template with a shortcode block, so I thought it'd be worth checking in with you to see if this is still a problem.

@smileBeda
Copy link
Author

smileBeda commented Aug 25, 2020

This might be fixed because I see the code now does run_shortcode in the named method, which should be what was missing.
However it is strange as that change was done before our report here.
See 3d6392d

Unfortunately I do not have anymore the setup from back then but will check if I find time soon to re-test this to confirm it as solved (I highly suspect it is, given the code), however I can't guarantee it just yet.

@carlomanf
Copy link

I just tested it with gutenberg 8.8 and wordpress 5.5, and the bug is half-fixed.

When the shortcode is part of the post content, it now works correctly.

When the shortcode is part of the template, the behaviour is unchanged since the report from #21397.

@deckblad
Copy link

I'm currently seeing the same behavior as described by carlomanf.

@carlomanf
Copy link

carlomanf commented Dec 30, 2021

I don't have the ability to close this, but I believe it was fixed with #37545. However, it appears that the fix has not propagated over to core yet so I expect there will need to be a mirroring patch for core. @TukuToi @carolinan @Mamaduka

@Mamaduka
Copy link
Member

Thanks for the ping, @carlomanf. Yes, I believe the issue got fixed by the PR you mentioned.

I'm not sure if we can backport the fix into core this late in the release cycle, but I left the comment in the PR.

I will close this issue since the bug is fixed in the plugin.

@Mamaduka Mamaduka removed the Needs Testing Needs further testing to be confirmed. label Dec 30, 2021
@ecairol
Copy link

ecairol commented May 16, 2024

When the shortcode is part of the post content, it now works correctly.
When the shortcode is part of the template, the behaviour is unchanged since the report from #21397.

I'm currently seeing exactly that issue.

The same shortcode works fine if it's part of the do_blocks() rendering, but not if it comes from block_template_part( 'header' );


Example

page-my-slug.php:

?>
<!doctype html>
<head>
<?php
	$block_content = do_blocks( '
		<!-- wp:group {"layout":{"type":"constrained"}} -->
		<div class="wp-block-group">
		<!-- wp:post-content /-->
		</div>
		<!-- /wp:group -->'
 	);
        wp_head();
?>
</head>
<body>

<!-- [shortcode] does not work: -->
<header class="wp-block-template-part site-header">
    <?php block_header_area(); ?>
    or
    <?php do_shortcode( block_header_area() ); ?>
</header>

<!-- [shortcode] works fine: -->
<?php echo $block_content; ?>

</body>

@carlomanf
Copy link

@ecairol The issue you are looking for is https://core.trac.wordpress.org/ticket/56780

@ecairol
Copy link

ecairol commented May 17, 2024

Thank you @carlomanf!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants