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 | | > }}} |
103 | | |
104 | | Hi gmariani405, |
105 | | |
106 | | 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. |
107 | | |
108 | | 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. |
| 1 | My problem has been solved with the help of people in the community forum... |