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

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