| @@ -5,8 +5,20 @@ | ||
| 5 | 5 | * @package gutenberg |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | + * Get the class name used on block level presets. | |
| 10 | + * | |
| 11 | + * @access private | |
| 12 | + * | |
| 13 | + * @param array $block Block object. | |
| 14 | + * @return string The unique class name. | |
| 15 | + */ | |
| 16 | +function _gutenberg_get_presets_class_name( $block ) { | |
| 17 | + return 'wp-settings-' . md5( serialize( $block ) ); | |
| 18 | +} | |
| 19 | + | |
| 20 | +/** | |
| 9 | 21 | * Update the block content with block level presets class name. |
| 10 | 22 | * |
| 11 | 23 | * @access private |
| 12 | 24 | * |
| @@ -25,9 +37,9 @@ | ||
| 25 | 37 | return $block_content; |
| 26 | 38 | } |
| 27 | 39 | |
| 28 | 40 | // return early if no settings are found on the block attributes. |
| 29 | - $block_settings = $block['attrs']['settings'] ?? null; | |
| 41 | + $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null ); | |
| 30 | 42 | if ( empty( $block_settings ) ) { |
| 31 | 43 | return $block_content; |
| 32 | 44 | } |
| 33 | 45 | |
| @@ -34,9 +46,9 @@ | ||
| 34 | 46 | // Like the layout hook this assumes the hook only applies to blocks with a single wrapper. |
| 35 | 47 | // Add the class name to the first element, presuming it's the wrapper, if it exists. |
| 36 | 48 | $tags = new WP_HTML_Tag_Processor( $block_content ); |
| 37 | 49 | if ( $tags->next_tag() ) { |
| 38 | - $tags->add_class( _wp_get_presets_class_name( $block ) ); | |
| 50 | + $tags->add_class( _gutenberg_get_presets_class_name( $block ) ); | |
| 39 | 51 | } |
| 40 | 52 | |
| 41 | 53 | return $tags->get_updated_html(); |
| 42 | 54 | } |
| @@ -58,14 +70,14 @@ | ||
| 58 | 70 | return null; |
| 59 | 71 | } |
| 60 | 72 | |
| 61 | 73 | // return early if no settings are found on the block attributes. |
| 62 | - $block_settings = $block['attrs']['settings'] ?? null; | |
| 74 | + $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null ); | |
| 63 | 75 | if ( empty( $block_settings ) ) { |
| 64 | 76 | return null; |
| 65 | 77 | } |
| 66 | 78 | |
| 67 | - $class_name = '.' . _wp_get_presets_class_name( $block ); | |
| 79 | + $class_name = '.' . _gutenberg_get_presets_class_name( $block ); | |
| 68 | 80 | |
| 69 | 81 | // the root selector for preset variables needs to target every possible block selector |
| 70 | 82 | // in order for the general setting to override any bock specific setting of a parent block or |
| 71 | 83 | // the site root. |
| @@ -116,19 +128,14 @@ | ||
| 116 | 128 | ) |
| 117 | 129 | ); |
| 118 | 130 | |
| 119 | 131 | if ( ! empty( $styles ) ) { |
| 120 | - /* | |
| 121 | - * This method is deprecated since WordPress 6.2. | |
| 122 | - * We could enqueue these styles separately, | |
| 123 | - * or print them out with other settings presets. | |
| 124 | - */ | |
| 125 | - wp_enqueue_block_support_styles( $styles ); | |
| 132 | + gutenberg_enqueue_block_support_styles( $styles ); | |
| 126 | 133 | } |
| 127 | 134 | |
| 128 | 135 | return null; |
| 129 | 136 | } |
| 130 | 137 | // Remove WordPress core filter to avoid rendering duplicate settings style blocks. |
| 131 | -remove_filter( 'render_block', '_wp_add_block_level_presets_class', 10 ); | |
| 132 | -remove_filter( 'pre_render_block', '_wp_add_block_level_preset_styles', 10 ); | |
| 138 | +remove_filter( 'render_block', '_wp_add_block_level_presets_class', 10, 2 ); | |
| 139 | +remove_filter( 'pre_render_block', '_wp_add_block_level_preset_styles', 10, 2 ); | |
| 133 | 140 | add_filter( 'render_block', '_gutenberg_add_block_level_presets_class', 10, 2 ); |
| 134 | 141 | add_filter( 'pre_render_block', '_gutenberg_add_block_level_preset_styles', 10, 2 ); |