json[ 'value' ] = ( '' == $this->value() ) ? json_encode( [ 0 ] ) : $this->value(); $args = array( 'post_type' => 'page', 'posts_per_page' => -1 ); $pages = get_posts( $args ); $this->json[ 'pages' ] = array( 'Please Select a Page' ); if( $pages && is_array( $pages ) ){ foreach( $pages as $p ) { $this->json[ 'pages' ][ $p->ID ] = $p->post_title; } } $this->json[ 'link' ] = $this->get_link(); $this->json[ 'id' ] = $this->id; $this->json[ 'limit' ] = $this->limit; $this->json[ 'pro_link' ] = $this->pro_link; $this->json[ 'pro_text' ] = $this->pro_text; } /** * An Underscore (JS) template for this control's content (but not its container). * * Class variables for this control class are available in the `data` JS object; * export custom variables by overriding {@see WP_Customize_Control::to_json()}. * * @access protected * @since 1.0.0 * * @package BusinessPower_ WordPress Theme */ protected function content_template() { ?>
<# var val = JSON.parse( data.value ); #> <# _.each( val, function(l, c){ #>
<# }) #>
'page-repeater', 'class' => 'Business_Power_Page_Repeater', 'sanitize' => array( 'Business_Power_Page_Repeater', 'sanitize' ) )); function business_power_page_repeater_control( $args, $section, $field ){ if( isset( $field[ 'type' ] ) && 'page-repeater' == $field[ 'type' ] ){ $args[ 'limit' ] = isset( $field[ 'limit' ] ) ? $field[ 'limit' ] : 1000; } return $args; } add_filter( 'business_power_customizer_get_control_arg', 'business_power_page_repeater_control', 10, 3 ); function business_power_page_repeater_get( $value, $id, $instance ){ if( isset( $instance::$controls[ $id ] ) && 'page-repeater' == $instance::$controls[ $id ][ 'type' ] ){ return json_decode( $value ); } return $value; } add_filter( 'business_power_customizer_get', 'business_power_page_repeater_get', 10, 3 );