control
2 weeks ago
template-library
2 weeks ago
widgets
2 weeks ago
ControlsWidgets.php
2 weeks ago
EditorCondition.php
2 weeks ago
EditorScripts.php
1 year ago
Integration.php
1 year ago
RegisterWidgets.php
1 year ago
ShopPressStyler.php
2 weeks ago
ShopPressWidgets.php
2 weeks ago
EditorScripts.php
155 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Editor Scripts. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Elementor; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | class EditorScripts { |
| 13 | /** |
| 14 | * page_id. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | private static $page_id; |
| 19 | |
| 20 | /** |
| 21 | * Post type. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | private static $post_type; |
| 26 | |
| 27 | /** |
| 28 | * Builder type. |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | private static $custom_type; |
| 33 | |
| 34 | /** |
| 35 | * SP post types. |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | private static $post_types = array( 'shoppress_pages', 'shoppress_myaccount', 'shoppress_loop' ); |
| 40 | |
| 41 | /** |
| 42 | * Init. |
| 43 | * |
| 44 | * @since 1.2.0 |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public static function init() { |
| 49 | self::hooks(); |
| 50 | self::definitions(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Definitions. |
| 55 | * |
| 56 | * @since 1.2.0 |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | private static function definitions() { |
| 61 | self::$page_id = get_the_ID(); |
| 62 | self::$post_type = get_post_type(); |
| 63 | self::$custom_type = self::$page_id ? get_post_meta( self::$page_id, 'custom_type', true ) : 'undefined'; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Hooks. |
| 68 | * |
| 69 | * @since 1.2.0 |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | private static function hooks() { |
| 74 | add_action( 'elementor/editor/after_enqueue_scripts', array( __CLASS__, 'editor_scripts' ) ); |
| 75 | add_action( 'elementor/preview/enqueue_styles', array( __CLASS__, 'editor_preview_styles' ), 99 ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Editor scripts |
| 80 | * |
| 81 | * @since 1.2.0 |
| 82 | * |
| 83 | * @return void |
| 84 | */ |
| 85 | public static function editor_scripts() { |
| 86 | wp_enqueue_script( 'sp-elementor-editor', SHOPPRESS_URL . 'public/dist/admin/editor.js', array( 'jquery', 'elementor-editor', 'sp-frontend' ), SHOPPRESS_VERSION, true ); |
| 87 | |
| 88 | if ( in_array( self::$post_type, self::$post_types ) ) { |
| 89 | |
| 90 | wp_enqueue_style( 'sp-elementor-editor-custom', SHOPPRESS_URL . 'public/admin/elementor/sp-editor.css', null, SHOPPRESS_VERSION ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Editor styles for preview. |
| 96 | * |
| 97 | * @since 1.2.0 |
| 98 | * |
| 99 | * @return void |
| 100 | */ |
| 101 | public static function editor_preview_styles() { |
| 102 | |
| 103 | if ( 'single' === self::$custom_type || 'quick_view' === self::$custom_type || isset( self::$custom_type[0] ) && 'single' === self::$custom_type[0] ) { |
| 104 | |
| 105 | wp_enqueue_style( 'sp-single' ); |
| 106 | |
| 107 | if ( is_rtl() ) { |
| 108 | wp_enqueue_style( 'sp-single-rtl' ); |
| 109 | } |
| 110 | |
| 111 | do_action( 'shoppress/editor/single_preview_styles' ); |
| 112 | } |
| 113 | |
| 114 | $is_shop = in_array( self::$custom_type, array( 'shop', 'archive' ) ); |
| 115 | if ( $is_shop || 'shoppress_loop' === self::$post_type || in_array( 'custom_page', (array) self::$custom_type ) ) { |
| 116 | |
| 117 | do_action( 'shoppress/editor/shop_preview_styles' ); |
| 118 | } |
| 119 | |
| 120 | if ( 'cart' === self::$custom_type || 'empty_cart' === self::$custom_type || ( isset( self::$custom_type[0] ) && 'cart' === self::$custom_type[0] ) ) { |
| 121 | |
| 122 | wp_enqueue_style( 'sp-cart' ); |
| 123 | |
| 124 | if ( is_rtl() ) { |
| 125 | wp_enqueue_style( 'sp-cart-rtl' ); |
| 126 | } |
| 127 | |
| 128 | do_action( 'shoppress/editor/cart_preview_styles' ); |
| 129 | } |
| 130 | |
| 131 | if ( 'checkout' === self::$custom_type || isset( self::$custom_type[0] ) && 'checkout' === self::$custom_type[0] ) { |
| 132 | |
| 133 | wp_enqueue_style( 'sp-checkout' ); |
| 134 | |
| 135 | if ( is_rtl() ) { |
| 136 | wp_enqueue_style( 'sp-checkout-rtl' ); |
| 137 | } |
| 138 | |
| 139 | do_action( 'shoppress/editor/checkout_preview_styles' ); |
| 140 | } |
| 141 | |
| 142 | if ( 'shoppress_myaccount' === self::$post_type ) { |
| 143 | |
| 144 | wp_enqueue_style( 'sp-my-account' ); |
| 145 | wp_enqueue_style( 'sp-my-account-notifications' ); |
| 146 | |
| 147 | if ( is_rtl() ) { |
| 148 | wp_enqueue_style( 'sp-my-account-notifications-rtl' ); |
| 149 | } |
| 150 | |
| 151 | do_action( 'shoppress/editor/my_account_preview_styles' ); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 |