row_label = array( 'type' => 'text', 'value' => esc_attr__( 'row', 'bizes' ), 'field' => false, ); // Validate row-labels. $this->row_label( $args ); if ( empty( $this->button_label ) ) { /* translators: %s: Add new label */ $this->button_label = sprintf( esc_attr__( 'Add new %s', 'bizes' ), $this->row_label['value'] ); } if ( empty( $args['fields'] ) || ! is_array( $args['fields'] ) ) { $args['fields'] = array(); } // An array to store keys of fields that need to be filtered. $media_fields_to_filter = array(); foreach ( $args['fields'] as $key => $value ) { $args['fields'][ $key ]['default'] = ( isset( $value['default'] ) ) ? $value['default'] : ''; $args['fields'][ $key ]['id'] = $key; // We check if the filed is an uploaded media ( image , file, video, etc.. ). if ( isset( $value['type'] ) ) { switch ( $value['type'] ) { case 'image': case 'cropped_image': case 'upload': // We add it to the list of fields that need some extra filtering/processing. $media_fields_to_filter[ $key ] = true; break; } } } $this->fields = $args['fields']; // Now we are going to filter the fields. // First we create a copy of the value that would be used otherwise. $this->filtered_value = $this->value(); if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { // We iterate over the list of fields. foreach ( $this->filtered_value as &$filtered_value_field ) { if ( is_array( $filtered_value_field ) && ! empty( $filtered_value_field ) ) { // We iterate over the list of properties for this field. foreach ( $filtered_value_field as $key => &$value ) { // We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload). if ( array_key_exists( $key, $media_fields_to_filter ) ) { // What follows was made this way to preserve backward compatibility. // The repeater control use to store the URL for images instead of the attachment ID. // We check if the value look like an ID (otherwise it's probably a URL so don't filter it). if ( is_numeric( $value ) ) { // "sanitize" the value. $attachment_id = (int) $value; // Try to get the attachment_url. $url = wp_get_attachment_url( $attachment_id ); $filename = basename( get_attached_file( $attachment_id ) ); // If we got a URL. if ( $url ) { // 'id' is needed for form hidden value, URL is needed to display the image. $value = array( 'id' => $attachment_id, 'url' => $url, 'filename' => $filename, ); } } } } } } } } /** * Refresh the parameters passed to the JavaScript via JSON. * * @access public */ public function to_json() { parent::to_json(); $this->json['default'] = ( isset( $this->default ) ) ? $this->default : $this->setting->default; $this->json['value'] = $this->value(); $this->json['choices'] = $this->choices; $this->json['link'] = $this->get_link(); $this->json['id'] = $this->id; if ( 'user_meta' === $this->option_type ) { $this->json['value'] = get_user_meta( get_current_user_id(), $this->id, true ); } $this->json['inputAttrs'] = ''; foreach ( $this->input_attrs as $attr => $value ) { $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; } $fields = $this->fields; $this->json['fields'] = $fields; $this->json['row_label'] = $this->row_label; // If filtered_value has been set and is not empty we use it instead of the actual value. if ( is_array( $this->filtered_value ) && ! empty( $this->filtered_value ) ) { $this->json['value'] = $this->filtered_value; } } /** * Enqueue control related scripts/styles. * * @access public */ public function enqueue() { // If we have a color picker field we need to enqueue the WordPress Color Picker style and script. if ( is_array( $this->fields ) && ! empty( $this->fields ) ) { foreach ( $this->fields as $field ) { if ( isset( $field['type'] ) ){ if( 'color' === $field['type'] ){ wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); }elseif( 'font' === $field['type'] ){ wp_enqueue_script( 'all', get_template_directory_uri() . '/js/all.min.js', array( 'jquery' ), '5.6.3', true ); wp_enqueue_script( 'v4-shims', get_template_directory_uri() . '/js/v4-shims.min.js', array( 'jquery', 'all' ), '5.6.3', true ); } } } } wp_enqueue_script( 'bizes-repeater', get_template_directory_uri() . '/inc/customizer/controls/repeater/repeater.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), false, true ); wp_enqueue_style( 'bizes-repeater', get_template_directory_uri() . '/inc/customizer/controls/repeater/repeater.css', null ); } /** * Render the control's content. * Allows the content to be overriden without having to rewrite the wrapper in $this->render(). * * @access protected */ protected function render_content() { ?> choices['limit'] ) ) : ?>

choices['limit'] ) ); ?>

repeater_js_template(); } /** * 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. * * @access public */ public function repeater_js_template() { ?> row_label['type'] = $args['row_label']['type']; } // Validating row label type. if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { $this->row_label['value'] = esc_attr( $args['row_label']['value'] ); } // Validating row label field. if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ esc_attr( $args['row_label']['field'] ) ] ) ) { $this->row_label['field'] = esc_attr( $args['row_label']['field'] ); } else { // If from field is not set correctly, making sure standard is set as the type. $this->row_label['type'] = 'text'; } } } } }