# king-addons/51.1.83/includes/features/Wrapper_Link/Wrapper_Link.php

King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder, version 51.1.83. 119 lines.

- Page: https://pluginprobe.com/plugins/king-addons/51.1.83/code/includes/features/Wrapper_Link/Wrapper_Link.php
- Raw: https://pluginprobe.com/plugins/king-addons/51.1.83/raw/includes/features/Wrapper_Link/Wrapper_Link.php
- Modified: 2026-09-16T13:52:08+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/king-addons/51.1.83/code/includes/features/Wrapper_Link/Wrapper_Link.php#L10-L20`.

```php
<?php /** @noinspection PhpUnused */

namespace King_Addons;

use Elementor\Controls_Manager;
use Elementor\Element_Base;

/** @noinspection SpellCheckingInspection */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

class Wrapper_Link
{
    private static ?Wrapper_Link $_instance = null;

    public static function instance(): Wrapper_Link
    {
        if (is_null(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function __construct()
    {
        add_action('elementor/element/container/section_layout/after_section_end', [__CLASS__, 'addControls'], 1);
        add_action('elementor/element/column/section_advanced/after_section_end', [__CLASS__, 'addControls'], 1);
        add_action('elementor/element/section/section_advanced/after_section_end', [__CLASS__, 'addControls'], 1);
        add_action('elementor/element/common/_section_style/after_section_end', [__CLASS__, 'addControls'], 1);
        add_action('elementor/frontend/before_render', [__CLASS__, 'renderLink'], 1);
    }

    public static function addControls(Element_Base $element): void
    {
        $element->start_controls_section(
            'kng_wrapper_link_section',
            [
                'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Wrapper Link', 'king-addons'),
                'tab' => Controls_Manager::TAB_ADVANCED
            ]
        );

        $element->add_control(
            'kng_wrapper_link_switch',
            [
                'label' => esc_html__('Enable Wrapper Link', 'king-addons'),
                'type' => Controls_Manager::SWITCHER
            ]
        );

        $element->add_control(
            'kng_wrapper_link',
            [
                'label' => esc_html__('Link', 'king-addons'),
                'type' => Controls_Manager::URL,
                'placeholder' => esc_html__('https://example.com', 'king-addons'),
                'options' => [
                    'url',
                    'is_external'
                ],
                'condition' => [
                    'kng_wrapper_link_switch!' => ''
                ]
            ]
        );

        $element->end_controls_section();
    }

    /**
     * Loads the click handler, and only for pages that actually use the feature.
     *
     * @return void
     */
    private static function enqueueScript(): void
    {
        $handle = KING_ADDONS_ASSETS_UNIQUE_KEY . '-wrapper-link-wrapper-link';

        if (!wp_script_is($handle, 'enqueued')) {
            wp_enqueue_script($handle);
        }
    }

    public static function renderLink(Element_Base $element): void
    {
        if (!empty($element->get_settings_for_display('kng_wrapper_link_switch'))) {

            $wrapper_link_settings = $element->get_settings_for_display('kng_wrapper_link');

            if (!empty($wrapper_link_settings['url'])) {

                $url = esc_url_raw($wrapper_link_settings['url']);
                if (empty($url)) {
                    return;
                }

                $link_target = (!empty($wrapper_link_settings['is_external'])) ? '_blank' : '_self';

                /**
                 * The URL travels in a data attribute and the click is handled by
                 * wrapper-link.js. An inline onclick fired on every click that
                 * bubbled up, so a link inside the container navigated twice —
                 * once itself and once through the wrapper.
                 */
                $element->add_render_attribute(
                    '_wrapper',
                    [
                        'style' => 'cursor: pointer;',
                        'data-kng-wrapper-link' => $url,
                        'data-kng-wrapper-link-target' => $link_target,
                    ]
                );

                self::enqueueScript();
            }
        }
    }
}
```
