| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor sidebar widget. |
| 10 |
* |
| 11 |
* Elementor widget that insert any sidebar into the page. |
| 12 |
* |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class Widget_Sidebar extends Widget_Base { |
| 16 |
|
| 17 |
/** |
| 18 |
* Get widget name. |
| 19 |
* |
| 20 |
* Retrieve sidebar widget name. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* @access public |
| 24 |
* |
| 25 |
* @return string Widget name. |
| 26 |
*/ |
| 27 |
public function get_name() { |
| 28 |
return 'sidebar'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get widget title. |
| 33 |
* |
| 34 |
* Retrieve sidebar widget title. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @access public |
| 38 |
* |
| 39 |
* @return string Widget title. |
| 40 |
*/ |
| 41 |
public function get_title() { |
| 42 |
return esc_html__( 'Sidebar', 'elementor' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get widget icon. |
| 47 |
* |
| 48 |
* Retrieve sidebar widget icon. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* @access public |
| 52 |
* |
| 53 |
* @return string Widget icon. |
| 54 |
*/ |
| 55 |
public function get_icon() { |
| 56 |
return 'eicon-sidebar'; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get widget keywords. |
| 61 |
* |
| 62 |
* Retrieve the list of keywords the widget belongs to. |
| 63 |
* |
| 64 |
* @since 2.1.0 |
| 65 |
* @access public |
| 66 |
* |
| 67 |
* @return array Widget keywords. |
| 68 |
*/ |
| 69 |
public function get_keywords() { |
| 70 |
return [ 'sidebar', 'widget' ]; |
| 71 |
} |
| 72 |
|
| 73 |
public function has_widget_inner_wrapper(): bool { |
| 74 |
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Register sidebar widget controls. |
| 79 |
* |
| 80 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 81 |
* |
| 82 |
* @since 3.1.0 |
| 83 |
* @access protected |
| 84 |
*/ |
| 85 |
protected function register_controls() { |
| 86 |
global $wp_registered_sidebars; |
| 87 |
|
| 88 |
$options = []; |
| 89 |
|
| 90 |
if ( ! $wp_registered_sidebars ) { |
| 91 |
$options[''] = esc_html__( 'No sidebars were found', 'elementor' ); |
| 92 |
} else { |
| 93 |
$options[''] = esc_html__( 'Choose Sidebar', 'elementor' ); |
| 94 |
|
| 95 |
foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) { |
| 96 |
$options[ $sidebar_id ] = $sidebar['name']; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
$default_key = array_keys( $options ); |
| 101 |
$default_key = array_shift( $default_key ); |
| 102 |
|
| 103 |
$this->start_controls_section( |
| 104 |
'section_sidebar', |
| 105 |
[ |
| 106 |
'label' => esc_html__( 'Sidebar', 'elementor' ), |
| 107 |
] |
| 108 |
); |
| 109 |
|
| 110 |
$this->add_control( |
| 111 |
'sidebar', |
| 112 |
[ |
| 113 |
'label' => esc_html__( 'Choose Sidebar', 'elementor' ), |
| 114 |
'type' => Controls_Manager::SELECT, |
| 115 |
'default' => $default_key, |
| 116 |
'options' => $options, |
| 117 |
] |
| 118 |
); |
| 119 |
|
| 120 |
$this->end_controls_section(); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Render sidebar widget output on the frontend. |
| 125 |
* |
| 126 |
* Written in PHP and used to generate the final HTML. |
| 127 |
* |
| 128 |
* @since 1.0.0 |
| 129 |
* @access protected |
| 130 |
*/ |
| 131 |
protected function render() { |
| 132 |
$sidebar = $this->get_settings_for_display( 'sidebar' ); |
| 133 |
|
| 134 |
if ( empty( $sidebar ) ) { |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
dynamic_sidebar( $sidebar ); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Render sidebar widget output in the editor. |
| 143 |
* |
| 144 |
* Written as a Backbone JavaScript template and used to generate the live preview. |
| 145 |
* |
| 146 |
* @since 2.9.0 |
| 147 |
* @access protected |
| 148 |
*/ |
| 149 |
protected function content_template() {} |
| 150 |
|
| 151 |
/** |
| 152 |
* Render sidebar widget as plain content. |
| 153 |
* |
| 154 |
* Override the default render behavior, don't render sidebar content. |
| 155 |
* |
| 156 |
* @since 1.0.0 |
| 157 |
* @access public |
| 158 |
*/ |
| 159 |
public function render_plain_content() {} |
| 160 |
} |
| 161 |
|