| @@ -56,12 +56,14 @@ | ||
| 56 | 56 | */ |
| 57 | 57 | public function __construct() { |
| 58 | 58 | |
| 59 | 59 | $this->wdkit_default_category(); |
| 60 | + $this->wdkit_db_widgetlist(); | |
| 60 | 61 | |
| 61 | 62 | $this->wdkit_elementor_load(); |
| 62 | 63 | $this->wdkit_gutenberg_load(); |
| 63 | 64 | $this->wdkit_bricks_load(); |
| 65 | + $this->wdkit_gutenberg_core_load(); | |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | /** |
| 67 | 69 | * This function is called to load Elementor files, categories, and everything needed for WDesignKit to build with Elementor. |
| @@ -74,19 +76,56 @@ | ||
| 74 | 76 | } |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | 79 | /** |
| 78 | - * This function is called to load Elementor files, categories, and everything needed for WDesignKit to build with Gutenberg. | |
| 80 | + * This function is called to load Gutenberg files, categories, and everything needed for WDesignKit to build with Gutenberg. | |
| 79 | 81 | * |
| 80 | 82 | * @since 1.0.0 |
| 81 | 83 | */ |
| 82 | 84 | public function wdkit_gutenberg_load() { |
| 83 | - if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) { | |
| 85 | + if ( ! Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) { | |
| 86 | + return; | |
| 87 | + } | |
| 88 | + | |
| 89 | + // Frontend: always load so register_block_type() runs and the style/script | |
| 90 | + // handles attached to each widget (wp_register_style, render_callback) are | |
| 91 | + // enqueued correctly on public pages. | |
| 92 | + if ( ! is_admin() ) { | |
| 84 | 93 | require_once WDKIT_INCLUDES . 'widget-load/gutenberg/class-wdkit-gutenberg-files-load.php'; |
| 94 | + return; | |
| 85 | 95 | } |
| 96 | + | |
| 97 | + // Skip Elementor editor — $_GET['action'] is set before plugins_loaded | |
| 98 | + // and is the most reliable way to detect the Elementor edit screen. | |
| 99 | + if ( isset( $_GET['action'] ) && 'elementor' === sanitize_key( wp_unslash( $_GET['action'] ) ) ) { | |
| 100 | + return; | |
| 101 | + } | |
| 102 | + | |
| 103 | + // Admin: whitelist pages where the block editor can be active. | |
| 104 | + // $pagenow is set by WordPress before plugins_loaded — no timing issues, | |
| 105 | + // no dependency on post-type registration. Covers all CPTs including | |
| 106 | + // ACF-registered ones. Bricks and other builders are excluded automatically | |
| 107 | + // because they do not use these pages. | |
| 108 | + global $pagenow; | |
| 109 | + $block_editor_pages = array( 'post.php', 'post-new.php', 'widgets.php', 'customize.php' ); | |
| 110 | + | |
| 111 | + if ( in_array( $pagenow, $block_editor_pages, true ) ) { | |
| 112 | + require_once WDKIT_INCLUDES . 'widget-load/gutenberg/class-wdkit-gutenberg-files-load.php'; | |
| 113 | + } | |
| 86 | 114 | } |
| 87 | 115 | |
| 88 | 116 | /** |
| 117 | + * This function is called to load Gutenberg Core files, categories, and everything needed for WDesignKit to build with Gutenberg. | |
| 118 | + * | |
| 119 | + * @since 1.2.5 | |
| 120 | + */ | |
| 121 | + public function wdkit_gutenberg_core_load() { | |
| 122 | + if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_core', 'widget' ) ) { | |
| 123 | + require_once WDKIT_INCLUDES . 'widget-load/gutenberg_core/class-wdkit-gutenberg-core-files-load.php'; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 89 | 128 | * This function is called to load Bricks files, categories, and everything needed for WDesignKit to build with bricks. |
| 90 | 129 | * |
| 91 | 130 | * @since 1.0.0 |
| 92 | 131 | */ |
| @@ -99,9 +138,8 @@ | ||
| 99 | 138 | /** |
| 100 | 139 | * Set widget Default Category as WDesignKit |
| 101 | 140 | * |
| 102 | 141 | * @since 1.0.0 |
| 103 | - * @access public | |
| 104 | 142 | */ |
| 105 | 143 | public function wdkit_default_category() { |
| 106 | 144 | $category_list = get_option( 'wkit_builder' ); |
| 107 | 145 | |
| @@ -111,8 +149,23 @@ | ||
| 111 | 149 | |
| 112 | 150 | update_option( 'wkit_builder', $final_category ); |
| 113 | 151 | } elseif ( ! is_array( $category_list ) && empty( $category_list ) ) { |
| 114 | 152 | do_action( 'wdkit_admin_create_default' ); |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * Store default widget list | |
| 158 | + * | |
| 159 | + * @since 1.0.19 | |
| 160 | + */ | |
| 161 | + public function wdkit_db_widgetlist(){ | |
| 162 | + | |
| 163 | + $get_db_widget = get_option( 'wkit_deactivate_widgets', [] ); | |
| 164 | + | |
| 165 | + if ( empty( $get_db_widget ) ) { | |
| 166 | + | |
| 167 | + add_option( 'wkit_deactivate_widgets', [], '', 'yes' ); | |
| 115 | 168 | } |
| 116 | 169 | } |
| 117 | 170 | } |
| 118 | 171 | |