elementor.php
502 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="fa fa-plus"></i>', 'widget-options' ) |
| 100 | ], |
| 101 | [ |
| 102 | 'overwrite' => true |
| 103 | ] |
| 104 | ); |
| 105 | $element->add_control( |
| 106 | 'widgetopts_pro', |
| 107 | [ |
| 108 | 'type' => Elementor\Controls_Manager::RAW_HTML, |
| 109 | 'raw' => '<div class="elementor-panel-nerd-box"> |
| 110 | <i class="elementor-panel-nerd-box-icon fa fa-lock"></i> |
| 111 | <div class="elementor-panel-nerd-box-title">' . |
| 112 | __( 'Unlock All Widget Options', 'widget-options' ) . |
| 113 | '</div> |
| 114 | <div class="elementor-panel-nerd-box-message">' . |
| 115 | __( 'Upgrade to Extended Widget Options to unlock all options to easily control and manage each Elementor widget.', 'widget-options' ) . |
| 116 | '</div> |
| 117 | <a href="http://widget-options.com/?utm_source=elementor&utm_medium=upgrade&utm_campaign=upgradebtn" class="elementor-panel-nerd-box-link elementor-button elementor-button-default elementor-go-pro" target="_blank">' . |
| 118 | __( 'Upgrade Now!', 'widget-options' ) . |
| 119 | '</a> |
| 120 | </div>', |
| 121 | ], |
| 122 | [ |
| 123 | 'overwrite' => true |
| 124 | ] |
| 125 | ); |
| 126 | $element->end_controls_tab(); |
| 127 | } |
| 128 | $element->end_controls_tabs(); |
| 129 | |
| 130 | $element->end_controls_section(); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if( !function_exists( 'widgetopts_elementor_tab_visibility' ) ){ |
| 138 | function widgetopts_elementor_tab_visibility( $element, $section_id, $args ){ |
| 139 | global $widget_options, $widgetopts_taxonomies, $widgetopts_pages, $widgetopts_types, $widgetopts_categories; |
| 140 | |
| 141 | $pages = ( !empty( $widgetopts_pages ) ) ? $widgetopts_pages : array(); |
| 142 | $taxonomies = ( !empty( $widgetopts_taxonomies ) ) ? $widgetopts_taxonomies : array(); |
| 143 | $types = ( !empty( $widgetopts_types ) ) ? $widgetopts_types : array(); |
| 144 | $categories = ( !empty( $widgetopts_categories ) ) ? $widgetopts_categories : array(); |
| 145 | |
| 146 | // print_r( $get_terms['community-category'] ); |
| 147 | |
| 148 | $element->start_controls_tab( |
| 149 | 'widgetopts_tab_visibility', |
| 150 | [ |
| 151 | 'label' => __( '<i class="fa fa-eye"></i>', 'widget-options' ) |
| 152 | ], |
| 153 | [ |
| 154 | 'overwrite' => true |
| 155 | ] |
| 156 | ); |
| 157 | |
| 158 | $element->add_control( |
| 159 | 'widgetopts_visibility', |
| 160 | [ |
| 161 | 'label' => __( 'Show/Hide', 'widget-options' ), |
| 162 | 'type' => Elementor\Controls_Manager::SELECT, |
| 163 | 'default' => 'hide', |
| 164 | 'options' => [ |
| 165 | 'show' => __( 'Show on Selected Pages' ), |
| 166 | 'hide' => __( 'Hide on Selected Pages' ) |
| 167 | ], |
| 168 | // 'separator' => 'none' |
| 169 | ], |
| 170 | [ |
| 171 | 'overwrite' => true |
| 172 | ] |
| 173 | ); |
| 174 | |
| 175 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['post_type'] ) && '1' == $widget_options['settings']['visibility']['post_type'] ){ |
| 176 | $pages_array = array(); |
| 177 | if( !empty( $pages ) ){ |
| 178 | foreach ( $pages as $page ) { |
| 179 | $pages_array[ $page->ID ] = $page->post_title; |
| 180 | } |
| 181 | |
| 182 | $element->add_control( |
| 183 | 'widgetopts_pages', |
| 184 | [ |
| 185 | 'label' => __( 'Pages', 'widget-options' ), |
| 186 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 187 | 'multiple' => true, |
| 188 | 'label_block' => true, |
| 189 | 'separator' => 'before', |
| 190 | 'options' => $pages_array, |
| 191 | 'render_type' => 'none', |
| 192 | 'description' => __( 'Click on the field to search and select pages', 'widget-options' ) |
| 193 | ], |
| 194 | [ |
| 195 | 'overwrite' => true |
| 196 | ] |
| 197 | ); |
| 198 | } |
| 199 | |
| 200 | if( !empty( $types ) ){ |
| 201 | $types_array = array(); |
| 202 | foreach ( $types as $ptype => $type ) { |
| 203 | $types_array[ $ptype ] = $type->labels->name; |
| 204 | } |
| 205 | |
| 206 | $element->add_control( |
| 207 | 'widgetopts_types', |
| 208 | [ |
| 209 | 'label' => __( 'Post Types', 'widget-options' ), |
| 210 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 211 | 'multiple' => true, |
| 212 | 'label_block' => true, |
| 213 | 'separator' => 'before', |
| 214 | 'options' => $types_array, |
| 215 | 'render_type' => 'none', |
| 216 | 'description' => __( 'Click on the field to search and select custom post types', 'widget-options' ) |
| 217 | ], |
| 218 | [ |
| 219 | 'overwrite' => true |
| 220 | ] |
| 221 | ); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['taxonomies'] ) && '1' == $widget_options['settings']['visibility']['taxonomies'] ){ |
| 226 | |
| 227 | if( !empty( $categories ) ){ |
| 228 | $cat_array = array(); |
| 229 | foreach ( $categories as $cat ) { |
| 230 | $cat_array[ $cat->cat_ID ] = $cat->cat_name; |
| 231 | } |
| 232 | |
| 233 | $element->add_control( |
| 234 | 'widgetopts_tax_category', |
| 235 | [ |
| 236 | 'label' => __( 'Categories', 'widget-options' ), |
| 237 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 238 | 'multiple' => true, |
| 239 | 'label_block' => true, |
| 240 | 'separator' => 'before', |
| 241 | 'options' => $cat_array, |
| 242 | 'render_type' => 'none', |
| 243 | 'description' => __( 'Click on the field to search and select categories', 'widget-options' ) |
| 244 | ], |
| 245 | [ |
| 246 | 'overwrite' => true |
| 247 | ] |
| 248 | ); |
| 249 | } |
| 250 | |
| 251 | if( !empty( $taxonomies ) ){ |
| 252 | $tax_array = array(); |
| 253 | foreach ( $taxonomies as $taxonomy ) { |
| 254 | $tax_array[ $taxonomy->name ] = $taxonomy->label; |
| 255 | } |
| 256 | |
| 257 | $element->add_control( |
| 258 | 'widgetopts_taxonomies', |
| 259 | [ |
| 260 | 'label' => __( 'Taxonomies', 'widget-options' ), |
| 261 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 262 | 'multiple' => true, |
| 263 | 'label_block' => true, |
| 264 | 'separator' => 'before', |
| 265 | 'options' => $tax_array, |
| 266 | 'render_type' => 'none', |
| 267 | 'description' => __( 'Click on the field to search and select taxonomies', 'widget-options' ) |
| 268 | ], |
| 269 | [ |
| 270 | 'overwrite' => true |
| 271 | ] |
| 272 | ); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if( isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['misc'] ) && '1' == $widget_options['settings']['visibility']['misc'] ){ |
| 277 | $element->add_control( |
| 278 | 'widgetopts_misc', |
| 279 | [ |
| 280 | 'label' => __( 'Miscellaneous', 'widget-options' ), |
| 281 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 282 | 'multiple' => true, |
| 283 | 'label_block' => true, |
| 284 | 'separator' => 'before', |
| 285 | 'options' => [ |
| 286 | 'home' => __( 'Home/Front', 'widget-options' ), |
| 287 | 'blog' => __( 'Blog', 'widget-options' ), |
| 288 | 'archives' => __( 'Archives', 'widget-options' ), |
| 289 | '404' => __( '404', 'widget-options' ), |
| 290 | 'search' => __( 'Search', 'widget-options' ) |
| 291 | ], |
| 292 | 'render_type' => 'none', |
| 293 | 'description' => __( 'Click on the field to search and select miscellaneous pages', 'widget-options' ) |
| 294 | ], |
| 295 | [ |
| 296 | 'overwrite' => true |
| 297 | ] |
| 298 | ); |
| 299 | } |
| 300 | $element->end_controls_tab(); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | if( !function_exists( 'widgetopts_elementor_tab_state' ) ){ |
| 305 | function widgetopts_elementor_tab_state( $element, $section_id, $args ){ |
| 306 | global $widget_options; |
| 307 | |
| 308 | $element->start_controls_tab( |
| 309 | 'widgetopts_tab_state', |
| 310 | [ |
| 311 | 'label' => __( '<i class="fa fa-user"></i>', 'widget-options' ) |
| 312 | ], |
| 313 | [ |
| 314 | 'overwrite' => true |
| 315 | ] |
| 316 | ); |
| 317 | |
| 318 | $element->add_control( |
| 319 | 'widgetopts_roles_state', |
| 320 | [ |
| 321 | 'label' => __( 'User Login State', 'widget-options' ), |
| 322 | 'type' => Elementor\Controls_Manager::SELECT, |
| 323 | 'default' => 'hide', |
| 324 | 'options' => [ |
| 325 | '' => __( 'Select Visibility Option' ), |
| 326 | 'in' => __( 'Show only for Logged-in Users' ), |
| 327 | 'out' => __( 'Show only for Logged-out Users' ) |
| 328 | ], |
| 329 | 'description' => __( 'Restrict widget visibility for logged-in and logged-out users.', 'widget-options' ) |
| 330 | ], |
| 331 | [ |
| 332 | 'overwrite' => true |
| 333 | ] |
| 334 | ); |
| 335 | |
| 336 | $element->end_controls_tab(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if( !function_exists( 'widgetopts_elementor_tab_settings' ) ){ |
| 341 | function widgetopts_elementor_tab_settings( $element, $section_id, $args ){ |
| 342 | global $widget_options; |
| 343 | |
| 344 | $element->start_controls_tab( |
| 345 | 'widgetopts_tab_settings', |
| 346 | [ |
| 347 | 'label' => __( '<i class="fa fa-cog"></i>', 'widget-options' ) |
| 348 | ], |
| 349 | [ |
| 350 | 'overwrite' => true |
| 351 | ] |
| 352 | ); |
| 353 | |
| 354 | 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' ) ) ){ |
| 355 | $element->add_control( |
| 356 | 'widgetopts_open_sliding', |
| 357 | [ |
| 358 | 'label' => __( 'Open Pop-up or Sliding Widgets', 'widget-options' ), |
| 359 | 'type' => Elementor\Controls_Manager::SWITCHER, |
| 360 | 'return_value' => 'on', |
| 361 | 'default' => '', |
| 362 | 'separator' => 'none' |
| 363 | ], |
| 364 | [ |
| 365 | 'overwrite' => true |
| 366 | ] |
| 367 | ); |
| 368 | } |
| 369 | |
| 370 | if( 'activate' == $widget_options['logic'] ){ |
| 371 | |
| 372 | $element->add_control( |
| 373 | 'widgetopts_logic', |
| 374 | [ |
| 375 | 'type' => Elementor\Controls_Manager::TEXTAREA, |
| 376 | 'label' => __( 'Display Widget Logic', 'widget-options' ), |
| 377 | 'description' => __( 'Add your PHP Conditional Tags. Please note that this will be EVAL\'d directly.', 'widget-options' ), |
| 378 | // 'separator' => 'none', |
| 379 | ], |
| 380 | [ |
| 381 | 'overwrite' => true |
| 382 | ] |
| 383 | ); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | if( isset( $widget_options['acf'] ) && 'activate' == $widget_options['acf'] ){ |
| 388 | $fields = array(); |
| 389 | |
| 390 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 391 | $groups = acf_get_field_groups(); |
| 392 | if ( is_array( $groups ) ) { |
| 393 | foreach ( $groups as $group ) { |
| 394 | $fields_group = acf_get_fields( $group ); |
| 395 | if( !empty( $fields_group ) ){ |
| 396 | foreach ( $fields_group as $k => $fg ) { |
| 397 | $fields[ $fg['key'] ] = $fg['label']; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | }else{ |
| 403 | $groups = apply_filters( 'acf/get_field_groups', array() ); |
| 404 | if ( is_array( $groups ) ) { |
| 405 | foreach ( $groups as $group ) { |
| 406 | $fields_group = apply_filters( 'acf/field_group/get_fields', array(), $group['id'] ); |
| 407 | if( !empty( $fields_group ) ){ |
| 408 | foreach ( $fields_group as $k => $fg ) { |
| 409 | $fields[ $fg['key'] ] = $fg['label']; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | $element->add_control( |
| 417 | 'widgetopts_acf_title', |
| 418 | [ |
| 419 | 'type' => Elementor\Controls_Manager::RAW_HTML, |
| 420 | 'separator' => 'before', |
| 421 | 'raw' => '<h3>'. __( 'Advanced Custom Fields', 'widget-options' ) .'</h3>', |
| 422 | ], |
| 423 | [ |
| 424 | 'overwrite' => true |
| 425 | ] |
| 426 | ); |
| 427 | |
| 428 | $element->add_control( |
| 429 | 'widgetopts_acf_visibility', |
| 430 | [ |
| 431 | 'label' => __( 'Show/Hide', 'widget-options' ), |
| 432 | 'type' => Elementor\Controls_Manager::SELECT, |
| 433 | 'default' => 'hide', |
| 434 | 'options' => [ |
| 435 | 'show' => __( 'Show when Condition\'s Met' ), |
| 436 | 'hide' => __( 'Hide when Condition\'s Met' ) |
| 437 | ], |
| 438 | 'separator' => 'before', |
| 439 | ], |
| 440 | [ |
| 441 | 'overwrite' => true |
| 442 | ] |
| 443 | ); |
| 444 | |
| 445 | $element->add_control( |
| 446 | 'widgetopts_acf_field', |
| 447 | [ |
| 448 | 'label' => __( 'Select ACF Field', 'widget-options' ), |
| 449 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 450 | 'multiple' => false, |
| 451 | 'label_block' => true, |
| 452 | 'options' => $fields, |
| 453 | 'render_type' => 'none', |
| 454 | 'description' => __( 'Select ACF field.', 'widget-options' ) |
| 455 | ], |
| 456 | [ |
| 457 | 'overwrite' => true |
| 458 | ] |
| 459 | ); |
| 460 | |
| 461 | $element->add_control( |
| 462 | 'widgetopts_acf_condition', |
| 463 | [ |
| 464 | 'label' => __( 'Condition', 'widget-options' ), |
| 465 | 'type' => Elementor\Controls_Manager::SELECT2, |
| 466 | 'multiple' => false, |
| 467 | 'label_block' => true, |
| 468 | 'options' => [ |
| 469 | 'equal' => __( 'Is Equal To', 'widget-options' ), |
| 470 | 'not_equal' => __( 'Is Not Equal To', 'widget-options' ), |
| 471 | 'contains' => __( 'Contains', 'widget-options' ), |
| 472 | 'not_contains' => __( 'Does Not Contain', 'widget-options' ), |
| 473 | 'empty' => __( 'Is Empty', 'widget-options' ), |
| 474 | 'not_empty' => __( 'Is Not Empty', 'widget-options' ) |
| 475 | ], |
| 476 | 'render_type' => 'none', |
| 477 | 'description' => __( 'Select your condition for this widget visibility.', 'widget-options' ) |
| 478 | ], |
| 479 | [ |
| 480 | 'overwrite' => true |
| 481 | ] |
| 482 | ); |
| 483 | $element->add_control( |
| 484 | 'widgetopts_acf', |
| 485 | [ |
| 486 | 'type' => Elementor\Controls_Manager::TEXTAREA, |
| 487 | 'label' => __( 'Conditional Value', 'widget-options' ), |
| 488 | 'description' => __( 'Add your Conditional Value here if you selected Equal to, Not Equal To or Contains on the selection above.', 'widget-options' ), |
| 489 | // 'separator' => 'none', |
| 490 | ], |
| 491 | [ |
| 492 | 'overwrite' => true |
| 493 | ] |
| 494 | ); |
| 495 | } |
| 496 | |
| 497 | $element->end_controls_tab(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | ?> |
| 502 |