wp/wp-includes/customize/class-wp-widget-form-customize-control.php
changeset 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     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 	 * @since 3.9.0
       
    31 	 *
       
    32 	 * @global array $wp_registered_widgets
       
    33 	 */
       
    34 	public function to_json() {
       
    35 		global $wp_registered_widgets;
       
    36 
       
    37 		parent::to_json();
       
    38 		$exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
       
    39 		foreach ( $exported_properties as $key ) {
       
    40 			$this->json[ $key ] = $this->$key;
       
    41 		}
       
    42 
       
    43 		// Get the widget_control and widget_content.
       
    44 		require_once ABSPATH . '/wp-admin/includes/widgets.php';
       
    45 
       
    46 		$widget = $wp_registered_widgets[ $this->widget_id ];
       
    47 		if ( ! isset( $widget['params'][0] ) ) {
       
    48 			$widget['params'][0] = array();
       
    49 		}
       
    50 
       
    51 		$args = array(
       
    52 			'widget_id' => $widget['id'],
       
    53 			'widget_name' => $widget['name'],
       
    54 		);
       
    55 
       
    56 		$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
       
    57 		$widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
       
    58 
       
    59 		$this->json['widget_control'] = $widget_control_parts['control'];
       
    60 		$this->json['widget_content'] = $widget_control_parts['content'];
       
    61 	}
       
    62 
       
    63 	/**
       
    64 	 * Override render_content to be no-op since content is exported via to_json for deferred embedding.
       
    65 	 *
       
    66 	 * @since 3.9.0
       
    67 	 */
       
    68 	public function render_content() {}
       
    69 
       
    70 	/**
       
    71 	 * Whether the current widget is rendered on the page.
       
    72 	 *
       
    73 	 * @since 4.0.0
       
    74 	 *
       
    75 	 * @return bool Whether the widget is rendered.
       
    76 	 */
       
    77 	public function active_callback() {
       
    78 		return $this->manager->widgets->is_widget_rendered( $this->widget_id );
       
    79 	}
       
    80 }