| @@ -38,14 +38,14 @@ | ||
| 38 | 38 | */ |
| 39 | 39 | public function register_elementor_rest_field() { |
| 40 | 40 | register_rest_field( get_post_types( '', 'names' ), |
| 41 | 41 | 'gutenberg_elementor_mode', [ |
| 42 | - 'update_callback' => function( $request_value, $obj ) { | |
| 43 | - if ( ! User::is_current_user_can_edit( $obj->ID ) ) { | |
| 42 | + 'update_callback' => function( $request_value, $object ) { | |
| 43 | + if ( ! User::is_current_user_can_edit( $object->ID ) ) { | |
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - $document = Plugin::$instance->documents->get( $obj->ID ); | |
| 47 | + $document = Plugin::$instance->documents->get( $object->ID ); | |
| 48 | 48 | |
| 49 | 49 | if ( ! $document ) { |
| 50 | 50 | return false; |
| 51 | 51 | } |
| @@ -70,9 +70,9 @@ | ||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $this->is_gutenberg_editor_active = true; |
| 73 | 73 | |
| 74 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 74 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 75 | 75 | |
| 76 | 76 | wp_enqueue_script( 'elementor-gutenberg', ELEMENTOR_ASSETS_URL . 'js/gutenberg' . $suffix . '.js', [ 'jquery' ], ELEMENTOR_VERSION, true ); |
| 77 | 77 | |
| 78 | 78 | $elementor_settings = [ |
| @@ -124,19 +124,8 @@ | ||
| 124 | 124 | </div> |
| 125 | 125 | </div> |
| 126 | 126 | </div> |
| 127 | 127 | </script> |
| 128 | - | |
| 129 | - <script id="elementor-gutenberg-button-tmpl" type="text/html"> | |
| 130 | - <div id="elementor-edit-button-gutenberg"> | |
| 131 | - <button id="elementor-edit-mode-button" type="button" class="button button-primary button-large"> | |
| 132 | - <span class="elementor-edit-mode-gutenberg"> | |
| 133 | - <i class="eicon-elementor-square" aria-hidden="true"></i> | |
| 134 | - <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?> | |
| 135 | - </span> | |
| 136 | - </button> | |
| 137 | - </div> | |
| 138 | - </script> | |
| 139 | 128 | <?php |
| 140 | 129 | } |
| 141 | 130 | |
| 142 | 131 | /** |
| @@ -143,16 +132,35 @@ | ||
| 143 | 132 | * @since 2.1.0 |
| 144 | 133 | * @access public |
| 145 | 134 | */ |
| 146 | 135 | public function __construct() { |
| 136 | + $this->register_experiments(); | |
| 137 | + | |
| 147 | 138 | add_action( 'rest_api_init', [ $this, 'register_elementor_rest_field' ] ); |
| 148 | 139 | add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ] ); |
| 149 | 140 | add_action( 'admin_footer', [ $this, 'print_admin_js_template' ] ); |
| 141 | + | |
| 150 | 142 | add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_assets' ], 999 ); |
| 151 | 143 | } |
| 152 | 144 | |
| 145 | + public function register_experiments() { | |
| 146 | + Plugin::$instance->experiments->add_feature( [ | |
| 147 | + 'name' => 'block_editor_assets_optimize', | |
| 148 | + 'title' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ), | |
| 149 | + 'description' => esc_html__( 'Use this experiment to reduce unnecessary render-blocking loads, enhancing site performance by dequeuing unused Gutenberg block editor files (styles and scripts).', 'elementor' ), | |
| 150 | + 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, | |
| 151 | + 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 152 | + 'new_site' => [ | |
| 153 | + 'default_active' => true, | |
| 154 | + 'minimum_installation_version' => '3.17.0', | |
| 155 | + ], | |
| 156 | + 'tag' => esc_html__( 'Performance', 'elementor' ), | |
| 157 | + 'generator_tag' => true, | |
| 158 | + ] ); | |
| 159 | + } | |
| 160 | + | |
| 153 | 161 | public function dequeue_assets() { |
| 154 | - if ( ! static::is_optimized_gutenberg_loading_enabled() ) { | |
| 162 | + if ( ! Plugin::$instance->experiments->is_feature_active( 'block_editor_assets_optimize' ) ) { | |
| 155 | 163 | return; |
| 156 | 164 | } |
| 157 | 165 | |
| 158 | 166 | if ( ! static::should_dequeue_gutenberg_assets() ) { |
| @@ -164,22 +172,9 @@ | ||
| 164 | 172 | wp_dequeue_style( 'wc-block-style' ); |
| 165 | 173 | wp_dequeue_style( 'wc-blocks-style' ); |
| 166 | 174 | } |
| 167 | 175 | |
| 168 | - /** | |
| 169 | - * Check whether the "Optimized Gutenberg Loading" settings is enabled. | |
| 170 | - * | |
| 171 | - * The 'elementor_optimized_gutenberg_loading' option can be enabled/disabled from the Elementor settings. | |
| 172 | - * For BC, when the option has not been saved in the database, the default '1' value is returned. | |
| 173 | - * | |
| 174 | - * @since 3.21.0 | |
| 175 | - * @access private | |
| 176 | - */ | |
| 177 | - private static function is_optimized_gutenberg_loading_enabled(): bool { | |
| 178 | - return (bool) get_option( 'elementor_optimized_gutenberg_loading', '1' ); | |
| 179 | - } | |
| 180 | - | |
| 181 | - private static function should_dequeue_gutenberg_assets(): bool { | |
| 176 | + private static function should_dequeue_gutenberg_assets() : bool { | |
| 182 | 177 | $post = get_post(); |
| 183 | 178 | |
| 184 | 179 | if ( empty( $post->ID ) ) { |
| 185 | 180 | return false; |
| @@ -195,9 +190,9 @@ | ||
| 195 | 190 | |
| 196 | 191 | return true; |
| 197 | 192 | } |
| 198 | 193 | |
| 199 | - private static function is_built_with_elementor( $post ): bool { | |
| 194 | + private static function is_built_with_elementor( $post ) : bool { | |
| 200 | 195 | $document = Plugin::$instance->documents->get( $post->ID ); |
| 201 | 196 | |
| 202 | 197 | if ( ! $document || ! $document->is_built_with_elementor() ) { |
| 203 | 198 | return false; |
| @@ -205,9 +200,9 @@ | ||
| 205 | 200 | |
| 206 | 201 | return true; |
| 207 | 202 | } |
| 208 | 203 | |
| 209 | - private static function is_gutenberg_in_post( $post ): bool { | |
| 204 | + private static function is_gutenberg_in_post( $post ) : bool { | |
| 210 | 205 | if ( has_blocks( $post ) ) { |
| 211 | 206 | return true; |
| 212 | 207 | } |
| 213 | 208 | |
| @@ -217,9 +212,9 @@ | ||
| 217 | 212 | |
| 218 | 213 | return false; |
| 219 | 214 | } |
| 220 | 215 | |
| 221 | - private static function current_theme_is_fse_theme(): bool { | |
| 216 | + private static function current_theme_is_fse_theme() : bool { | |
| 222 | 217 | if ( function_exists( 'wp_is_block_theme' ) ) { |
| 223 | 218 | return (bool) wp_is_block_theme(); |
| 224 | 219 | } |
| 225 | 220 | if ( function_exists( 'gutenberg_is_fse_theme' ) ) { |