ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-kirki-selective-refresh.php (1982B)


      1 <?php
      2 /**
      3  * Handles sections created via the Kirki API.
      4  *
      5  * @package     Kirki
      6  * @category    Core
      7  * @author      Aristeides Stathopoulos
      8  * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
      9  * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
     10  * @since       1.0
     11  */
     12 
     13 /**
     14  * Handle selective refreshes introduced in WordPress 4.5.
     15  */
     16 class Kirki_Selective_Refresh {
     17 
     18 	/**
     19 	 * Adds any necessary actions & filters.
     20 	 */
     21 	public function __construct() {
     22 		add_action( 'customize_register', array( $this, 'register_partials' ), 99 );
     23 	}
     24 
     25 	/**
     26 	 * Parses all fields and searches for the "partial_refresh" argument inside them.
     27 	 * If that argument is found, then it starts parsing the array of arguments.
     28 	 * Registers a selective_refresh in the customizer for each one of them.
     29 	 *
     30 	 * @param object $wp_customize WP_Customize_Manager.
     31 	 */
     32 	public function register_partials( $wp_customize ) {
     33 
     34 		// Abort if selective refresh is not available.
     35 		if ( ! isset( $wp_customize->selective_refresh ) ) {
     36 			return;
     37 		}
     38 
     39 		// Get an array of all fields.
     40 		$fields = Kirki::$fields;
     41 
     42 		if( ! apply_filters('materialis_enable_kirki_selective_refresh',true))
     43         {
     44             return;
     45         }
     46 
     47 		// Start parsing the fields.
     48 		foreach ( $fields as $field_id => $args ) {
     49 			if ( isset( $args['partial_refresh'] ) && ! empty( $args['partial_refresh'] ) ) {
     50 				// Start going through each item in the array of partial refreshes.
     51 				foreach ( $args['partial_refresh'] as $partial_refresh => $partial_refresh_args ) {
     52 					// If we have all we need, create the selective refresh call.
     53 					if ( isset( $partial_refresh_args['render_callback'] ) && isset( $partial_refresh_args['selector'] ) ) {
     54 						$partial_refresh_args = wp_parse_args( $partial_refresh_args, array(
     55 							'settings' => $args['settings'],
     56 						) );
     57 						$wp_customize->selective_refresh->add_partial( $partial_refresh, $partial_refresh_args );
     58 					}
     59 				}
     60 			}
     61 		}
     62 	}
     63 }