PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.0-dev2
Elementor Website Builder – more than just a page builder v3.24.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / wc-product-editor / module.php

module.php in Elementor Website Builder – more than just a page builder 3.24.0-dev2, at modules/wc-product-editor/module.php

102 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\WcProductEditor;
4
5 use Elementor\Core\Base\Module as BaseModule;
6 use Elementor\Plugin;
7 use Elementor\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Module extends BaseModule {
14
15 public function __construct() {
16 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
17 add_action( 'admin_footer', [ $this, 'print_button_js_template' ] );
18 }
19
20 public static function is_active() {
21 return self::is_new_woocommerce_product_editor_page();
22 }
23
24 public function enqueue_assets() {
25 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
26
27 wp_enqueue_script(
28 'elementor-wc-product-editor',
29 ELEMENTOR_ASSETS_URL . 'js/wc-product-editor' . $suffix . '.js',
30 [],
31 ELEMENTOR_VERSION,
32 true
33 );
34
35 wp_enqueue_style(
36 'elementor-wc-product-editor',
37 ELEMENTOR_ASSETS_URL . 'css/wc-product-editor' . $suffix . '.css',
38 [],
39 ELEMENTOR_VERSION
40 );
41 }
42
43 public function get_name() {
44 return 'wc-product-editor';
45 }
46
47 public static function is_new_woocommerce_product_editor_page() {
48 $page = Utils::get_super_global_value( $_GET, 'page' );
49 $path = Utils::get_super_global_value( $_GET, 'path' );
50
51 if ( ! isset( $page ) || 'wc-admin' !== $page || ! isset( $path ) ) {
52 return false;
53 }
54
55 $path_pieces = explode( '/', $path );
56 $route = $path_pieces[1];
57
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 );
100 }
101 }
102