PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.7
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.2.7, at elementor-extensions/class-hider-addons.php

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