$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'] ) || false !== $args['allow_unlimited'] ) { $this->max_item = apply_filters( 'bloghash_reepeatable_max_item', absint( $args['max_item'] ) ); } else { $this->max_item = absint( $args['max_item'] ); } $this->changeable = isset( $args['changeable'] ) && 'no' === $args['changeable'] ? 'no' : 'yes'; $this->default_empty_title = isset( $args['default_empty_title'] ) && '' !== $args['default_empty_title'] ? $args['default_empty_title'] : esc_html__( 'Item', 'bloghash' ); add_action( 'customize_controls_print_footer_scripts', array( __CLASS__, 'item_tpl' ), 66 ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'bloghash_customize_controls_enqueue_scripts' ) ); } /** * Merge fields data * * @param array $array_value field values. * @param array $array_default default field values. * @return array */ 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 ); } /** * Refresh the parameters passed to the JavaScript via JSON. * * @see WP_Customize_Control::to_json() */ public function to_json() { parent::to_json(); $value = $this->value(); if ( is_string( $value ) ) { $value = json_decode( $value, true ); } if ( empty( $value ) ) { $value = $this->defined_values; } elseif ( is_array( $this->defined_values ) && ! empty( $this->defined_values ) ) { $value = $this->merge_data( $value, $this->defined_values ); } $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['add_text'] = $this->add_text ?? __( 'Add new item', 'bloghash' ); $this->json['value'] = $value; $this->json['id_key'] = $this->id_key; $this->json['fields'] = $this->fields; $this->json['l10n'] = array( 'image' => array( 'placeholder' => __( 'No image selected', 'bloghash' ), 'less' => __( 'Less Settings', 'bloghash' ), 'more' => __( 'Advanced', 'bloghash' ), 'select_image' => __( 'Select Image', 'bloghash' ), 'use_image' => __( 'Use This Image', 'bloghash' ), ), ); } /** * Enqueue control related scripts/styles. * * @access public */ public function enqueue() { parent::enqueue(); // Script debug. $bloghash_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; // Enqueue background image stylesheet. if ( in_array( 'button_set', array_values( array_column( $this->fields, 'type' ) ), true ) ) { wp_enqueue_style( 'bloghash-background-alignment-style', BLOGHASH_THEME_URI . '/inc/customizer/controls/alignment/alignment' . $bloghash_suffix . '.css', false, BLOGHASH_THEME_VERSION, 'all' ); } // Enqueue background image stylesheet. if ( in_array( 'link', array_values( array_column( $this->fields, 'type' ) ), true ) ) { wp_enqueue_script( 'wplink' ); wp_enqueue_style( 'editor-buttons' ); } // Enqueue background image stylesheet. if ( in_array( 'background', array_values( array_column( $this->fields, 'type' ) ), true ) ) { wp_enqueue_style( 'bloghash-background-control-style', BLOGHASH_THEME_URI . '/inc/customizer/controls/background/background' . $bloghash_suffix . '.css', false, BLOGHASH_THEME_VERSION, 'all' ); } } /** * Item template to for repeatable * * @return void */ public static function item_tpl() { ?> <# if ( data.label ) { #>