get_settings_for_display(); foreach (['aad_visibility_toggle', 'aad_visibility_toggle_container'] as $key) { if (isset($settings[$key])) { $class = aad_get_visibility_class($settings[$key]); if ($class) { $element->add_render_attribute('_wrapper', 'class', $class); } } } } } //<< 2.0 – Control Injection (Widgets, Sections, Columns) foreach (['common', 'section', 'column'] as $type) { add_action("elementor/element/{$type}/_section_style/after_section_end", function($element) use ($type) { if (method_exists($element, 'get_controls') && isset($element->get_controls()['aad_visibility_section'])) { return; } $element->start_controls_section('aad_visibility_section', [ 'label' => __('Adaptive Audience Display', 'adaptive-audience-display'), 'tab' => \Elementor\Controls_Manager::TAB_ADVANCED, ]); //<< 2.1 – Login State Toggle $element->add_control('aad_visibility_toggle', [ 'label' => __('Show Element', 'adaptive-audience-display'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'always', 'options' => [ 'always' => esc_html__('Always', 'adaptive-audience-display'), 'logged_in' => esc_html__('When the user is logged in', 'adaptive-audience-display'), 'logged_out' => esc_html__('When the user is logged out', 'adaptive-audience-display'), ], ]); //<< 2.2 – Role-Based Toggle if ( ! aad_is_pro_active() ) { $element->add_control('aad_enable_role_toggle', [ 'label' => __('Enable Role Based Visibility', 'adaptive-audience-display'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'adaptive-audience-display'), 'label_off' => __('No', 'adaptive-audience-display'), 'return_value' => 'yes', 'default' => 'no', ]); } //<< 2.3 – Divider Text (CTA for Widgets/Sections/Columns) – MATCH 3.3 FORMAT if ( ! aad_is_pro_active() ) { $element->add_control( 'aad_role_divider_widgets', [ 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => '
' . esc_html__( '— Upgrade To PRO Version —', 'adaptive-audience-display' ) . '
' . esc_html__( 'Unlock Role-Based Visibility', 'adaptive-audience-display' ) . '
', 'content_classes' => 'aad-role-divider', 'separator' => 'none', 'condition' => [ 'aad_enable_role_toggle' => 'yes', ], ] ); } //<< 2.4 – Dynamic Role List $roles = wp_roles()->roles; foreach ($roles as $role_key => $role_details) { $element->add_control('aad_role_toggle_' . $role_key, [ 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => '
' . esc_html($role_details['name']) . ' ' . esc_attr__('Locked Toggle', 'adaptive-audience-display') . '
', 'content_classes' => 'aad-role-locked', 'condition' => [ 'aad_enable_role_toggle' => 'yes', ], ]); } $element->end_controls_section(); }, 10, 2); } //<< 3.0 – Control Injection (Containers) add_action('elementor/element/container/section_layout/after_section_end', function($element) { if (method_exists($element, 'get_controls') && isset($element->get_controls()['aad_visibility_section_container'])) { return; } $element->start_controls_section('aad_visibility_section_container', [ 'label' => __('Adaptive Audience Display', 'adaptive-audience-display'), 'tab' => \Elementor\Controls_Manager::TAB_ADVANCED, ]); //<< 3.1 – Login State Toggle $element->add_control('aad_visibility_toggle_container', [ 'label' => __('Show Element', 'adaptive-audience-display'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'always', 'options' => [ 'always' => esc_html__('Always', 'adaptive-audience-display'), 'logged_in' => esc_html__('When the user is logged in', 'adaptive-audience-display'), 'logged_out' => esc_html__('When the user is logged out', 'adaptive-audience-display'), ], ]); //<< 3.2 – Role-Based Toggle if ( ! aad_is_pro_active() ) { $element->add_control('aad_enable_role_toggle', [ 'label' => __('Enable Role Based Visibility', 'adaptive-audience-display'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'adaptive-audience-display'), 'label_off' => __('No', 'adaptive-audience-display'), 'return_value' => 'yes', 'default' => 'no', ]); } //<< 3.3 – Divider Text (leave as-is per user request) $element->add_control( 'aad_role_divider', [ 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => '
' . esc_html__( '— Upgrade To PRO Version —', 'adaptive-audience-display' ) . '
' . esc_html__( 'Unlock Role-Based Visibility', 'adaptive-audience-display' ) . '
', 'content_classes' => 'aad-role-divider', 'separator' => 'none', 'condition' => [ 'aad_enable_role_toggle' => 'yes', ], ] ); //<< 3.4 – Dynamic Role List $roles = wp_roles()->roles; foreach ($roles as $role_key => $role_details) { $element->add_control('aad_role_toggle_' . $role_key, [ 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => '
' . esc_html($role_details['name']) . ' ' . esc_attr__('Locked Toggle', 'adaptive-audience-display') . '
', 'content_classes' => 'aad-role-locked', 'condition' => [ 'aad_enable_role_toggle' => 'yes', ], ]); } $element->end_controls_section(); }, 10, 2); //<< 4.0 – Visibility Class Injection add_action('elementor/frontend/widget/before_render', 'aad_auto_class_assignment'); add_action('elementor/frontend/container/before_render', 'aad_auto_class_assignment'); add_action('elementor/frontend/section/before_render', 'aad_auto_class_assignment'); //<< 5.0 – CSS Fallback + JS Logic add_action('wp_enqueue_scripts', function () { wp_register_style('aad-visibility-inline', false, [], '1.1.28'); wp_enqueue_style('aad-visibility-inline'); wp_add_inline_style('aad-visibility-inline', ' .aad-hide-logged-in, .aad-hide-logged-out { display: none !important; } '); wp_register_script('aad-visibility-inline', '', [], '1.1.28', true); wp_enqueue_script('aad-visibility-inline'); wp_add_inline_script('aad-visibility-inline', ' document.addEventListener("DOMContentLoaded", function() { const isLoggedIn = document.body.classList.contains("logged-in"); const forceShow = function(el) { let current = el; while (current && current.tagName.toLowerCase() !== "body") { const computedDisplay = window.getComputedStyle(current).display; let restoreDisplay = current.getAttribute("data-original-display") || (computedDisplay === "none" ? "flex" : computedDisplay); current.style.setProperty("display", restoreDisplay, "important"); current.style.setProperty("visibility", "visible", "important"); if (window.getComputedStyle(current).opacity === "0") { current.style.setProperty("opacity", "1", "important"); } current = current.parentElement; } }; if (isLoggedIn) { document.querySelectorAll(".aad-hide-logged-out").forEach(function(el) { forceShow(el); }); document.querySelectorAll(".aad-hide-logged-in").forEach(function(el) { el.style.setProperty("display", "none", "important"); }); } else { document.querySelectorAll(".aad-hide-logged-in").forEach(function(el) { forceShow(el); }); document.querySelectorAll(".aad-hide-logged-out").forEach(function(el) { el.style.setProperty("display", "none", "important"); }); } }); '); });