PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta2
Elementor Website Builder – more than just a page builder v4.3.0-beta2
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.3.0-beta2, at includes/widgets/wordpress.php

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