Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #58333, comment 78


Ignore:
Timestamp:
05/18/2023 03:35:22 PM (16 months ago)
Author:
siiimon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #58333, comment 78

    initial v1  
    1 Replying to [comment:72 gmariani405]:
    2 > Replying to [comment:7 andergmartins]:
    3 > > 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.
    4 > >
    5 > > Add the following code as a plugin in a PHP file in the plugins folder:
    6 > >
    7 > > {{{#!php
    8 > > <?php
    9 > > /*
    10 > > Plugin Name: Fix shortcode
    11 > > Plugin URI:
    12 > > Description: Restore shortcode support on block templates
    13 > > Author: Anderson Martins
    14 > > Version: 0.1.0
    15 > > */
    16 > >
    17 > > add_filter('render_block_data', function($parsed_block) {
    18 > >     if (isset($parsed_block['innerContent'])) {
    19 > >         foreach ($parsed_block['innerContent'] as &$innerContent) {
    20 > >             if (empty($innerContent)) {
    21 > >                 continue;
    22 > >             }
    23 > >
    24 > >             $innerContent = do_shortcode($innerContent);
    25 > >         }
    26 > >     }
    27 > >
    28 > >     if (isset($parsed_block['innerBlocks'])) {
    29 > >         foreach ($parsed_block['innerBlocks'] as $key => &$innerBlock) {
    30 > >             if (! empty($innerBlock['innerContent'])) {
    31 > >                 foreach ($innerBlock['innerContent'] as &$innerContent) {
    32 > >                     if (empty($innerContent)) {
    33 > >                         continue;
    34 > >                     }
    35 > >
    36 > >                     $innerContent = do_shortcode($innerContent);
    37 > >                 }
    38 > >             }
    39 > >         }
    40 > >     }
    41 > >
    42 > >     return $parsed_block;
    43 > > }, 10, 1);
    44 > >
    45 > >
    46 > > }}}
    47 > >
    48 > >
    49 > > But be aware that support was removed for fixing a security issue, and restoring shortcode support you are probably bringing back the security issue.
    50 >
    51 > Fixed it, this looks to be working now.
    52 >
    53 > {{{#!php
    54 > <?php
    55 > /*
    56 > Plugin Name: Fix shortcode
    57 > Plugin URI:
    58 > Description: Restore shortcode support on block templates https://core.trac.wordpress.org/ticket/58333
    59 > Author: Anderson Martins, Gabriel Mariani
    60 > Version: 0.2.0
    61 > */
    62 >
    63 > function parse_inner_blocks(&$parsed_block)
    64 > {
    65 >     if (isset($parsed_block['innerBlocks'])) {
    66 >         foreach ($parsed_block['innerBlocks'] as $key => &$inner_block) {
    67 >             if (!empty($inner_block['innerContent'])) {
    68 >                 foreach ($inner_block['innerContent'] as &$inner_content) {
    69 >                     if (empty($inner_content)) {
    70 >                         continue;
    71 >                     }
    72 >
    73 >                     $inner_content = do_shortcode($inner_content);
    74 >                 }
    75 >             }
    76 >             if (isset($inner_block['innerBlocks'])) {
    77 >                 $inner_block = parse_inner_blocks($inner_block);
    78 >             }
    79 >         }
    80 >     }
    81 >
    82 >     return $parsed_block;
    83 > }
    84 >
    85 > add_filter('render_block_data', function ($parsed_block) {
    86 >
    87 >     if (isset($parsed_block['innerContent'])) {
    88 >         foreach ($parsed_block['innerContent'] as &$inner_content) {
    89 >             if (empty($inner_content)) {
    90 >                 continue;
    91 >             }
    92 >
    93 >             $inner_content = do_shortcode($inner_content);
    94 >         }
    95 >     }
    96 >
    97 >     $parsed_block = parse_inner_blocks($parsed_block);
    98 >
    99 >     return $parsed_block;
    100 > }, 10, 1);
    101 >
    102 > }}}