| @@ -12,9 +12,10 @@ | ||
| 12 | 12 | |
| 13 | 13 | class Module extends BaseModule { |
| 14 | 14 | |
| 15 | 15 | public function __construct() { |
| 16 | - add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ] ); | |
| 16 | + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); | |
| 17 | + add_action( 'admin_footer', [ $this, 'print_button_js_template' ] ); | |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | 20 | public static function is_active() { |
| 20 | 21 | return self::is_new_woocommerce_product_editor_page(); |
| @@ -20,22 +21,24 @@ | ||
| 20 | 21 | return self::is_new_woocommerce_product_editor_page(); |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | public function enqueue_assets() { |
| 24 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 25 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 25 | 26 | |
| 26 | 27 | wp_enqueue_script( |
| 27 | - 'e-wc-product-editor', | |
| 28 | - ELEMENTOR_ASSETS_URL . 'js/e-wc-product-editor' . $suffix . '.js', | |
| 29 | - [ 'wp-components', 'wp-core-data', 'wc-admin-layout', 'wp-plugins' ], | |
| 28 | + 'elementor-wc-product-editor', | |
| 29 | + ELEMENTOR_ASSETS_URL . 'js/wc-product-editor' . $suffix . '.js', | |
| 30 | + [], | |
| 30 | 31 | ELEMENTOR_VERSION, |
| 31 | 32 | true |
| 32 | 33 | ); |
| 33 | 34 | |
| 34 | - $elementor_settings = [ | |
| 35 | - 'editLink' => admin_url( 'post.php' ), | |
| 36 | - ]; | |
| 37 | - Utils::print_js_config( 'e-wc-product-editor', 'ElementorWCProductEditorSettings', $elementor_settings ); | |
| 35 | + wp_enqueue_style( | |
| 36 | + 'elementor-wc-product-editor', | |
| 37 | + ELEMENTOR_ASSETS_URL . 'css/wc-product-editor' . $suffix . '.css', | |
| 38 | + [], | |
| 39 | + ELEMENTOR_VERSION | |
| 40 | + ); | |
| 38 | 41 | } |
| 39 | 42 | |
| 40 | 43 | public function get_name() { |
| 41 | 44 | return 'wc-product-editor'; |
| @@ -51,7 +54,48 @@ | ||
| 51 | 54 | |
| 52 | 55 | $path_pieces = explode( '/', $path ); |
| 53 | 56 | $route = $path_pieces[1]; |
| 54 | 57 | |
| 55 | - return 'product' === $route || 'add-product' === $route; | |
| 58 | + return 'product' === $route; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function print_button_js_template() { | |
| 62 | + $post_id = $this->get_post_id(); | |
| 63 | + $document = Plugin::$instance->documents->get( $post_id ); | |
| 64 | + | |
| 65 | + if ( ! $document ) { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + ?> | |
| 69 | + <script id="elementor-woocommerce-new-editor-button" type="text/html"> | |
| 70 | + <a id="elementor-go-to-edit-page-link" class="elementor-wc-button-wrapper" href="<?php echo esc_url( $document->get_edit_url() ); ?>"> | |
| 71 | + <div id="elementor-editor-button" class="button button-primary button-large"> | |
| 72 | + <i class="eicon-elementor-square" aria-hidden="true"></i> | |
| 73 | + <?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?> | |
| 74 | + </div> | |
| 75 | + <div class="elementor-loader-wrapper"> | |
| 76 | + <div class="elementor-loader"> | |
| 77 | + <div class="elementor-loader-boxes"> | |
| 78 | + <div class="elementor-loader-box"></div> | |
| 79 | + <div class="elementor-loader-box"></div> | |
| 80 | + <div class="elementor-loader-box"></div> | |
| 81 | + <div class="elementor-loader-box"></div> | |
| 82 | + </div> | |
| 83 | + </div> | |
| 84 | + <div class="elementor-loading-title"><?php echo esc_html__( 'Loading', 'elementor' ); ?></div> | |
| 85 | + </div> | |
| 86 | + </a> | |
| 87 | + </script> | |
| 88 | + <?php | |
| 89 | + } | |
| 90 | + | |
| 91 | + private function get_post_id() { | |
| 92 | + if ( Utils::get_super_global_value( $_GET, 'path' ) === null ) { | |
| 93 | + return false; | |
| 94 | + } | |
| 95 | + | |
| 96 | + $path_query = Utils::get_super_global_value( $_GET, 'path' ); | |
| 97 | + $query_string = isset( $path_query ) ? explode( '/', $path_query ) : []; | |
| 98 | + | |
| 99 | + return (int) end( $query_string ); | |
| 56 | 100 | } |
| 57 | 101 | } |