| @@ -59,8 +59,38 @@ | ||
| 59 | 59 | public function enqueue_editor_assets(): void { |
| 60 | 60 | $this->enqueue_asset( 'global', true, true ); |
| 61 | 61 | $this->enqueue_asset( 'modules', false ); |
| 62 | 62 | $this->localize_preview_images(); |
| 63 | + $this->localize_editor_settings(); | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Expose editor-facing settings to the global editor bundle. | |
| 68 | + * | |
| 69 | + * Printed as an inline script rather than via wp_localize_script so the | |
| 70 | + * values keep their real types — wp_localize_script casts top level | |
| 71 | + * scalars to strings, which would turn `false` into a truthy "". | |
| 72 | + * | |
| 73 | + * @since 3.0.0 | |
| 74 | + * | |
| 75 | + * @return void | |
| 76 | + */ | |
| 77 | + private function localize_editor_settings(): void { | |
| 78 | + $settings = get_option( 'gutslider_settings', array() ); | |
| 79 | + | |
| 80 | + $pattern_library = ! is_array( $settings ) || ! array_key_exists( 'pattern_library', $settings ) | |
| 81 | + ? true | |
| 82 | + : (bool) $settings['pattern_library']; | |
| 83 | + | |
| 84 | + wp_add_inline_script( | |
| 85 | + 'gutslider-blocks-global-script', | |
| 86 | + 'window.gutsliderEditor = ' . wp_json_encode( | |
| 87 | + array( | |
| 88 | + 'patternLibrary' => $pattern_library, | |
| 89 | + ) | |
| 90 | + ) . ';', | |
| 91 | + 'before' | |
| 92 | + ); | |
| 63 | 93 | } |
| 64 | 94 | |
| 65 | 95 | /** |
| 66 | 96 | * Enqueue front-end and shared assets. |