Custom_JS.php
1 year ago
Hover_Effect.php
1 year ago
Image_Masking.php
2 months ago
Liquid_Glass_Effect.php
5 months ago
Post_Duplicator.php
2 months ago
Promotion.php
9 months ago
Reading_Progress.php
5 months ago
Scroll_to_Top.php
5 months ago
Table_of_Content.php
2 weeks ago
Vertical_Text_Orientation.php
7 months ago
Wrapper_Link.php
2 months ago
index.php
3 years ago
Wrapper_Link.php
136 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Essential_Addons_Elementor\Extensions; |
| 4 | |
| 5 | use Elementor\Controls_Manager; |
| 6 | |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | class Wrapper_Link { |
| 13 | |
| 14 | /** |
| 15 | * Initialize hooks |
| 16 | */ |
| 17 | public function __construct() { |
| 18 | add_action( 'elementor/element/common/_section_style/after_section_end', [ $this, 'register_controls' ] ); |
| 19 | add_action( 'elementor/element/column/section_advanced/after_section_end', [ $this, 'register_controls' ] ); |
| 20 | add_action( 'elementor/element/section/section_advanced/after_section_end', [ $this, 'register_controls' ] ); |
| 21 | add_action( 'elementor/element/container/section_layout/after_section_end', [ $this, 'register_controls' ] ); |
| 22 | add_action( 'elementor/frontend/before_render', [ $this, 'before_render' ], 100 ); |
| 23 | //WPML Support |
| 24 | add_filter( 'elementor/frontend/before_render', [ $this, 'eael_container_before_wrapper_link_wpml' ] ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * WPML Support for container's wrapper link |
| 29 | */ |
| 30 | public function eael_container_before_wrapper_link_wpml( $element ) { |
| 31 | if ( 'container' !== $element->get_data( 'elType' ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | $settings = $element->get_settings(); |
| 36 | |
| 37 | if ( empty( $settings['eael_wrapper_link']['url'] ) ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | $lang = apply_filters( 'wpml_current_language', null ); |
| 42 | $url = apply_filters( 'wpml_permalink', $settings['eael_wrapper_link']['url'], $lang, true ); |
| 43 | |
| 44 | $settings['eael_wrapper_link']['url'] = $url; |
| 45 | $element->set_settings( 'eael_wrapper_link', $settings['eael_wrapper_link'] ); |
| 46 | } |
| 47 | |
| 48 | public function register_controls( $element ) { |
| 49 | $element->start_controls_section( |
| 50 | 'eael_wrapper_link_section', |
| 51 | [ |
| 52 | 'label' => __( '<i class="eaicon-logo"></i> Wrapper Link', 'essential-addons-for-elementor-lite' ), |
| 53 | 'tab' => Controls_Manager::TAB_ADVANCED |
| 54 | ] |
| 55 | ); |
| 56 | |
| 57 | $element->add_control( |
| 58 | 'eael_wrapper_link_switch', |
| 59 | [ |
| 60 | 'label' => __( 'Enable Wrapper Link', 'essential-addons-for-elementor-lite' ), |
| 61 | 'type' => Controls_Manager::SWITCHER |
| 62 | ] |
| 63 | ); |
| 64 | |
| 65 | $element->add_control( |
| 66 | 'eael_wrapper_link', |
| 67 | [ |
| 68 | 'label' => __( 'Link', 'essential-addons-for-elementor-lite' ), |
| 69 | 'type' => Controls_Manager::URL, |
| 70 | 'dynamic' => [ |
| 71 | 'active' => true, |
| 72 | ], |
| 73 | 'condition' => [ |
| 74 | 'eael_wrapper_link_switch!' => '' |
| 75 | ] |
| 76 | ] |
| 77 | ); |
| 78 | |
| 79 | $element->add_control( |
| 80 | 'eael_wrapper_link_disable_traditional', |
| 81 | [ |
| 82 | 'label' => __( 'Disable Traditional Link', 'essential-addons-for-elementor-lite' ), |
| 83 | 'type' => Controls_Manager::SWITCHER, |
| 84 | 'label_on' => esc_html__( 'Yes', 'essential-addons-for-elementor-lite' ), |
| 85 | 'label_off' => esc_html__( 'Off', 'essential-addons-for-elementor-lite' ), |
| 86 | 'return_value' => 'yes', |
| 87 | 'condition' => [ |
| 88 | 'eael_wrapper_link_switch!' => '' |
| 89 | ] |
| 90 | ] |
| 91 | ); |
| 92 | |
| 93 | $element->add_control( |
| 94 | 'ael_wrapper_link_warning_text', |
| 95 | [ |
| 96 | 'type' => Controls_Manager::RAW_HTML, |
| 97 | 'raw' => __('By Disabling <strong>Traditional Link</strong> some features (ex: dynamic tags, custom atrributes etc.) may not work.', 'essential-addons-for-elementor-lite'), |
| 98 | 'content_classes' => 'eael-warning', |
| 99 | 'condition' => [ |
| 100 | 'eael_wrapper_link_switch!' => '', |
| 101 | 'eael_wrapper_link_disable_traditional' => 'yes' |
| 102 | ] |
| 103 | ] |
| 104 | ); |
| 105 | |
| 106 | $element->end_controls_section(); |
| 107 | } |
| 108 | |
| 109 | public function before_render( $element ) { |
| 110 | $wrapper_link_settings = $element->get_settings_for_display( 'eael_wrapper_link' ); |
| 111 | |
| 112 | if ( "yes" === $element->get_settings_for_display( 'eael_wrapper_link_switch' ) && ! empty( $wrapper_link_settings['url'] ) ) { |
| 113 | $disable_traditional = $element->get_settings_for_display( 'eael_wrapper_link_disable_traditional' ); |
| 114 | if( 'yes' === $disable_traditional ){ |
| 115 | $element->add_render_attribute( '_wrapper', |
| 116 | 'data-eael-wrapper-link', |
| 117 | wp_json_encode( [ |
| 118 | 'url' => esc_url( $wrapper_link_settings['url'] ), |
| 119 | 'is_external' => esc_attr( $wrapper_link_settings['is_external'] ), |
| 120 | 'nofollow' => esc_attr( $wrapper_link_settings['nofollow'] ) |
| 121 | ] ) |
| 122 | ); |
| 123 | |
| 124 | $element->add_render_attribute( '_wrapper', 'class', 'eael-non-traditional-link' ); |
| 125 | } else { |
| 126 | $link_id = 'eael-wrapper-link-' . $element->get_id(); |
| 127 | $element->add_render_attribute( 'eael_wrapper_link', 'class', $link_id . ' --eael-wrapper-link-tag' ); |
| 128 | $element->add_link_attributes( 'eael_wrapper_link', $wrapper_link_settings ); |
| 129 | echo "<a "; $element->print_render_attribute_string( 'eael_wrapper_link' ); echo "></a>"; |
| 130 | |
| 131 | $element->add_render_attribute( '_wrapper', 'data-eael-wrapper-link', $link_id ); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 |