PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-dev1
Elementor Website Builder – more than just a page builder v3.6.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 / trunk / includes / widgets / wordpress.php

wordpress.php in Elementor Website Builder – more than just a page builder 3.6.0-dev1, at trunk/includes/widgets/wordpress.php

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