PluginProbe
WP Directory Kit / 1.3.1
WP Directory Kit v1.3.1
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / elementor-extensions / class-hider-addons.php

class-hider-addons.php in WP Directory Kit 1.3.1, at elementor-extensions/class-hider-addons.php

401 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH'))
4 exit; // Exit if accessed directly
5
6 use Elementor\Plugin;
7 use Elementor\Controls_Manager;
8 use Elementor\Modules\DynamicTags\Module;
9
10 add_action( 'elementor/init', function() {
11 new WDK_Extension_Hider_Addons();
12 });
13
14 /**
15 * WDK_Extension_Hider_Addons
16 *
17 * Class to extend Elementor controls functionality, adding hide feature based on specific wdk field
18 *
19 */
20
21 class WDK_Extension_Hider_Addons {
22
23 public $name = 'WDK Hider Addons';
24
25 private $is_common = true;
26
27 private $depended_scripts = [];
28
29 private $depended_styles = [];
30
31 private $has_controls = TRUE;
32
33 public $addons = array();
34
35 public $common_sections_actions = array(
36 array(
37 'element' => 'common',
38 'action' => '_section_style',
39 ),
40 array(
41 'element' => 'section',
42 'action' => 'section_advanced',
43 ),
44 array(
45 'element' => 'container',
46 'action' => 'section_layout',
47 ),
48 array(
49 'element' => 'column',
50 'action' => 'section_advanced',
51 ),
52 );
53
54 private $supported_elements = array(
55 'heading'
56 );
57
58 public function __construct() {
59
60 /*
61 Controls_Manager::add_tab(
62 'wdk_hider',
63 __( 'Hider', 'wpdirectorykit' )
64 );*/
65
66
67 $this->addons = array();
68
69 $this->addons [] = array(
70 'title' => __('Energy efficiency', 'wpdirectorykit'),
71 'slug' => 'sweet_energy_efficiency',
72 'is_activated_slug' => 'run_sweet_energy_efficiency',
73 );
74
75 $this->addons [] = array(
76 'title' => __('Multy Currency', 'wpdirectorykit'),
77 'slug' => 'wdk_currency_conversion',
78 'is_activated_slug' => 'run_wdk_currency_conversion',
79 );
80
81 $this->addons [] = array(
82 'title' => __('Booking & Calendar', 'wpdirectorykit'),
83 'slug' => 'wdk_bookings',
84 'is_activated_slug' => 'run_wdk_bookings',
85 );
86
87 $this->addons [] = array(
88 'title' => __('Review system', 'wpdirectorykit'),
89 'slug' => 'wdk_reviews',
90 'is_activated_slug' => 'run_wdk_reviews',
91 );
92
93 $this->addons [] = array(
94 'title' => __('Membership Features', 'wpdirectorykit'),
95 'slug' => 'wdk_membership',
96 'is_activated_slug' => 'run_wdk_membership',
97 );
98
99 $this->addons [] = array(
100 'title' => __('Import/Export', 'wpdirectorykit'),
101 'slug' => 'wdk_export_xml',
102 'is_activated_slug' => 'wdk_export_xml',
103 );
104
105 $this->addons [] = array(
106 'title' => __('Favorites', 'wpdirectorykit'),
107 'slug' => 'wdk_favorites',
108 'is_activated_slug' => 'run_wdk_favorites',
109 );
110
111 $this->addons [] = array(
112 'title' => __('Mortgage Calculator', 'wpdirectorykit'),
113 'slug' => 'wdk_mortgage',
114 'is_activated_slug' => 'run_wdk_mortgage',
115 );
116
117 $this->addons [] = array(
118 'title' => __('Profile picture uploader', 'wpdirectorykit'),
119 'slug' => 'profile_picture_uploader',
120 'is_activated_slug' => 'ppu_custom_user_profile_fields',
121 );
122
123 $this->addons [] = array(
124 'title' => __('MailChimp Newsletter', 'wpdirectorykit'),
125 'slug' => 'wdk_mailchimp',
126 'is_activated_slug' => 'run_wdk_mailchimp',
127 );
128
129 $this->addons [] = array(
130 'title' => __('Facebook Comments', 'wpdirectorykit'),
131 'slug' => 'wdk_facebook_comments',
132 'is_activated_slug' => 'run_wdk_facebook_comments',
133 );
134
135 $this->addons [] = array(
136 'title' => __('Report Abuse', 'wpdirectorykit'),
137 'slug' => 'wdk_report_abuse',
138 'is_activated_slug' => 'run_wdk_report_abuse',
139 );
140
141 $this->addons [] = array(
142 'title' => __('Payments Listing Packages', 'wpdirectorykit'),
143 'slug' => 'wdk_payments',
144 'is_activated_slug' => 'run_wdk_payments',
145 );
146
147 $this->addons [] = array(
148 'title' => __('Compare Listings', 'wpdirectorykit'),
149 'slug' => 'wdk_compare_listing',
150 'is_activated_slug' => 'run_wdk_compare_listing',
151 );
152
153 $this->addons [] = array(
154 'title' => __('Save Search', 'wpdirectorykit'),
155 'slug' => 'wdk_save_search',
156 'is_activated_slug' => 'run_wdk_save_search',
157 );
158
159 $this->addons [] = array(
160 'title' => __('WDK Claim / Take Ownership', 'wpdirectorykit'),
161 'slug' => 'wdk_listing_claim',
162 'is_activated_slug' => 'run_wdk_listing_claim',
163 );
164
165 $this->addons [] = array(
166 'title' => __('WDK PDF Download', 'wpdirectorykit'),
167 'slug' => 'wdk_pdf_export',
168 'is_activated_slug' => 'run_wdk_pdf_export',
169 );
170
171 $this->init();
172 }
173
174 public function init( $param = null ) {
175 // Enqueue scripts
176 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
177
178 // Enqueue styles
179 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_styles' ] );
180
181 // Elementor hooks
182
183 if ( $this->is_common ) {
184 // Add the advanced section required to display controls
185 $this->add_common_sections_actions();
186 }
187
188 $this->add_actions();
189 }
190
191 public static function is_enabled() {
192 return true;
193 }
194
195 public function add_script_depends( $handler ) {
196 $this->depended_scripts[] = $handler;
197 }
198
199 public function add_style_depends( $handler ) {
200 $this->depended_styles[] = $handler;
201 }
202
203 public function get_script_depends() {
204 return $this->depended_scripts;
205 }
206
207 public function enqueue_scripts() {
208 foreach ( $this->get_script_depends() as $script ) {
209 wp_enqueue_script( $script );
210 }
211 }
212
213 public function get_style_depends() {
214 return $this->depended_styles;
215 }
216
217 public static function get_description() {
218 return '';
219 }
220
221 public function enqueue_styles() {
222 foreach ( $this->get_style_depends() as $style ) {
223 wp_enqueue_style( $style );
224 }
225 }
226
227 public function _enqueue_scripts() {
228 $scripts = $this->get_script_depends();
229 if ( ! empty( $scripts ) ) {
230 foreach ( $scripts as $script ) {
231 wp_enqueue_script( $script );
232 }
233 }
234 }
235
236 public function _enqueue_styles() {
237 $styles = $this->get_style_depends();
238 if ( ! empty( $styles ) ) {
239 foreach ( $styles as $style ) {
240 wp_enqueue_style( $style );
241 }
242 }
243 }
244
245 public function enqueue_all() {
246 $this->_enqueue_styles();
247 $this->_enqueue_scripts();
248 }
249
250 public function get_low_name() {
251 return 'hider-addons';
252 }
253
254 final public function add_common_sections( $element, $args ) {
255 $low_name = $this->get_low_name();
256 $section_name = 'wdk_section_' . $low_name . '_advanced';
257
258 if ( ! $this->has_controls ) {
259 // no need settings
260 return false;
261 }
262
263 // Check if this section exists
264 $section_exists = \Elementor\Plugin::instance()->controls_manager->get_control_from_stack( $element->get_unique_name(), $section_name );
265
266 if ( ! is_wp_error( $section_exists ) ) {
267 // We can't and should try to add this section to the stack
268 return false;
269 }
270
271 $this->get_control_section( $section_name, $element );
272 }
273
274 public function add_common_sections_actions() {
275 foreach ( $this->common_sections_actions as $action ) {
276 // Activate action for elements
277 add_action('elementor/element/' . $action['element'] . '/' . $action['action'] . '/after_section_end', function ( $element, $args ) {
278 $this->add_common_sections( $element, $args );
279 }, 10, 2);
280 }
281 }
282
283 protected function add_actions() {
284
285 // WIDGET
286 add_action( 'elementor/frontend/widget/before_render', [ $this, '_start_element' ], 10, 1 );
287 add_action( 'elementor/frontend/widget/after_render', [ $this, '_end_element' ], 10, 1 );
288
289 // SECTION
290 add_action( 'elementor/frontend/section/before_render', [ $this, '_start_element' ], 10, 1 );
291 add_action( 'elementor/frontend/section/after_render', [ $this, '_end_element' ], 10, 1 );
292
293 // CONTAINER
294 add_action( 'elementor/frontend/container/before_render', [ $this, '_start_element' ], 10, 1 );
295 add_action( 'elementor/frontend/container/after_render', [ $this, '_end_element' ], 10, 1 );
296
297 // COLUMN
298 add_action( 'elementor/frontend/column/before_render', [ $this, '_start_element' ], 10, 1 );
299 add_action( 'elementor/frontend/column/after_render', [ $this, '_end_element' ], 10, 1 );
300
301
302 }
303
304 protected function remove_controls( $element, $controls = null ) {
305 if ( empty( $controls ) ) {
306 return;
307 }
308
309 if ( is_array( $controls ) ) {
310 $control_id = $controls;
311
312 foreach ( $controls as $control_id ) {
313 $element->remove_control( $control_id );
314 }
315 } else {
316 $element->remove_control( $controls );
317 }
318 }
319
320 public function get_control_section( $section_name, $element ) {
321 $low_name = $this->get_low_name();
322
323 $element->start_controls_section(
324 $section_name,
325 [
326 'label' => '<span class="color-wdk icon icon-dyn-logo-wdk pull-right ml-1"></span> ' . $this->name,
327 'tab' => 'advanced',
328 ]
329 );
330
331 foreach($this->addons as $addon) {
332 $element->add_control(
333 'wdk_addon_hide_'.wmvc_show_data('slug', $addon, '', TRUE, TRUE),
334 [
335 'label' => wmvc_show_data('title', $addon, '', TRUE, TRUE),
336 'type' => \Elementor\Controls_Manager::SWITCHER,
337 'label_on' => __( 'On', 'wpdirectorykit' ),
338 'label_off' => __( 'Off', 'wpdirectorykit' ),
339 'return_value' => 'true',
340 'default' => '',
341 ]
342 );
343 }
344
345
346 $element->end_controls_section();
347
348 }
349
350 public function _start_element( $element ) {
351 if(Plugin::$instance->editor->is_edit_mode())return;
352
353 $element_skip = FALSE;
354 $settings = $element->get_settings_for_display();
355 foreach($this->addons as $addon) {
356 $key = 'wdk_addon_hide_'.wmvc_show_data('slug', $addon, '', TRUE, TRUE);
357 if(isset($settings[$key]) && $settings[$key] == 'true') {
358
359 if(!function_exists(wmvc_show_data('is_activated_slug', $addon, 'wdk_non_function', TRUE, TRUE))) {
360 $element_skip = TRUE;
361 break;
362 }
363 }
364 }
365
366 if($element_skip)
367 {
368 ob_start();
369 }
370 }
371
372 public function _end_element( $element ) {
373 if(Plugin::$instance->editor->is_edit_mode())return;
374
375 $element_skip = FALSE;
376 $settings = $element->get_settings_for_display();
377 foreach($this->addons as $addon) {
378 $key = 'wdk_addon_hide_'.wmvc_show_data('slug', $addon, '', TRUE, TRUE);
379 if(isset($settings[$key]) && $settings[$key] == 'true') {
380
381 if(!function_exists(wmvc_show_data('is_activated_slug', $addon, 'wdk_non_function', TRUE, TRUE))) {
382 $element_skip = TRUE;
383 break;
384 }
385 }
386 }
387
388 if($element_skip)
389 {
390 $content = ob_get_clean();
391 }
392 }
393
394 }
395
396
397
398
399
400
401