|
8 | 8 | * @package Functionalities |
9 | 9 | * @subpackage Features |
10 | 10 | * @since 0.3.0 |
11 | | - * @version 0.8.0 |
12 | 11 | */ |
13 | 12 |
|
14 | 13 | namespace Functionalities\Features; |
@@ -108,7 +107,10 @@ public static function init() : void { |
108 | 107 | // Output CSS in footer (both frontend and admin). |
109 | 108 | \add_action( 'wp_footer', array( __CLASS__, 'print_footer_link' ), 90 ); |
110 | 109 | \add_action( 'admin_footer', array( __CLASS__, 'print_footer_link' ), 90 ); |
111 | | - \add_action( 'enqueue_block_assets', array( __CLASS__, 'enqueue_editor_components' ) ); |
| 110 | + |
| 111 | + // Serve the block editor canvas (an iframe) via the editor `styles` |
| 112 | + // setting — the only channel guaranteed to reach the iframe. |
| 113 | + \add_filter( 'block_editor_settings_all', array( __CLASS__, 'add_editor_settings_components' ) ); |
112 | 114 |
|
113 | 115 | // Regenerate CSS file when settings are updated. |
114 | 116 | \add_action( 'update_option_functionalities_components', array( __CLASS__, 'on_option_update' ), 10, 2 ); |
@@ -156,38 +158,49 @@ protected static function get_options() : array { |
156 | 158 | } |
157 | 159 |
|
158 | 160 | /** |
159 | | - * Enqueue components CSS in the block editor iframe for WP 7 compatibility. |
| 161 | + * Inject component CSS into the block editor's style settings. |
160 | 162 | * |
161 | | - * @since 1.3.0 |
162 | | - * @return void |
| 163 | + * The editor canvas is iframed (WP 6.3+/7.x). Feeding CSS through the editor |
| 164 | + * `styles` setting — the channel add_editor_style() and the Font Library use — |
| 165 | + * is the reliable way into that iframe: WordPress copies it in verbatim and |
| 166 | + * scopes the selectors to the content wrapper. |
| 167 | + * |
| 168 | + * This replaces an enqueue_block_assets path that only reached the iframe when |
| 169 | + * a generated CSS file existed; its inline fallback used a src-less style handle |
| 170 | + * (wp_register_style( $h, false ) + wp_add_inline_style) that does NOT cross |
| 171 | + * into the iframe, so component CSS silently vanished in the editor whenever the |
| 172 | + * uploads file could not be written. |
| 173 | + * |
| 174 | + * @since 1.4.7 |
| 175 | + * |
| 176 | + * @param array $settings Block editor settings (from block_editor_settings_all). |
| 177 | + * @return array Modified settings. |
163 | 178 | */ |
164 | | - public static function enqueue_editor_components() : void { |
165 | | - if ( ! \is_admin() ) { |
166 | | - return; |
167 | | - } |
168 | | - |
| 179 | + public static function add_editor_settings_components( $settings ) { |
169 | 180 | $opts = self::get_options(); |
170 | 181 |
|
171 | 182 | if ( ! \apply_filters( 'functionalities_components_enabled', ! empty( $opts['enabled'] ) ) ) { |
172 | | - return; |
| 183 | + return $settings; |
173 | 184 | } |
174 | 185 |
|
175 | 186 | if ( empty( $opts['items'] ) || ! is_array( $opts['items'] ) ) { |
176 | | - return; |
| 187 | + return $settings; |
177 | 188 | } |
178 | 189 |
|
179 | 190 | $items = \apply_filters( 'functionalities_components_items', $opts['items'] ); |
180 | | - $css = self::build_css( $items ); |
181 | | - $file = self::ensure_css_file( $css ); |
| 191 | + $css = self::sanitize_css( self::build_css( $items ) ); |
182 | 192 |
|
183 | | - if ( $file && isset( $file['url'], $file['ver'] ) ) { |
184 | | - \wp_enqueue_style( 'functionalities-components', $file['url'], array(), $file['ver'] ); |
185 | | - return; |
| 193 | + if ( $css === '' ) { |
| 194 | + return $settings; |
186 | 195 | } |
187 | 196 |
|
188 | | - \wp_register_style( 'functionalities-components', false, array(), FUNCTIONALITIES_VERSION ); |
189 | | - \wp_enqueue_style( 'functionalities-components' ); |
190 | | - \wp_add_inline_style( 'functionalities-components', self::sanitize_css( $css ) ); |
| 197 | + if ( empty( $settings['styles'] ) || ! is_array( $settings['styles'] ) ) { |
| 198 | + $settings['styles'] = array(); |
| 199 | + } |
| 200 | + |
| 201 | + $settings['styles'][] = array( 'css' => $css ); |
| 202 | + |
| 203 | + return $settings; |
191 | 204 | } |
192 | 205 |
|
193 | 206 | /** |
|
0 commit comments