wp/wp-includes/customize/class-wp-customize-selective-refresh.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    47 
    47 
    48 	/**
    48 	/**
    49 	 * Keep track of the current partial being rendered.
    49 	 * Keep track of the current partial being rendered.
    50 	 *
    50 	 *
    51 	 * @since 4.5.0
    51 	 * @since 4.5.0
    52 	 * @var string
    52 	 * @var string|null
    53 	 */
    53 	 */
    54 	protected $current_partial_id;
    54 	protected $current_partial_id;
    55 
    55 
    56 	/**
    56 	/**
    57 	 * Plugin bootstrap for Partial Refresh functionality.
    57 	 * Plugin bootstrap for Partial Refresh functionality.
    58 	 *
    58 	 *
    59 	 * @since 4.5.0
    59 	 * @since 4.5.0
    60 	 *
    60 	 *
    61 	 * @param WP_Customize_Manager $manager Manager instance.
    61 	 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
    62 	 */
    62 	 */
    63 	public function __construct( WP_Customize_Manager $manager ) {
    63 	public function __construct( WP_Customize_Manager $manager ) {
    64 		$this->manager = $manager;
    64 		$this->manager = $manager;
    65 		require_once( ABSPATH . WPINC . '/customize/class-wp-customize-partial.php' );
    65 		require_once ABSPATH . WPINC . '/customize/class-wp-customize-partial.php';
    66 
    66 
    67 		add_action( 'customize_preview_init', array( $this, 'init_preview' ) );
    67 		add_action( 'customize_preview_init', array( $this, 'init_preview' ) );
    68 	}
    68 	}
    69 
    69 
    70 	/**
    70 	/**
    81 	/**
    81 	/**
    82 	 * Adds a partial.
    82 	 * Adds a partial.
    83 	 *
    83 	 *
    84 	 * @since 4.5.0
    84 	 * @since 4.5.0
    85 	 *
    85 	 *
    86 	 * @param WP_Customize_Partial|string $id   Customize Partial object, or Panel ID.
    86 	 * @see WP_Customize_Partial::__construct()
    87 	 * @param array                       $args {
    87 	 *
    88 	 *  Optional. Array of properties for the new Partials object. Default empty array.
    88 	 * @param WP_Customize_Partial|string $id   Customize Partial object, or Partial ID.
    89 	 *
    89 	 * @param array                       $args Optional. Array of properties for the new Partials object.
    90 	 *  @type string   $type                  Type of the partial to be created.
    90 	 *                                          See WP_Customize_Partial::__construct() for information
    91 	 *  @type string   $selector              The jQuery selector to find the container element for the partial, that is, a partial's placement.
    91 	 *                                          on accepted arguments. Default empty array.
    92 	 *  @type array    $settings              IDs for settings tied to the partial.
    92 	 * @return WP_Customize_Partial The instance of the partial that was added.
    93 	 *  @type string   $primary_setting       The ID for the setting that this partial is primarily responsible for
       
    94 	 *                                        rendering. If not supplied, it will default to the ID of the first setting.
       
    95 	 *  @type string   $capability            Capability required to edit this partial.
       
    96 	 *                                        Normally this is empty and the capability is derived from the capabilities
       
    97 	 *                                        of the associated `$settings`.
       
    98 	 *  @type callable $render_callback       Render callback.
       
    99 	 *                                        Callback is called with one argument, the instance of WP_Customize_Partial.
       
   100 	 *                                        The callback can either echo the partial or return the partial as a string,
       
   101 	 *                                        or return false if error.
       
   102 	 *  @type bool     $container_inclusive   Whether the container element is included in the partial, or if only
       
   103 	 *                                        the contents are rendered.
       
   104 	 *  @type bool     $fallback_refresh      Whether to refresh the entire preview in case a partial cannot be refreshed.
       
   105 	 *                                        A partial render is considered a failure if the render_callback returns
       
   106 	 *                                        false.
       
   107 	 * }
       
   108 	 * @return WP_Customize_Partial             The instance of the panel that was added.
       
   109 	 */
    93 	 */
   110 	public function add_partial( $id, $args = array() ) {
    94 	public function add_partial( $id, $args = array() ) {
   111 		if ( $id instanceof WP_Customize_Partial ) {
    95 		if ( $id instanceof WP_Customize_Partial ) {
   112 			$partial = $id;
    96 			$partial = $id;
   113 		} else {
    97 		} else {
   206 			'renderQueryVar' => self::RENDER_QUERY_VAR,
   190 			'renderQueryVar' => self::RENDER_QUERY_VAR,
   207 			'l10n'           => $l10n,
   191 			'l10n'           => $l10n,
   208 		);
   192 		);
   209 
   193 
   210 		// Export data to JS.
   194 		// Export data to JS.
   211 		echo sprintf( '<script>var _customizePartialRefreshExports = %s;</script>', wp_json_encode( $exports ) );
   195 		printf( '<script>var _customizePartialRefreshExports = %s;</script>', wp_json_encode( $exports ) );
   212 	}
   196 	}
   213 
   197 
   214 	/**
   198 	/**
   215 	 * Registers dynamically-created partials.
   199 	 * Registers dynamically-created partials.
   216 	 *
   200 	 *