| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\Gutenberg; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | -use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 6 | 5 | use Elementor\Plugin; |
| 7 | 6 | use Elementor\User; |
| 8 | 7 | use Elementor\Utils; |
| 9 | 8 | |
| @@ -38,21 +37,15 @@ | ||
| 38 | 37 | */ |
| 39 | 38 | public function register_elementor_rest_field() { |
| 40 | 39 | register_rest_field( get_post_types( '', 'names' ), |
| 41 | 40 | 'gutenberg_elementor_mode', [ |
| 42 | - 'update_callback' => function( $request_value, $obj ) { | |
| 43 | - if ( ! User::is_current_user_can_edit( $obj->ID ) ) { | |
| 41 | + 'update_callback' => function( $request_value, $object ) { | |
| 42 | + if ( ! User::is_current_user_can_edit( $object->ID ) ) { | |
| 44 | 43 | return false; |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | - $document = Plugin::$instance->documents->get( $obj->ID ); | |
| 46 | + Plugin::$instance->db->set_is_elementor_page( $object->ID, false ); | |
| 48 | 47 | |
| 49 | - if ( ! $document ) { | |
| 50 | - return false; | |
| 51 | - } | |
| 52 | - | |
| 53 | - $document->set_is_built_with_elementor( false ); | |
| 54 | - | |
| 55 | 48 | return true; |
| 56 | 49 | }, |
| 57 | 50 | ] |
| 58 | 51 | ); |
| @@ -70,9 +63,9 @@ | ||
| 70 | 63 | } |
| 71 | 64 | |
| 72 | 65 | $this->is_gutenberg_editor_active = true; |
| 73 | 66 | |
| 74 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 67 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 75 | 68 | |
| 76 | 69 | wp_enqueue_script( 'elementor-gutenberg', ELEMENTOR_ASSETS_URL . 'js/gutenberg' . $suffix . '.js', [ 'jquery' ], ELEMENTOR_VERSION, true ); |
| 77 | 70 | |
| 78 | 71 | $elementor_settings = [ |
| @@ -94,12 +87,12 @@ | ||
| 94 | 87 | ?> |
| 95 | 88 | <script id="elementor-gutenberg-button-switch-mode" type="text/html"> |
| 96 | 89 | <div id="elementor-switch-mode"> |
| 97 | 90 | <button id="elementor-switch-mode-button" type="button" class="button button-primary button-large"> |
| 98 | - <span class="elementor-switch-mode-on"><?php echo esc_html__( '← Back to WordPress Editor', 'elementor' ); ?></span> | |
| 91 | + <span class="elementor-switch-mode-on"><?php echo __( '← Back to WordPress Editor', 'elementor' ); ?></span> | |
| 99 | 92 | <span class="elementor-switch-mode-off"> |
| 100 | 93 | <i class="eicon-elementor-square" aria-hidden="true"></i> |
| 101 | - <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?> | |
| 94 | + <?php echo __( 'Edit with Elementor', 'elementor' ); ?> | |
| 102 | 95 | </span> |
| 103 | 96 | </button> |
| 104 | 97 | </div> |
| 105 | 98 | </script> |
| @@ -104,14 +97,13 @@ | ||
| 104 | 97 | </div> |
| 105 | 98 | </script> |
| 106 | 99 | |
| 107 | 100 | <script id="elementor-gutenberg-panel" type="text/html"> |
| 108 | - <div id="elementor-editor"> | |
| 109 | - <div id="elementor-go-to-edit-page-link"> | |
| 110 | - <button id="elementor-editor-button" class="button button-primary button-hero"> | |
| 101 | + <div id="elementor-editor"><a id="elementor-go-to-edit-page-link" href="#"> | |
| 102 | + <div id="elementor-editor-button" class="button button-primary button-hero"> | |
| 111 | 103 | <i class="eicon-elementor-square" aria-hidden="true"></i> |
| 112 | - <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?> | |
| 113 | - </button> | |
| 104 | + <?php echo __( 'Edit with Elementor', 'elementor' ); ?> | |
| 105 | + </div> | |
| 114 | 106 | <div class="elementor-loader-wrapper"> |
| 115 | 107 | <div class="elementor-loader"> |
| 116 | 108 | <div class="elementor-loader-boxes"> |
| 117 | 109 | <div class="elementor-loader-box"></div> |
| @@ -119,24 +111,12 @@ | ||
| 119 | 111 | <div class="elementor-loader-box"></div> |
| 120 | 112 | <div class="elementor-loader-box"></div> |
| 121 | 113 | </div> |
| 122 | 114 | </div> |
| 123 | - <div class="elementor-loading-title"><?php echo esc_html__( 'Loading', 'elementor' ); ?></div> | |
| 115 | + <div class="elementor-loading-title"><?php echo __( 'Loading', 'elementor' ); ?></div> | |
| 124 | 116 | </div> |
| 125 | - </div> | |
| 126 | - </div> | |
| 117 | + </a></div> | |
| 127 | 118 | </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 | 119 | <?php |
| 140 | 120 | } |
| 141 | 121 | |
| 142 | 122 | /** |
| @@ -146,86 +126,6 @@ | ||
| 146 | 126 | public function __construct() { |
| 147 | 127 | add_action( 'rest_api_init', [ $this, 'register_elementor_rest_field' ] ); |
| 148 | 128 | add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ] ); |
| 149 | 129 | add_action( 'admin_footer', [ $this, 'print_admin_js_template' ] ); |
| 150 | - add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_assets' ], 999 ); | |
| 151 | - } | |
| 152 | - | |
| 153 | - public function dequeue_assets() { | |
| 154 | - if ( ! static::is_optimized_gutenberg_loading_enabled() ) { | |
| 155 | - return; | |
| 156 | - } | |
| 157 | - | |
| 158 | - if ( ! static::should_dequeue_gutenberg_assets() ) { | |
| 159 | - return; | |
| 160 | - } | |
| 161 | - | |
| 162 | - wp_dequeue_style( 'wp-block-library' ); | |
| 163 | - wp_dequeue_style( 'wp-block-library-theme' ); | |
| 164 | - wp_dequeue_style( 'wc-block-style' ); | |
| 165 | - wp_dequeue_style( 'wc-blocks-style' ); | |
| 166 | - } | |
| 167 | - | |
| 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 { | |
| 182 | - $post = get_post(); | |
| 183 | - | |
| 184 | - if ( empty( $post->ID ) ) { | |
| 185 | - return false; | |
| 186 | - } | |
| 187 | - | |
| 188 | - if ( ! static::is_built_with_elementor( $post ) ) { | |
| 189 | - return false; | |
| 190 | - } | |
| 191 | - | |
| 192 | - if ( static::is_gutenberg_in_post( $post ) ) { | |
| 193 | - return false; | |
| 194 | - } | |
| 195 | - | |
| 196 | - return true; | |
| 197 | - } | |
| 198 | - | |
| 199 | - private static function is_built_with_elementor( $post ): bool { | |
| 200 | - $document = Plugin::$instance->documents->get( $post->ID ); | |
| 201 | - | |
| 202 | - if ( ! $document || ! $document->is_built_with_elementor() ) { | |
| 203 | - return false; | |
| 204 | - } | |
| 205 | - | |
| 206 | - return true; | |
| 207 | - } | |
| 208 | - | |
| 209 | - private static function is_gutenberg_in_post( $post ): bool { | |
| 210 | - if ( has_blocks( $post ) ) { | |
| 211 | - return true; | |
| 212 | - } | |
| 213 | - | |
| 214 | - if ( static::current_theme_is_fse_theme() ) { | |
| 215 | - return true; | |
| 216 | - } | |
| 217 | - | |
| 218 | - return false; | |
| 219 | - } | |
| 220 | - | |
| 221 | - private static function current_theme_is_fse_theme(): bool { | |
| 222 | - if ( function_exists( 'wp_is_block_theme' ) ) { | |
| 223 | - return (bool) wp_is_block_theme(); | |
| 224 | - } | |
| 225 | - if ( function_exists( 'gutenberg_is_fse_theme' ) ) { | |
| 226 | - return (bool) gutenberg_is_fse_theme(); | |
| 227 | - } | |
| 228 | - | |
| 229 | - return false; | |
| 230 | 130 | } |
| 231 | 131 | } |