fields ) ) { $this->fields = array( 'label' => array( 'type' => 'text', 'label' => __( 'Label', 'accepta' ), 'placeholder' => __( 'Enter label', 'accepta' ), ), 'url' => array( 'type' => 'url', 'label' => __( 'URL', 'accepta' ), 'placeholder' => __( 'https://example.com', 'accepta' ), ), ); } } /** * Enqueue control related scripts/styles */ public function enqueue() { wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/fonts/fontawesome/all.min.css', array(), '6.4.0' ); wp_enqueue_script( 'accepta-repeater-control', get_template_directory_uri() . '/inc/customizer-controls/js/repeater-control.js', array( 'jquery', 'customize-base', 'jquery-ui-sortable' ), wp_get_theme()->get( 'Version' ), true ); wp_enqueue_style( 'accepta-repeater-control', get_template_directory_uri() . '/inc/customizer-controls/css/repeater-control.css', array( 'font-awesome' ), wp_get_theme()->get( 'Version' ) ); // Localize script for translations and theme data wp_localize_script( 'accepta-repeater-control', 'acceptaRepeaterL10n', array( 'confirmDelete' => __( 'Are you sure you want to delete this item?', 'accepta' ), 'addNew' => __( 'Add New Item', 'accepta' ), 'maxItems' => sprintf( __( 'Maximum %d items allowed', 'accepta' ), $this->max_items ), 'templateUrl' => get_template_directory_uri(), ) ); } /** * Render the control's content */ public function render_content() { $input_id = '_customize-input-' . $this->id; $describedby_attr = ''; if ( ! empty( $this->description ) ) { $describedby_attr = 'aria-describedby="' . esc_attr( $input_id ) . '-description"'; } ?>
label ) ) : ?> label ); ?> description ) ) : ?> description; ?>
render_items(); ?>
link(); ?> value="value() ); ?>" class="accepta-repeater-input" />
value(); $items = array(); if ( ! empty( $value ) ) { $items = json_decode( $value, true ); if ( ! is_array( $items ) ) { $items = array(); } } if ( empty( $items ) && ! empty( $this->default_item ) ) { $items = array( $this->default_item ); } foreach ( $items as $index => $item ) { $this->render_item( $item, $index ); } } /** * Render a single item */ private function render_item( $item = array(), $index = 0 ) { ?>
render_item_fields( $item, $index ); ?>
render_item_fields_template(); ?>
fields as $field_key => $field_config ) { $field_value = isset( $item[ $field_key ] ) ? $item[ $field_key ] : ''; $this->render_field( $field_key, $field_config, $field_value, $index ); } } /** * Render fields template for JavaScript */ private function render_item_fields_template() { foreach ( $this->fields as $field_key => $field_config ) { $this->render_field_template( $field_key, $field_config ); } } /** * Render a single field */ private function render_field( $field_key, $field_config, $value = '', $index = 0 ) { $field_id = $this->id . '_' . $index . '_' . $field_key; $field_name = $this->id . '[' . $index . '][' . $field_key . ']'; ?>
render_field_input( $field_key, $field_config, $value, $field_id, $field_name ); ?>
render_field_input_template( $field_key, $field_config ); ?>