[wp-trac] [WordPress Trac] #58333: WordPress 6.2.1 Shortcodes some shortcode no longer works!

WordPress Trac noreply at wordpress.org
Wed May 31 03:39:13 UTC 2023


#58333: WordPress 6.2.1 Shortcodes some shortcode no longer works!
--------------------------+----------------------
 Reporter:  jorcus        |       Owner:  desrosj
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  6.2.2
Component:  Shortcodes    |     Version:  6.2.2
 Severity:  normal        |  Resolution:  fixed
 Keywords:                |     Focuses:
--------------------------+----------------------

Comment (by sao987):

 Replying to [comment:72 gmariani405]:
 > Replying to [comment:7 andergmartins]:
 > > For those who want to stay on 6.2.1 and need to restore the support
 for shortcodes on templates, you can try this workaround.
 > >
 > > Add the following code as a plugin in a PHP file in the plugins
 folder:
 > >
 > > {{{#!php
 > > <?php
 > > /*
 > > Plugin Name: Fix shortcode
 > > Plugin URI:
 > > Description: Restore shortcode support on block templates
 > > Author: Anderson Martins
 > > Version: 0.1.0
 > > */
 > >
 > > add_filter('render_block_data', function($parsed_block) {
 > >     if (isset($parsed_block['innerContent'])) {
 > >         foreach ($parsed_block['innerContent'] as &$innerContent) {
 > >             if (empty($innerContent)) {
 > >                 continue;
 > >             }
 > >
 > >             $innerContent = do_shortcode($innerContent);
 > >         }
 > >     }
 > >
 > >     if (isset($parsed_block['innerBlocks'])) {
 > >         foreach ($parsed_block['innerBlocks'] as $key => &$innerBlock)
 {
 > >             if (! empty($innerBlock['innerContent'])) {
 > >                 foreach ($innerBlock['innerContent'] as
 &$innerContent) {
 > >                     if (empty($innerContent)) {
 > >                         continue;
 > >                     }
 > >
 > >                     $innerContent = do_shortcode($innerContent);
 > >                 }
 > >             }
 > >         }
 > >     }
 > >
 > >     return $parsed_block;
 > > }, 10, 1);
 > >
 > >
 > > }}}
 > >
 > >
 > > But be aware that support was removed for fixing a security issue, and
 restoring shortcode support you are probably bringing back the security
 issue.
 >
 > Fixed it, this looks to be working now.
 >
 > {{{#!php
 > <?php
 > /*
 > Plugin Name: Fix shortcode
 > Plugin URI:
 > Description: Restore shortcode support on block templates
 https://core.trac.wordpress.org/ticket/58333
 > Author: Anderson Martins, Gabriel Mariani
 > Version: 0.2.0
 > */
 >
 > function parse_inner_blocks(&$parsed_block)
 > {
 >     if (isset($parsed_block['innerBlocks'])) {
 >         foreach ($parsed_block['innerBlocks'] as $key => &$inner_block)
 {
 >             if (!empty($inner_block['innerContent'])) {
 >                 foreach ($inner_block['innerContent'] as
 &$inner_content) {
 >                     if (empty($inner_content)) {
 >                         continue;
 >                     }
 >
 >                     $inner_content = do_shortcode($inner_content);
 >                 }
 >             }
 >             if (isset($inner_block['innerBlocks'])) {
 >                 $inner_block = parse_inner_blocks($inner_block);
 >             }
 >         }
 >     }
 >
 >     return $parsed_block;
 > }
 >
 > add_filter('render_block_data', function ($parsed_block) {
 >
 >     if (isset($parsed_block['innerContent'])) {
 >         foreach ($parsed_block['innerContent'] as &$inner_content) {
 >             if (empty($inner_content)) {
 >                 continue;
 >             }
 >
 >             $inner_content = do_shortcode($inner_content);
 >         }
 >     }
 >
 >     $parsed_block = parse_inner_blocks($parsed_block);
 >
 >     return $parsed_block;
 > }, 10, 1);
 >
 > }}}

 Hi gmariani405,

 Is it possible for this code to work for navigation block custom link too?
 Currently it does not work for navigation block in 6.2.2.

 I'm willing to pay for an edited snippet to make shortcodes work again for
 custom link in navigation block. If you are interested please contact me.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58333#comment:110>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list