PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.3
Elementor Website Builder – more than just a page builder v3.26.3
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 3.26.3, at includes/widgets/wordpress.php

316 lines 7.2 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 public function get_help_url() {
126 return '';
127 }
128
129 /**
130 * Whether the reload preview is required or not.
131 *
132 * Used to determine whether the reload preview is required.
133 *
134 * @since 1.0.0
135 * @access public
136 *
137 * @return bool Whether the reload preview is required.
138 */
139 public function is_reload_preview_required() {
140 return true;
141 }
142
143 /**
144 * Retrieve WordPress widget form.
145 *
146 * Returns the WordPress widget form, to be used in Elementor.
147 *
148 * @since 1.0.0
149 * @access public
150 *
151 * @return string Widget form.
152 */
153 public function get_form() {
154 $instance = $this->get_widget_instance();
155
156 ob_start();
157 echo '<div class="widget-inside media-widget-control"><div class="form wp-core-ui">';
158 echo '<input type="hidden" class="id_base" value="' . esc_attr( $instance->id_base ) . '" />';
159 echo '<input type="hidden" class="widget-id" value="widget-' . esc_attr( $this->get_id() ) . '" />';
160 echo '<div class="widget-content">';
161 $widget_data = $this->get_settings( 'wp' );
162 $instance->form( $widget_data );
163 do_action( 'in_widget_form', $instance, null, $widget_data );
164 echo '</div></div></div>';
165 return ob_get_clean();
166 }
167
168 /**
169 * Retrieve WordPress widget instance.
170 *
171 * Returns an instance of WordPress widget, to be used in Elementor.
172 *
173 * @since 1.0.0
174 * @access public
175 *
176 * @return \WP_Widget
177 */
178 public function get_widget_instance() {
179 if ( is_null( $this->_widget_instance ) ) {
180 global $wp_widget_factory;
181
182 if ( isset( $wp_widget_factory->widgets[ $this->_widget_name ] ) ) {
183 $this->_widget_instance = $wp_widget_factory->widgets[ $this->_widget_name ];
184 $this->_widget_instance->_set( 'REPLACE_TO_ID' );
185 } elseif ( class_exists( $this->_widget_name ) ) {
186 $this->_widget_instance = new $this->_widget_name();
187 $this->_widget_instance->_set( 'REPLACE_TO_ID' );
188 }
189 }
190 return $this->_widget_instance;
191 }
192
193 /**
194 * Retrieve WordPress widget parsed settings.
195 *
196 * Returns the WordPress widget settings, to be used in Elementor.
197 *
198 * @access protected
199 * @since 2.3.0
200 *
201 * @return array Parsed settings.
202 */
203 protected function get_init_settings() {
204 $settings = parent::get_init_settings();
205
206 if ( ! empty( $settings['wp'] ) ) {
207 $widget = $this->get_widget_instance();
208 $instance = $widget->update( $settings['wp'], [] );
209 /** This filter is documented in wp-includes/class-wp-widget.php */
210 $settings['wp'] = apply_filters( 'widget_update_callback', $instance, $settings['wp'], [], $widget );
211 }
212
213 return $settings;
214 }
215
216 /**
217 * Register WordPress widget controls.
218 *
219 * Adds different input fields to allow the user to change and customize the widget settings.
220 *
221 * @since 3.1.0
222 * @access protected
223 */
224 protected function register_controls() {
225 $this->add_control(
226 'wp',
227 [
228 'label' => esc_html__( 'Form', 'elementor' ),
229 'type' => Controls_Manager::WP_WIDGET,
230 'widget' => $this->get_name(),
231 'id_base' => $this->get_widget_instance()->id_base,
232 ]
233 );
234 }
235
236 /**
237 * Render WordPress widget output on the frontend.
238 *
239 * Written in PHP and used to generate the final HTML.
240 *
241 * @since 1.0.0
242 * @access protected
243 */
244 protected function render() {
245 $default_widget_args = [
246 'widget_id' => $this->get_name(),
247 'before_widget' => '',
248 'after_widget' => '',
249 'before_title' => '<h5>',
250 'after_title' => '</h5>',
251 ];
252
253 /**
254 * WordPress widget args.
255 *
256 * Filters the WordPress widget arguments when they are rendered in Elementor panel.
257 *
258 * @since 1.0.0
259 *
260 * @param array $default_widget_args Default widget arguments.
261 * @param Widget_WordPress $this The WordPress widget.
262 */
263 $default_widget_args = apply_filters( 'elementor/widgets/wordpress/widget_args', $default_widget_args, $this );
264 $is_gallery_widget = 'wp-widget-media_gallery' === $this->get_name();
265
266 if ( $is_gallery_widget ) {
267 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
268 }
269
270 $this->get_widget_instance()->widget( $default_widget_args, $this->get_settings( 'wp' ) );
271
272 if ( $is_gallery_widget ) {
273 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
274 }
275 }
276
277 /**
278 * Render WordPress widget output in the editor.
279 *
280 * Written as a Backbone JavaScript template and used to generate the live preview.
281 *
282 * @since 2.9.0
283 * @access protected
284 */
285 protected function content_template() {}
286
287 /**
288 * WordPress widget constructor.
289 *
290 * Used to run WordPress widget constructor.
291 *
292 * @since 1.0.0
293 * @access public
294 *
295 * @param array $data Widget data. Default is an empty array.
296 * @param array $args Widget arguments. Default is null.
297 */
298 public function __construct( $data = [], $args = null ) {
299 $this->_widget_name = $args['widget_name'];
300
301 parent::__construct( $data, $args );
302 }
303
304 /**
305 * Render WordPress widget as plain content.
306 *
307 * Override the default render behavior, don't render widget content.
308 *
309 * @since 1.0.0
310 * @access public
311 *
312 * @param array $instance Widget instance. Default is empty array.
313 */
314 public function render_plain_content( $instance = [] ) {}
315 }
316