| 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( 'enqueue_block_editor_assets', [ $this, 'enqueue_assets' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
public static function is_active() { |
| 20 |
return self::is_new_woocommerce_product_editor_page(); |
| 21 |
} |
| 22 |
|
| 23 |
public function enqueue_assets() { |
| 24 |
$suffix = Utils::is_script_debug() ? '' : '.min'; |
| 25 |
|
| 26 |
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' ], |
| 30 |
ELEMENTOR_VERSION, |
| 31 |
true |
| 32 |
); |
| 33 |
|
| 34 |
$elementor_settings = [ |
| 35 |
'editLink' => admin_url( 'post.php' ), |
| 36 |
]; |
| 37 |
Utils::print_js_config( 'e-wc-product-editor', 'ElementorWCProductEditorSettings', $elementor_settings ); |
| 38 |
} |
| 39 |
|
| 40 |
public function get_name() { |
| 41 |
return 'wc-product-editor'; |
| 42 |
} |
| 43 |
|
| 44 |
public static function is_new_woocommerce_product_editor_page() { |
| 45 |
$page = Utils::get_super_global_value( $_GET, 'page' ); |
| 46 |
$path = Utils::get_super_global_value( $_GET, 'path' ); |
| 47 |
|
| 48 |
if ( ! isset( $page ) || 'wc-admin' !== $page || ! isset( $path ) ) { |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
$path_pieces = explode( '/', $path ); |
| 53 |
$route = $path_pieces[1]; |
| 54 |
|
| 55 |
return 'product' === $route || 'add-product' === $route; |
| 56 |
} |
| 57 |
} |
| 58 |
|