PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / wordpress.php

wordpress.php in Elementor Website Builder – more than just a page builder 4.2.4, at includes/widgets/wordpress.php

330 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor WordPress widget.
10 *
11 * Elementor widget that displays all the WordPress widgets.
12 *
13 * @since 1.0.0
14 */
15 class Widget_WordPress extends Widget_Base {
16
17 /**
18 * WordPress widget name.
19 *
20 * @access private
21 *
22 * @var string
23 */
24 private $_widget_name = null;
25
26 /**
27 * WordPress widget instance.
28 *
29 * @access private
30 *
31 * @var \WP_Widget
32 */
33 private $_widget_instance = null;
34
35 public function hide_on_search() {
36 return true;
37 }
38
39 /**
40 * Get widget name.
41 *
42 * Retrieve WordPress widget name.
43 *
44 * @since 1.0.0
45 * @access public
46 *
47 * @return string Widget name.
48 */
49 public function get_name() {
50 return 'wp-widget-' . $this->get_widget_instance()->id_base;
51 }
52
53 /**
54 * Get widget title.
55 *
56 * Retrieve WordPress widget title.
57 *
58 * @since 1.0.0
59 * @access public
60 *
61 * @return string Widget title.
62 */
63 public function get_title() {
64 return $this->get_widget_instance()->name;
65 }
66
67 /**
68 * Get widget categories.
69 *
70 * Retrieve the list of categories the WordPress widget belongs to.
71 *
72 * Used to determine where to display the widget in the editor.
73 *
74 * @since 1.0.0
75 * @access public
76 *
77 * @return array Widget categories. Returns either a WordPress category.
78 */
79 public function get_categories() {
80 return [ 'wordpress' ];
81 }
82
83 /**
84 * Get widget icon.
85 *
86 * Retrieve WordPress widget icon.
87 *
88 * @since 1.0.0
89 * @access public
90 *
91 * @return string Widget icon. Returns either a WordPress icon.
92 */
93 public function get_icon() {
94 return 'eicon-wordpress';
95 }
96
97 /**
98 * Get widget keywords.
99 *
100 * Retrieve the list of keywords the widget belongs to.
101 *
102 * @since 2.1.0
103 * @access public
104 *
105 * @return array Widget keywords.
106 */
107 public function get_keywords() {
108 return [ 'wordpress', 'widget' ];
109 }
110
111 /**
112 * Get style dependencies.
113 *
114 * Retrieve the list of style dependencies the widget requires.
115 *
116 * @since 3.26.0
117 * @access public
118 *
119 * @return array Widget style dependencies.
120 */
121 public function get_style_depends(): array {
122 return [ 'e-swiper' ];
123 }
124
125 /**
126 * Get script dependencies.
127 *
128 * Retrieve the list of script dependencies the widget requires.
129 *
130 * @since 3.27.0
131 * @access public
132 *
133 * @return array Widget script dependencies.
134 */
135 public function get_script_depends(): array {
136 return [ 'swiper' ];
137 }
138
139 public function get_help_url() {
140 return '';
141 }
142
143 /**
144 * Whether the reload preview is required or not.
145 *
146 * Used to determine whether the reload preview is required.
147 *
148 * @since 1.0.0
149 * @access public
150 *
151 * @return bool Whether the reload preview is required.
152 */
153 public function is_reload_preview_required() {
154 return true;
155 }
156
157 /**
158 * Retrieve WordPress widget form.
159 *
160 * Returns the WordPress widget form, to be used in Elementor.
161 *
162 * @since 1.0.0
163 * @access public
164 *
165 * @return string Widget form.
166 */
167 public function get_form() {
168 $instance = $this->get_widget_instance();
169
170 ob_start();
171 echo '<div class="widget-inside media-widget-control"><div class="form wp-core-ui">';
172 echo '<input type="hidden" class="id_base" value="' . esc_attr( $instance->id_base ) . '" />';
173 echo '<input type="hidden" class="widget-id" value="widget-' . esc_attr( $this->get_id() ) . '" />';
174 echo '<div class="widget-content">';
175 $widget_data = $this->get_settings( 'wp' );
176 $instance->form( $widget_data );
177 do_action( 'in_widget_form', $instance, null, $widget_data );
178 echo '</div></div></div>';
179 return ob_get_clean();
180 }
181
182 /**
183 * Retrieve WordPress widget instance.
184 *
185 * Returns an instance of WordPress widget, to be used in Elementor.
186 *
187 * @since 1.0.0
188 * @access public
189 *
190 * @return \WP_Widget
191 */
192 public function get_widget_instance() {
193 if ( is_null( $this->_widget_instance ) ) {
194 global $wp_widget_factory;
195
196 if ( isset( $wp_widget_factory->widgets[ $this->_widget_name ] ) ) {
197 $this->_widget_instance = $wp_widget_factory->widgets[ $this->_widget_name ];
198 $this->_widget_instance->_set( 'REPLACE_TO_ID' );
199 } elseif ( class_exists( $this->_widget_name ) ) {
200 $this->_widget_instance = new $this->_widget_name();
201 $this->_widget_instance->_set( 'REPLACE_TO_ID' );
202 }
203 }
204 return $this->_widget_instance;
205 }
206
207 /**
208 * Retrieve WordPress widget parsed settings.
209 *
210 * Returns the WordPress widget settings, to be used in Elementor.
211 *
212 * @access protected
213 * @since 2.3.0
214 *
215 * @return array Parsed settings.
216 */
217 protected function get_init_settings() {
218 $settings = parent::get_init_settings();
219
220 if ( ! empty( $settings['wp'] ) ) {
221 $widget = $this->get_widget_instance();
222 $instance = $widget->update( $settings['wp'], [] );
223 /** This filter is documented in wp-includes/class-wp-widget.php */
224 $settings['wp'] = apply_filters( 'widget_update_callback', $instance, $settings['wp'], [], $widget );
225 }
226
227 return $settings;
228 }
229
230 /**
231 * Register WordPress widget controls.
232 *
233 * Adds different input fields to allow the user to change and customize the widget settings.
234 *
235 * @since 3.1.0
236 * @access protected
237 */
238 protected function register_controls() {
239 $this->add_control(
240 'wp',
241 [
242 'label' => esc_html__( 'Form', 'elementor' ),
243 'type' => Controls_Manager::WP_WIDGET,
244 'widget' => $this->get_name(),
245 'id_base' => $this->get_widget_instance()->id_base,
246 ]
247 );
248 }
249
250 /**
251 * Render WordPress widget output on the frontend.
252 *
253 * Written in PHP and used to generate the final HTML.
254 *
255 * @since 1.0.0
256 * @access protected
257 */
258 protected function render() {
259 $default_widget_args = [
260 'widget_id' => $this->get_name(),
261 'before_widget' => '',
262 'after_widget' => '',
263 'before_title' => '<h5>',
264 'after_title' => '</h5>',
265 ];
266
267 /**
268 * WordPress widget args.
269 *
270 * Filters the WordPress widget arguments when they are rendered in Elementor panel.
271 *
272 * @since 1.0.0
273 *
274 * @param array $default_widget_args Default widget arguments.
275 * @param Widget_WordPress $this The WordPress widget.
276 */
277 $default_widget_args = apply_filters( 'elementor/widgets/wordpress/widget_args', $default_widget_args, $this );
278 $is_gallery_widget = 'wp-widget-media_gallery' === $this->get_name();
279
280 if ( $is_gallery_widget ) {
281 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
282 }
283
284 $this->get_widget_instance()->widget( $default_widget_args, $this->get_settings( 'wp' ) );
285
286 if ( $is_gallery_widget ) {
287 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
288 }
289 }
290
291 /**
292 * Render WordPress widget output in the editor.
293 *
294 * Written as a Backbone JavaScript template and used to generate the live preview.
295 *
296 * @since 2.9.0
297 * @access protected
298 */
299 protected function content_template() {}
300
301 /**
302 * WordPress widget constructor.
303 *
304 * Used to run WordPress widget constructor.
305 *
306 * @since 1.0.0
307 * @access public
308 *
309 * @param array $data Widget data. Default is an empty array.
310 * @param array $args Widget arguments. Default is null.
311 */
312 public function __construct( $data = [], $args = null ) {
313 $this->_widget_name = $args['widget_name'];
314
315 parent::__construct( $data, $args );
316 }
317
318 /**
319 * Render WordPress widget as plain content.
320 *
321 * Override the default render behavior, don't render widget content.
322 *
323 * @since 1.0.0
324 * @access public
325 *
326 * @param array $instance Widget instance. Default is empty array.
327 */
328 public function render_plain_content( $instance = [] ) {}
329 }
330