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

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