elementor.php
503 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Extends funtionality to Elementor Pagebuilder |
| 4 | * |
| 5 | * |
| 6 | * @copyright Copyright (c) 2017, Jeffrey Carandang |
| 7 | * @since 4.3 |
| 8 | */ |
| 9 | // Exit if accessed directly |
| 10 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 11 | |
| 12 | if( !function_exists( 'widgetopts_elementor_section' ) ){ |
| 13 | //Add "Widget Options" section to every Elementor Widgets |
| 14 | add_action( 'elementor/element/after_section_end', 'widgetopts_elementor_section', 10, 3 ); |
| 15 | function widgetopts_elementor_section( $element, $section_id, $args ){ |
| 16 | if ( Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 17 | global $widget_options; |
| 18 | |
| 19 | //filter the elements first to avoid conflicts that can cause pagebuilder not to load |
| 20 | if ( !in_array( $element->get_name(), array( 'global-settings', 'section', 'page-settings', 'oew-blog-grid' ) ) ) { |
| 21 | |
| 22 | //create array of section_id to set Widget Options Section to single section to avoid issues |
| 23 | $widgetopts_elementor_section_id = apply_filters( 'widgetopts_elementor_section_id', array( |
| 24 | 'section_image', |
| 25 | 'section_advanced', |
| 26 | 'section_title', |
| 27 | 'section_editor', |
| 28 | 'section_video', |
| 29 | 'section_button', |
| 30 | 'section_divider', |
| 31 | 'section_spacer', |
| 32 | 'section_map', |
| 33 | 'section_icon', |
| 34 | 'section_gallery', |
| 35 | 'section_image_carousel', |
| 36 | 'section_icon_list', |
| 37 | 'section_counter', |
| 38 | 'section_testimonial', |
| 39 | 'section_tabs', |
| 40 | 'section_toggle', |
| 41 | 'section_social_icon', |
| 42 | 'section_alert', |
| 43 | 'section_audio', |
| 44 | 'section_shortcode', |
| 45 | 'section_anchor', |
| 46 | 'section_sidebar', |
| 47 | 'section_layout', |
| 48 | 'section_slides', |
| 49 | 'section_form_fields', |
| 50 | 'section_list', |
| 51 | 'section_header', |
| 52 | 'section_pricing', |
| 53 | 'section_countdown', |
| 54 | 'section_buttons_content', |
| 55 | 'section_blockquote_content', |
| 56 | 'section_content', |
| 57 | 'section_login_content', |
| 58 | 'text_elements', |
| 59 | 'section_side_a_content', |
| 60 | 'section_side_b_content', |
| 61 | '_section_style' |
| 62 | ) |
| 63 | ); |
| 64 | |
| 65 | //filter by the section_ids above |
| 66 | if( in_array( $section_id, $widgetopts_elementor_section_id ) ){ |
| 67 | $element->start_controls_section( |
| 68 | 'widgetopts_section', |
| 69 | [ |
| 70 | 'tab' => Elementor\Controls_Manager::TAB_ADVANCED, |
| 71 | 'label' => __( 'Widget Options', 'widget-options' ), |
| 72 | ], |
| 73 | [ |
| 74 | 'overwrite' => true |
| 75 | ] |
| 76 | ); |
| 77 | |
| 78 | $element->start_controls_tabs( 'widgetopts_content_tabs',[ |
| 79 | 'overwrite' => true |
| 80 | ] ); |
| 81 | |
| 82 | if( isset( $widget_options['visibility'] ) && 'activate' == $widget_options['visibility'] ){ |
| 83 | widgetopts_elementor_tab_visibility( $element, $section_id, $args ); |
| 84 | } |
| 85 | |
| 86 | if( isset( $widget_options['state'] ) && 'activate' == $widget_options['state'] ){ |
| 87 | widgetopts_elementor_tab_state( $element, $section_id, $args ); |
| 88 | } |
| 89 | |
| 90 | if( 'activate' == $widget_options['logic'] || ( isset( $widget_options['sliding'] ) && 'activate' == $widget_options['sliding'] && in_array( $element->get_name(), array( 'button', 'button_plus', 'eael-creative-button', 'cta' ) ) ) ){ |
| 91 | widgetopts_elementor_tab_settings( $element, $section_id, $args ); |
| 92 | } |
| 93 | |
| 94 | //upsell pro |
| 95 | if( !is_plugin_active( 'extended-widget-options/plugin.php' ) ){ |
| 96 | $element->start_controls_tab( |
| 97 | 'widgetopts_tab_upsell', |
| 98 | [ |
| 99 | 'label' => __( '<i class="dashicons dashicons-plus"></i>', 'widget-options' ) |
| 100 | ], |
| 101 | [ |
| 102 | 'overwrite' => true |
| 103 | ] |
| 104 | ); |
| 105 | $upgrade_link = apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE).'?utm_source=elementor&utm_medium=upgrade&utm_campaign=upgradebtn'); |
| 106 | $element->add_control( |
| 107 | 'widgetopts_pro', |
| 108 | [ |
| 109 | 'type' => Elementor\Controls_Manager::RAW_HTML, |
| 110 | 'raw' => '<div class="elementor-panel-nerd-box"> |
| 111 | <i class="elementor-panel-nerd-box-icon dashicons dashicons-lock"></i> |
| 112 | <div class="elementor-panel-nerd-box-title">' . |
| 113 | __( 'Unlock All Widget Options', 'widget-options' ) . |
| 114 | '</div> |
| 115 | <div class="elementor-panel-nerd-box-message">' . |
| 116 | __( 'Upgrade to Extended Widget Options to unlock all options to easily control and manage each Elementor widget.', 'widget-options' ) . |
| 117 | '</div> |
| 118 | <a href="'.$upgrade_link.'" class="elementor-panel-nerd-box-link elementor-button elementor-button-default elementor-go-pro" target="_blank">' . |
| 119 | __( 'Upgrade Now!', 'widget-options' ) . |
| 120 | '</a> |
| 121 | </div>', |
| 122 | ], |
| 123 | [ |
| 124 | 'overwrite' => true |
| 125 | ] |
| 126 | ); |
| 127 | $element->end_controls_tab(); |
| 128 | } |
| 129 | $element->end_controls_tabs(); |
| 130 | |
| 131 | $element->end_controls_section(); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if( !function_exists( 'widgetopts_elementor_tab_visibility' ) ){ |
| 139 | function widgetopts_elementor_tab_visibility( $element, $section_id, $args ){ |
| 140 | global $widget_options, $widgetopts_taxonomies, $widgetopts_pages, $widgetopts_types, $widgetopts_categories; |
| 141 | |
| 142 | $pages = ( !empty( $widgetopts_pages ) ) ? $widgetopts_pages : array(); |
| 143 | $taxonomies = ( !empty( $widgetopts_taxonomies ) ) ? $widgetopts_taxonomies : array(); |
| 144 | $types = ( !empty( $widgetopts_types ) ) ? $widgetopts_types : array(); |
| 145 | $categories = ( !empty( $widgetopts_categories ) ) ? $widgetopts_categories : array(); |
| 146 | |
| 147 | // print_r( $get_terms['community-category'] ); |
| 148 | |
| 149 | $element->start_controls_tab( |
| 150 | 'widgetopts_tab_visibility', |
| 151 | [ |
| 152 | 'label' => __( '<span class="dashicons dashicons-visibility"></span>', 'widget-options' ) |
| 153 | ], |
| 154 | [ |
| 155 | 'overwrite' => true |
| 156 | ] |
| 157 | ); |
| 158 | |
| 159 | $element->add_control( |
| 160 | 'widgetopts_visibility', |
| 161 | [ |
| 162 | 'label' => __( 'Show/Hide', 'widget-options' ), |
| 163 | 'type' => Elementor\Controls_Manager::SELECT, |
| 164 | 'default' => 'hide', |
| 165 | 'options' => [ |
| 166 | 'show' => __( 'Show on Selected Pages' ), |
| 167 | 'hide' => __( 'Hide on Selected Pages' ) |
| 168 | ], |
| 169 | // 'separator' => 'none' |
| 170 | ], |
| 171 | [ |
| 172 | 'overwrite' => true |
| 173 | ] |
| 174 | ); |
| 175 | |
| 176 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['post_type'] ) && '1' == $widget_options['settings']['visibility']['post_type'] ){ |
| 177 | $pages_array = array(); |
| 178 | if( !empty( $pages ) ){ |
| 179 | foreach ( $pages as $page ) { |
| 180 | $pages_array[ $page->ID ] = $page->post_title; |
| 181 | } |
| 182 | |
| 183 | $element->add_control( |
| 184 | 'widgetopts_pages', |
| 185 | [ |
| 186 | 'label' => __( 'Pages', 'widget-options' ), |
| 187 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 188 | 'multiple' => true, |
| 189 | 'label_block' => true, |
| 190 | 'separator' => 'before', |
| 191 | 'options' => $pages_array, |
| 192 | 'render_type' => 'none', |
| 193 | 'description' => __( 'Click on the field to search and select pages', 'widget-options' ) |
| 194 | ], |
| 195 | [ |
| 196 | 'overwrite' => true |
| 197 | ] |
| 198 | ); |
| 199 | } |
| 200 | |
| 201 | if( !empty( $types ) ){ |
| 202 | $types_array = array(); |
| 203 | foreach ( $types as $ptype => $type ) { |
| 204 | $types_array[ $ptype ] = $type->labels->name; |
| 205 | } |
| 206 | |
| 207 | $element->add_control( |
| 208 | 'widgetopts_types', |
| 209 | [ |
| 210 | 'label' => __( 'Post Types', 'widget-options' ), |
| 211 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 212 | 'multiple' => true, |
| 213 | 'label_block' => true, |
| 214 | 'separator' => 'before', |
| 215 | 'options' => $types_array, |
| 216 | 'render_type' => 'none', |
| 217 | 'description' => __( 'Click on the field to search and select custom post types', 'widget-options' ) |
| 218 | ], |
| 219 | [ |
| 220 | 'overwrite' => true |
| 221 | ] |
| 222 | ); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['taxonomies'] ) && '1' == $widget_options['settings']['visibility']['taxonomies'] ){ |
| 227 | |
| 228 | if( !empty( $categories ) ){ |
| 229 | $cat_array = array(); |
| 230 | foreach ( $categories as $cat ) { |
| 231 | $cat_array[ $cat->cat_ID ] = $cat->cat_name; |
| 232 | } |
| 233 | |
| 234 | $element->add_control( |
| 235 | 'widgetopts_tax_category', |
| 236 | [ |
| 237 | 'label' => __( 'Categories', 'widget-options' ), |
| 238 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 239 | 'multiple' => true, |
| 240 | 'label_block' => true, |
| 241 | 'separator' => 'before', |
| 242 | 'options' => $cat_array, |
| 243 | 'render_type' => 'none', |
| 244 | 'description' => __( 'Click on the field to search and select categories', 'widget-options' ) |
| 245 | ], |
| 246 | [ |
| 247 | 'overwrite' => true |
| 248 | ] |
| 249 | ); |
| 250 | } |
| 251 | |
| 252 | if( !empty( $taxonomies ) ){ |
| 253 | $tax_array = array(); |
| 254 | foreach ( $taxonomies as $taxonomy ) { |
| 255 | $tax_array[ $taxonomy->name ] = $taxonomy->label; |
| 256 | } |
| 257 | |
| 258 | $element->add_control( |
| 259 | 'widgetopts_taxonomies', |
| 260 | [ |
| 261 | 'label' => __( 'Taxonomies', 'widget-options' ), |
| 262 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 263 | 'multiple' => true, |
| 264 | 'label_block' => true, |
| 265 | 'separator' => 'before', |
| 266 | 'options' => $tax_array, |
| 267 | 'render_type' => 'none', |
| 268 | 'description' => __( 'Click on the field to search and select taxonomies', 'widget-options' ) |
| 269 | ], |
| 270 | [ |
| 271 | 'overwrite' => true |
| 272 | ] |
| 273 | ); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['misc'] ) && '1' == $widget_options['settings']['visibility']['misc'] ){ |
| 278 | $element->add_control( |
| 279 | 'widgetopts_misc', |
| 280 | [ |
| 281 | 'label' => __( 'Miscellaneous', 'widget-options' ), |
| 282 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 283 | 'multiple' => true, |
| 284 | 'label_block' => true, |
| 285 | 'separator' => 'before', |
| 286 | 'options' => [ |
| 287 | 'home' => __( 'Home/Front', 'widget-options' ), |
| 288 | 'blog' => __( 'Blog', 'widget-options' ), |
| 289 | 'archives' => __( 'Archives', 'widget-options' ), |
| 290 | '404' => __( '404', 'widget-options' ), |
| 291 | 'search' => __( 'Search', 'widget-options' ) |
| 292 | ], |
| 293 | 'render_type' => 'none', |
| 294 | 'description' => __( 'Click on the field to search and select miscellaneous pages', 'widget-options' ) |
| 295 | ], |
| 296 | [ |
| 297 | 'overwrite' => true |
| 298 | ] |
| 299 | ); |
| 300 | } |
| 301 | $element->end_controls_tab(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | if( !function_exists( 'widgetopts_elementor_tab_state' ) ){ |
| 306 | function widgetopts_elementor_tab_state( $element, $section_id, $args ){ |
| 307 | global $widget_options; |
| 308 | |
| 309 | $element->start_controls_tab( |
| 310 | 'widgetopts_tab_state', |
| 311 | [ |
| 312 | 'label' => __( '<span class="dashicons dashicons-admin-users"></span>', 'widget-options' ) |
| 313 | ], |
| 314 | [ |
| 315 | 'overwrite' => true |
| 316 | ] |
| 317 | ); |
| 318 | |
| 319 | $element->add_control( |
| 320 | 'widgetopts_roles_state', |
| 321 | [ |
| 322 | 'label' => __( 'User Login State', 'widget-options' ), |
| 323 | 'type' => Elementor\Controls_Manager::SELECT, |
| 324 | 'default' => 'hide', |
| 325 | 'options' => [ |
| 326 | '' => __( 'Select Visibility Option' ), |
| 327 | 'in' => __( 'Show only for Logged-in Users' ), |
| 328 | 'out' => __( 'Show only for Logged-out Users' ) |
| 329 | ], |
| 330 | 'description' => __( 'Restrict widget visibility for logged-in and logged-out users.', 'widget-options' ) |
| 331 | ], |
| 332 | [ |
| 333 | 'overwrite' => true |
| 334 | ] |
| 335 | ); |
| 336 | |
| 337 | $element->end_controls_tab(); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if( !function_exists( 'widgetopts_elementor_tab_settings' ) ){ |
| 342 | function widgetopts_elementor_tab_settings( $element, $section_id, $args ){ |
| 343 | global $widget_options; |
| 344 | |
| 345 | $element->start_controls_tab( |
| 346 | 'widgetopts_tab_settings', |
| 347 | [ |
| 348 | 'label' => __( '<span class="dashicons dashicons-admin-generic"></span>', 'widget-options' ) |
| 349 | ], |
| 350 | [ |
| 351 | 'overwrite' => true |
| 352 | ] |
| 353 | ); |
| 354 | |
| 355 | if( is_plugin_active( 'sliding-widget-options/plugin.php' ) && 'activate' == $widget_options['sliding'] && in_array( $element->get_name(), array( 'button', 'button_plus', 'eael-creative-button', 'cta' ) ) ){ |
| 356 | $element->add_control( |
| 357 | 'widgetopts_open_sliding', |
| 358 | [ |
| 359 | 'label' => __( 'Open Pop-up or Sliding Widgets', 'widget-options' ), |
| 360 | 'type' => Elementor\Controls_Manager::SWITCHER, |
| 361 | 'return_value' => 'on', |
| 362 | 'default' => '', |
| 363 | 'separator' => 'none' |
| 364 | ], |
| 365 | [ |
| 366 | 'overwrite' => true |
| 367 | ] |
| 368 | ); |
| 369 | } |
| 370 | |
| 371 | if( 'activate' == $widget_options['logic'] ){ |
| 372 | |
| 373 | $element->add_control( |
| 374 | 'widgetopts_logic', |
| 375 | [ |
| 376 | 'type' => Elementor\Controls_Manager::TEXTAREA, |
| 377 | 'label' => __( 'Display Widget Logic', 'widget-options' ), |
| 378 | 'description' => __( 'Add your PHP Conditional Tags. Please note that this will be EVAL\'d directly.', 'widget-options' ), |
| 379 | // 'separator' => 'none', |
| 380 | ], |
| 381 | [ |
| 382 | 'overwrite' => true |
| 383 | ] |
| 384 | ); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | if( isset( $widget_options['acf'] ) && 'activate' == $widget_options['acf'] ){ |
| 389 | $fields = array(); |
| 390 | |
| 391 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 392 | $groups = acf_get_field_groups(); |
| 393 | if ( is_array( $groups ) ) { |
| 394 | foreach ( $groups as $group ) { |
| 395 | $fields_group = acf_get_fields( $group ); |
| 396 | if( !empty( $fields_group ) ){ |
| 397 | foreach ( $fields_group as $k => $fg ) { |
| 398 | $fields[ $fg['key'] ] = $fg['label']; |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | }else{ |
| 404 | $groups = apply_filters( 'acf/get_field_groups', array() ); |
| 405 | if ( is_array( $groups ) ) { |
| 406 | foreach ( $groups as $group ) { |
| 407 | $fields_group = apply_filters( 'acf/field_group/get_fields', array(), $group['id'] ); |
| 408 | if( !empty( $fields_group ) ){ |
| 409 | foreach ( $fields_group as $k => $fg ) { |
| 410 | $fields[ $fg['key'] ] = $fg['label']; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | $element->add_control( |
| 418 | 'widgetopts_acf_title', |
| 419 | [ |
| 420 | 'type' => Elementor\Controls_Manager::RAW_HTML, |
| 421 | 'separator' => 'before', |
| 422 | 'raw' => '<h3>'. __( 'Advanced Custom Fields', 'widget-options' ) .'</h3>', |
| 423 | ], |
| 424 | [ |
| 425 | 'overwrite' => true |
| 426 | ] |
| 427 | ); |
| 428 | |
| 429 | $element->add_control( |
| 430 | 'widgetopts_acf_visibility', |
| 431 | [ |
| 432 | 'label' => __( 'Show/Hide', 'widget-options' ), |
| 433 | 'type' => Elementor\Controls_Manager::SELECT, |
| 434 | 'default' => 'hide', |
| 435 | 'options' => [ |
| 436 | 'show' => __( 'Show when Condition\'s Met' ), |
| 437 | 'hide' => __( 'Hide when Condition\'s Met' ) |
| 438 | ], |
| 439 | 'separator' => 'before', |
| 440 | ], |
| 441 | [ |
| 442 | 'overwrite' => true |
| 443 | ] |
| 444 | ); |
| 445 | |
| 446 | $element->add_control( |
| 447 | 'widgetopts_acf_field', |
| 448 | [ |
| 449 | 'label' => __( 'Select ACF Field', 'widget-options' ), |
| 450 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 451 | 'multiple' => false, |
| 452 | 'label_block' => true, |
| 453 | 'options' => $fields, |
| 454 | 'render_type' => 'none', |
| 455 | 'description' => __( 'Select ACF field.', 'widget-options' ) |
| 456 | ], |
| 457 | [ |
| 458 | 'overwrite' => true |
| 459 | ] |
| 460 | ); |
| 461 | |
| 462 | $element->add_control( |
| 463 | 'widgetopts_acf_condition', |
| 464 | [ |
| 465 | 'label' => __( 'Condition', 'widget-options' ), |
| 466 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 467 | 'multiple' => false, |
| 468 | 'label_block' => true, |
| 469 | 'options' => [ |
| 470 | 'equal' => __( 'Is Equal To', 'widget-options' ), |
| 471 | 'not_equal' => __( 'Is Not Equal To', 'widget-options' ), |
| 472 | 'contains' => __( 'Contains', 'widget-options' ), |
| 473 | 'not_contains' => __( 'Does Not Contain', 'widget-options' ), |
| 474 | 'empty' => __( 'Is Empty', 'widget-options' ), |
| 475 | 'not_empty' => __( 'Is Not Empty', 'widget-options' ) |
| 476 | ], |
| 477 | 'render_type' => 'none', |
| 478 | 'description' => __( 'Select your condition for this widget visibility.', 'widget-options' ) |
| 479 | ], |
| 480 | [ |
| 481 | 'overwrite' => true |
| 482 | ] |
| 483 | ); |
| 484 | $element->add_control( |
| 485 | 'widgetopts_acf', |
| 486 | [ |
| 487 | 'type' => Elementor\Controls_Manager::TEXTAREA, |
| 488 | 'label' => __( 'Conditional Value', 'widget-options' ), |
| 489 | 'description' => __( 'Add your Conditional Value here if you selected Equal to, Not Equal To or Contains on the selection above.', 'widget-options' ), |
| 490 | // 'separator' => 'none', |
| 491 | ], |
| 492 | [ |
| 493 | 'overwrite' => true |
| 494 | ] |
| 495 | ); |
| 496 | } |
| 497 | |
| 498 | $element->end_controls_tab(); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | ?> |
| 503 |