WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-includes / customize / class-wp-widget-form-customize-control.php
1 <?php
2 /**
3  * Customize API: WP_Widget_Form_Customize_Control class
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 4.4.0
8  */
9
10 /**
11  * Widget Form Customize Control class.
12  *
13  * @since 3.9.0
14  *
15  * @see WP_Customize_Control
16  */
17 class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
18         public $type = 'widget_form';
19         public $widget_id;
20         public $widget_id_base;
21         public $sidebar_id;
22         public $is_new = false;
23         public $width;
24         public $height;
25         public $is_wide = false;
26
27         /**
28          * Gather control params for exporting to JavaScript.
29          *
30          * @global array $wp_registered_widgets
31          */
32         public function to_json() {
33                 global $wp_registered_widgets;
34
35                 parent::to_json();
36                 $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
37                 foreach ( $exported_properties as $key ) {
38                         $this->json[ $key ] = $this->$key;
39                 }
40
41                 // Get the widget_control and widget_content.
42                 require_once ABSPATH . '/wp-admin/includes/widgets.php';
43
44                 $widget = $wp_registered_widgets[ $this->widget_id ];
45                 if ( ! isset( $widget['params'][0] ) ) {
46                         $widget['params'][0] = array();
47                 }
48
49                 $args = array(
50                         'widget_id' => $widget['id'],
51                         'widget_name' => $widget['name'],
52                 );
53
54                 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
55                 $widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
56
57                 $this->json['widget_control'] = $widget_control_parts['control'];
58                 $this->json['widget_content'] = $widget_control_parts['content'];
59         }
60
61         /**
62          * Override render_content to be no-op since content is exported via to_json for deferred embedding.
63          */
64         public function render_content() {}
65
66         /**
67          * Whether the current widget is rendered on the page.
68          *
69          * @since 4.0.0
70          * @access public
71          *
72          * @return bool Whether the widget is rendered.
73          */
74         public function active_callback() {
75                 return $this->manager->widgets->is_widget_rendered( $this->widget_id );
76         }
77 }