manager->get_control( $setting->id ); $fields = $control->fields; $input = json_decode( $input , true ); $data = wp_parse_args( $input, array() ); if ( ! is_array( $data ) ) { return false; } if ( ! isset( $data['_items'] ) ) { return false; } $data = $data['_items']; foreach( $data as $i => $item_data ){ foreach( $item_data as $id => $value ){ if ( isset( $fields[ $id ] ) ){ switch( strtolower( $fields[ $id ]['type'] ) ) { case 'text': $data[ $i ][ $id ] = sanitize_text_field( $value ); break; case 'textarea': $data[ $i ][ $id ] = force_balance_tags( $value ); break; case 'color': $data[ $i ][ $id ] = sanitize_hex_color_no_hash( $value ); break; case 'coloralpha': $data[ $i ][ $id ] = panoply_sanitize_color_alpha( $value ); break; case 'checkbox': $data[ $i ][ $id ] = panoply_sanitize_checkbox( $value ); break; case 'select': $data[ $i ][ $id ] = ''; if ( is_array( $fields[ $id ]['options'] ) && ! empty( $fields[ $id ]['options'] ) ){ // if is multiple choices if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { if ( isset( $fields[ $id ]['options'][ $v ] ) ) { $value [ $k ] = $v; } } $data[ $i ][ $id ] = $value; }else { // is single choice if ( isset( $fields[ $id ]['options'][ $value ] ) ) { $data[ $i ][ $id ] = $value; } } } break; case 'radio': $data[ $i ][ $id ] = sanitize_text_field( $value ); break; case 'media': $value = wp_parse_args( $value, array( 'url' => '', 'id'=> false ) ); $value['id'] = absint( $value['id'] ); $data[ $i ][ $id ]['url'] = sanitize_text_field( $value['url'] ); if ( $url = wp_get_attachment_url( $value['id'] ) ) { $data[ $i ][ $id ]['id'] = $value['id']; $data[ $i ][ $id ]['url'] = $url; } else { $data[ $i ][ $id ]['id'] = ''; } break; default: $data[ $i ][ $id ] = wp_kses_post( $value ); } }else { $data[ $i ][ $id ] = wp_kses_post( $value ); } if ( count( $data[ $i ] ) != count( $fields ) ) { foreach ( $fields as $k => $f ){ if ( ! isset( $data[ $i ][ $k ] ) ) { $data[ $i ][ $k ] = ''; } } } } } return $data; } endif; /** * Repeatable control class. * * @since 1.0.0 * @access public */ if(!class_exists('panoply_Customize_Repeatable_Control')): class panoply_Customize_Repeatable_Control extends WP_Customize_Control { /** * The type of customize control being rendered. * * @since 1.0.0 * @access public * @var string */ public $type = 'repeatable'; // public $fields = array(); public $fields = array(); public $live_title_id = null; public $title_format = null; public $defined_values = null; public $id_key = null; public $limited_msg = null; public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args); if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { $args['fields'] = array(); } foreach ( $args['fields'] as $key => $op ) { $args['fields'][ $key ]['id'] = $key; if( ! isset( $op['value'] ) ) { if( isset( $op['default'] ) ) { $args['fields'][ $key ]['value'] = $op['default']; } else { $args['fields'][ $key ]['value'] = ''; } } } $this->fields = $args['fields']; $this->live_title_id = isset( $args['live_title_id'] ) ? $args['live_title_id'] : false; $this->defined_values = isset( $args['defined_values'] ) ? $args['defined_values'] : false; $this->id_key = isset( $args['id_key'] ) ? $args['id_key'] : false; if ( isset( $args['title_format'] ) && $args['title_format'] != '' ) { $this->title_format = $args['title_format']; } else { $this->title_format = ''; } if ( isset( $args['limited_msg'] ) && $args['limited_msg'] != '' ) { $this->limited_msg = $args['limited_msg']; } else { $this->limited_msg = ''; } if ( ! isset( $args['max_item'] ) ) { $args['max_item'] = 0; } if ( ! isset( $args['allow_unlimited'] ) || $args['allow_unlimited'] != false ) { $this->max_item = apply_filters( 'panoply_reepeatable_max_item', absint( $args['max_item'] ) ); } else { $this->max_item = absint( $args['max_item'] ); } $this->changeable = isset( $args['changeable'] ) && $args['changeable'] == 'no' ? 'no' : 'yes'; $this->default_empty_title = isset( $args['default_empty_title'] ) && $args['default_empty_title'] != '' ? $args['default_empty_title'] : esc_html__( 'Item', 'panoply' ); } public function merge_data( $array_value, $array_default ){ if ( ! $this->id_key ) { return $array_value; } if ( ! is_array( $array_value ) ) { $array_value = array(); } if ( ! is_array( $array_default ) ) { $array_default = array(); } $new_array = array(); foreach ( $array_value as $k => $a ) { if ( is_array( $a ) ) { if ( isset ( $a[ $this->id_key ] ) && $a[ $this->id_key ] != '' ) { $new_array[ $a[ $this->id_key ] ] = $a; } else { $new_array[ $k ] = $a; } } } foreach ( $array_default as $k => $a ) { if ( is_array( $a ) && isset ( $a[ $this->id_key ] ) ) { if ( ! isset ( $new_array[ $a[ $this->id_key ] ] ) ) { $new_array[ $a[ $this->id_key ] ] = $a; } } } return array_values( $new_array ); } public function to_json() { parent::to_json(); $value = $this->value(); if ( empty ( $value ) ){ $value = json_encode( $this->defined_values ); } elseif ( is_array( $this->defined_values ) && ! empty ( $this->defined_values ) ) { if ( ! is_array( $value ) ) { $value = json_decode( $value, true ); } $value = $this->merge_data( $value, $this->defined_values ); $value = json_encode( $value ); } $this->json['live_title_id'] = $this->live_title_id; $this->json['title_format'] = $this->title_format; $this->json['max_item'] = $this->max_item; $this->json['limited_msg'] = $this->limited_msg; $this->json['changeable'] = $this->changeable; $this->json['default_empty_title'] = $this->default_empty_title; $this->json['value'] = $value; $this->json['id_key'] = $this->id_key; $this->json['fields'] = $this->fields; } /** * Enqueue scripts/styles. * * @since 1.0.0 * @access public * @return void */ public function enqueue() { wp_enqueue_media(); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); wp_register_script( 'panoply-customizer', get_template_directory_uri() . '/inc/js/customizer.js', array( 'customize-controls', 'wp-color-picker' ) ); wp_register_style( 'panoply-customizer', get_template_directory_uri() . '/inc/css/customizer.css' ); wp_enqueue_script( 'panoply-customizer' ); wp_enqueue_style( 'panoply-customizer' ); } public function render_content() { ?> input_attrs(); ?> value="" link(); ?> />
  • <# var cond_v; #> <# for ( i in data ) { #> <# if ( ! data.hasOwnProperty( i ) ) continue; #> <# field = data[i]; #> <# if ( ! field.type ) continue; #> <# if ( field.type ){ #> <# if ( field.required && field.required.length >= 3 ) { #>
    <# } else { #>
    <# } #> <# if ( field.type !== 'checkbox' ) { #> <# if ( field.title ) { #> <# } #> <# if ( field.desc ) { #>

    {{{ field.desc }}}

    <# } #> <# } #> <# if ( field.type === 'hidden' ) { #> <# } else if ( field.type === 'add_by' ) { #> <# } else if ( field.type === 'text' ) { #> <# } else if ( field.type === 'checkbox' ) { #> <# if ( field.title ) { #> <# } #> <# if ( field.desc ) { #>

    {{ field.desc }}

    <# } #> <# } else if ( field.type === 'select' ) { #> <# if ( field.multiple ) { #> <# } #> <# for ( k in field.options ) { #> <# if ( _.isArray( field.value ) ) { #> <# } else { #> <# } #> <# } #> <# } else if ( field.type === 'radio' ) { #> <# for ( k in field.options ) { #> <# if ( field.options.hasOwnProperty( k ) ) { #> <# } #> <# } #> <# } else if ( field.type == 'color' || field.type == 'coloralpha' ) { #> <# if ( field.value !='' ) { field.value = '#'+field.value ; } #> <# } else if ( field.type == 'media' ) { #> <# if ( !field.media || field.media == '' || field.media =='image' ) { #> <# } else { #> <# } #> <# if ( !field.media || field.media == '' || field.media =='image' ) { #>
    <# if ( field.value && field.value.url ){ #> <# var ext = field.value.url.substr( field.value.url.lastIndexOf('.') + 1); if ( ext == 'mp4' || ext == 'ogv' || ext == 'webm' ) { #> <# } else { #> <# } #> <# } #>
    <# } #>
    <# } else if ( field.type == 'textarea' || field.type == 'editor' ) { #> <# } else if ( field.type == 'icon' ) { #>
    <# } #>
    <# } #> <# } #>
    |