PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Elementor / Integration.php
shop-press / Elementor Last commit date
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
Integration.php
215 lines
1 <?php
2 /**
3 * Elementor Integrations.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Elementor;
9
10 defined( 'ABSPATH' ) || exit;
11
12 class Integration {
13 /**
14 * init.
15 *
16 * @since 1.0.0
17 */
18 public static function init() {
19
20 if ( ! did_action( 'elementor/loaded' ) ) {
21 return false;
22 }
23
24 static::hooks();
25
26 // Init the widgets.
27 RegisterWidgets::init();
28 }
29
30 /**
31 * Init hooks.
32 *
33 * @since 1.0.0
34 */
35 private static function hooks() {
36 add_action( 'elementor/editor/after_enqueue_styles', array( __CLASS__, 'editor_styles' ) );
37 add_action( 'elementor/elements/categories_registered', array( __CLASS__, 'setup_categories' ) );
38 add_action( 'elementor/preview/enqueue_styles', array( __CLASS__, 'preview_styles' ) );
39 // add_action( 'elementor/init', array( __CLASS__, 'template_library' ), 0 );
40 add_action( 'elementor/init', array( __CLASS__, 'activate_fontawesome' ) );
41 add_filter( 'elementor/document/wrapper_attributes', array( __CLASS__, 'loop_builder_wrapper_attributes' ) );
42 add_action( 'elementor/widgets/register', array( __CLASS__, 'init_editor_scripts' ) );
43 add_action( 'elementor/preview/enqueue_styles', array( __CLASS__, 'loop_builder_editor_style' ) );
44 add_action( 'elementor/controls/register', array( __CLASS__, 'add_controls' ) );
45 }
46
47 /**
48 * Elementor editor styles.
49 *
50 * @since 1.0.0
51 */
52 public static function editor_styles() {
53 wp_enqueue_style( 'sp-elementor-editor', SHOPPRESS_URL . 'public/admin/elementor/editor.css', null, SHOPPRESS_VERSION );
54 }
55
56 /**
57 * Elementor preview styles.
58 *
59 * @since 1.1.3
60 */
61 public static function preview_styles() {
62 wp_enqueue_style( 'sp-elementor-preview', SHOPPRESS_URL . 'public/admin/elementor/preview.css', null, SHOPPRESS_VERSION );
63 }
64
65 /**
66 * Loop builder editor style.
67 *
68 * @since 1.0.0
69 */
70 public static function loop_builder_editor_style() {
71
72 if ( get_the_ID() ) {
73
74 $post_type = get_post_type( get_the_ID() );
75
76 if ( 'shoppress_loop' === $post_type ) {
77
78 echo '<style> .shoppress-wrap { max-width: 400px !important; margin: 0 auto !important; } .shoppress-wrap .elementor-section.elementor-section-boxed>.elementor-container { padding: 0 !important } .woocommerce ul.products li.product, .woocommerce-page ul.products li.product {width: 100% !important;} </style>';
79 }
80 }
81 }
82
83 /**
84 * Setup categories.
85 *
86 * @since 1.0.0
87 */
88 public static function setup_categories( $elements_manager ) {
89 $elements_manager->add_category(
90 'sp_woo_single',
91 array(
92 'icon' => 'eicon-single-product',
93 'title' => __( 'Product Single', 'shop-press' ),
94 )
95 );
96 $elements_manager->add_category(
97 'sp_woo_shop',
98 array(
99 'icon' => 'eicon-products-archive',
100 'title' => __( 'Shop', 'shop-press' ),
101 )
102 );
103 $elements_manager->add_category(
104 'sp_woo_dashboard',
105 array(
106 'icon' => 'eicon-dashboard',
107 'title' => __( 'My Account', 'shop-press' ),
108 )
109 );
110 $elements_manager->add_category(
111 'sp_woo_cart',
112 array(
113 'icon' => 'eicon-cart-light',
114 'title' => __( 'Cart', 'shop-press' ),
115 )
116 );
117 $elements_manager->add_category(
118 'sp_general',
119 array(
120 'icon' => 'eicon-global-settings',
121 'title' => __( 'ShopPress General', 'shop-press' ),
122 )
123 );
124 $elements_manager->add_category(
125 'sp_woo_checkout',
126 array(
127 'icon' => 'eicon-checkout',
128 'title' => __( 'Checkout', 'shop-press' ),
129 )
130 );
131 $elements_manager->add_category(
132 'sp_woo_loop',
133 array(
134 'icon' => 'eicon-products',
135 'title' => __( 'Product Loop', 'shop-press' ),
136 )
137 );
138 $elements_manager->add_category(
139 'sp_wishlist',
140 array(
141 'icon' => 'eicon-products',
142 'title' => __( 'Wishlist', 'shop-press' ),
143 )
144 );
145 $elements_manager->add_category(
146 'sp_compare',
147 array(
148 'icon' => 'eicon-products',
149 'title' => __( 'Compare', 'shop-press' ),
150 )
151 );
152 }
153
154 /**
155 * Change Post Query Before load.
156 *
157 * @since 1.2.0
158 */
159 public static function template_library() {
160 require_once SHOPPRESS_PATH . 'Elementor/template-library/TemplatesLib.php';
161 }
162
163 /**
164 * Activate Elementor FontAwesome Icons.
165 *
166 * @since 1.2.0
167 */
168 public static function activate_fontawesome() {
169
170 if ( ! get_option( 'elementor_load_fa4_shim' ) ) {
171 update_option( 'elementor_load_fa4_shim', 'yes' );
172 }
173 }
174
175 /**
176 * Add Essential HTML to elementor editor.
177 *
178 * @since 1.2.0
179 */
180 public static function loop_builder_wrapper_attributes( $attributes ) {
181
182 if ( isset( $attributes['data-elementor-title'] ) && get_post_type() === 'shoppress_loop' && \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
183 $attributes['class'] = 'product ' . $attributes['class'];
184 }
185 return $attributes;
186 }
187
188 /**
189 * Init the editor styles.
190 *
191 * @since 1.2.0
192 */
193 public static function init_editor_scripts() {
194 EditorScripts::init();
195 }
196
197 /**
198 * Add controls.
199 *
200 * @since 1.0.0
201 */
202 public static function add_controls( $controls_manager ) {
203
204 if ( ! did_action( 'elementor/loaded' ) ) {
205 return false;
206 }
207
208 require_once SHOPPRESS_PATH . 'Elementor/control/custom-css/CustomCSS.php';
209 require_once SHOPPRESS_PATH . 'Elementor/control/product-select/product-select.php';
210
211 $controls_manager->register( new \ShopPressElementorCustomCSS() );
212 $controls_manager->register( new \ShopPressSelectProduct() );
213 }
214 }
215