json[ 'value' ] = ( '' == $this->value() ) ? json_encode( [ 0 ] ) : $this->value(); $args = array( 'post_type' => 'page', 'posts_per_page' => -1 ); $pages = get_posts( $args ); $select_pages = array( esc_html__( 'Select page', 'bizline' ) ); if( $pages && is_array( $pages ) ){ foreach( $pages as $p ) { $select_pages[ $p->ID ] = $p->post_title; } } $this->json[ 'pages' ] = $select_pages; $this->json[ 'link' ] = $this->get_link(); $this->json[ 'id' ] = $this->id; $this->json[ 'limit' ] = $this->limit; $this->json[ 'repeat' ] = $this->repeat; } /** * 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 Bizline WordPress Theme */ protected function content_template() { ?>
<# var val = JSON.parse( data.value ); #> <# _.each( val, function(l, c){ #>
<# _.each( data.repeat, function( value, type ) { #> <# if( 'text' == type ){ #> <# if ( value.label ) { #> {{value.label}} <# } #> <# if ( value.description ) { #> {{value.description}} <# } #> <# if( l ){ if( Array.isArray( l ) ){ inputValue = l[ 0 ]; }else{ inputValue = l; } }else{ inputValue = ''; }#> <# } #> <# if( 'page' == type ){ #> <# if ( value.label ) { #> {{value.label}} <# } #> <# if ( value.description ) { #> {{value.description}} <# } #> <# } #> <# }) #>
<# }) #>
'repeater', 'class' => 'Bizline_Page_Repeater', 'sanitize' => array( 'Bizline_Page_Repeater', 'sanitize' ) )); function bizline_page_repeater_control( $args, $section, $field ){ if( isset( $field[ 'type' ] ) && 'repeater' == $field[ 'type' ] ){ $args[ 'limit' ] = isset( $field[ 'limit' ] ) ? $field[ 'limit' ] : 1000; } $args[ 'repeat' ] = isset( $field[ 'repeat' ] ) ? $field[ 'repeat' ] : 'text'; return $args; } add_filter( 'bizline_customizer_get_control_arg', 'bizline_page_repeater_control', 10, 3 ); function bizline_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( 'bizline_customizer_get', 'bizline_page_repeater_get', 10, 3 );