' : '
'; ?> '; ?>

' : '
'; ?> ' : '
'; ?> '; ?>

' : '
'; ?> ' : '
'; ?> ' . esc_html__( 'Use variation images?', 'flatsome' ) . '' : '
'; ?> attribute_name . '_add_form_fields', array( $this, 'add_attribute_term_fields' ) ); add_action( 'pa_' . $tax->attribute_name . '_edit_form_fields', array( $this, 'edit_attribute_term_fields' ), 10, 2 ); add_filter( 'manage_edit-pa_' . $tax->attribute_name . '_columns', array( $this, 'add_attribute_columns' ) ); add_filter( 'manage_pa_' . $tax->attribute_name . '_custom_column', array( $this, 'add_attribute_column_content' ), 10, 3 ); } add_action( 'created_term', array( $this, 'save_term_meta' ), 10, 3 ); add_action( 'edit_term', array( $this, 'save_term_meta' ), 10, 3 ); add_action( 'edit_term', array( flatsome_swatches(), 'cache_clear' ), 10, 3 ); } /** * Load scripts in edit product attribute screen. */ public function enqueue_scripts() { $screen = get_current_screen(); if ( $screen && strpos( $screen->id, 'edit-pa_' ) === false && strpos( $screen->id, 'product' ) === false ) { return; } wp_enqueue_media(); wp_enqueue_style( 'flatsome-swatches-admin', get_template_directory_uri() . '/assets/css/extensions/flatsome-swatches-admin.css', array( 'wp-color-picker' ), flatsome_swatches()->version ); wp_enqueue_script( 'flatsome-swatches-admin', get_template_directory_uri() . '/assets/js/extensions/flatsome-swatches-admin.js', array( 'jquery', 'wp-color-picker', 'wp-util', ), flatsome_swatches()->version, true ); wp_localize_script( 'flatsome-swatches-admin', 'flatsome_swatches', array( 'placeholder' => WC()->plugin_url() . '/assets/images/placeholder.png', ) ); } /** * Create hook to add fields to add attribute term screen. * * @param string $taxonomy Taxonomy. */ public function add_attribute_term_fields( $taxonomy ) { $attr = flatsome_swatches()->get_attribute( $taxonomy ); do_action( 'flatsome_product_attribute_term_fields', $attr->attribute_type, '', 'add' ); } /** * Create hook to fields to edit attribute term screen. * * @param object $term Term. * @param string $taxonomy Taxonomy. */ public function edit_attribute_term_fields( $term, $taxonomy ) { $attr = flatsome_swatches()->get_attribute( $taxonomy ); $value = get_term_meta( $term->term_id, $attr->attribute_type, true ); do_action( 'flatsome_product_attribute_term_fields', $attr->attribute_type, $value, 'edit' ); } /** * Print HTML of custom field on attribute term add/edit screens. * * @param string $type Attribute type. * @param string $value Field value. * @param string $form The form kind. */ public function attribute_term_field( $type, $value, $form ) { // Return if this is a default attribute type. if ( in_array( $type, array( 'select', 'text' ), true ) ) { return; } $name = $type; // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped printf( '<%s class="form-field term-%s-wrap">%s%s', 'edit' == $form ? 'tr' : 'div', esc_attr( $type ), 'edit' == $form ? '' : '', esc_attr( $type ), esc_html( flatsome_swatches()->get_attribute_types()[ $type ] ), 'edit' == $form ? '' : '' ); // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped switch ( $type ) { case 'ux_image': $image = $value ? wp_get_attachment_image_src( $value ) : ''; $image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png'; ?>

The swatch image.

parse_ux_color_term_meta( $value ); $value = $color['color']; $value_2 = ''; $name .= '[]'; if ( $color['color_2'] ) $value_2 = $color['color_2']; ?>

The swatch color.

The swatch text.

' : ''; } /** * Save term meta. * * @param int $term_id Term ID. * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ public function save_term_meta( $term_id, $tt_id, $taxonomy ) { foreach ( flatsome_swatches()->get_attribute_types() as $type => $label ) { if ( isset( $_POST[ $type ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $value = wp_unslash( $_POST[ $type ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( is_array( $value ) ) { $array_values = array_filter( $value ); if ( empty( $array_values ) ) { $value = ''; } else { $value = implode( ',', $array_values ); } } update_term_meta( $term_id, $type, sanitize_text_field( $value ) ); } } } /** * Attribute added. * * @param int $id Added attribute ID. * @param array $data Attribute data. */ public function add_attribute_options( $id, $data ) { // phpcs:disable WordPress.Security.NonceVerification $values = array( 'swatch_size' => isset( $_POST['attribute_swatch_size'] ) ? sanitize_text_field( wp_unslash( $_POST['attribute_swatch_size'] ) ) : '', 'swatch_shape' => isset( $_POST['attribute_swatch_shape'] ) ? sanitize_text_field( wp_unslash( $_POST['attribute_swatch_shape'] ) ) : '', 'swatch_variation_images' => isset( $_POST['attribute_swatch_variation_images'] ) ? isset( $_POST['attribute_swatch_variation_images'] ) : '', ); // phpcs:enable WordPress.Security.NonceVerification add_option( "flatsome_product_attribute-{$id}", $values ); } /** * Attribute updated. * * @param int $id Added attribute ID. * @param array $data Attribute data. * @param string $old_slug Attribute old name. */ public function update_attribute_options( $id, $data, $old_slug ) { // phpcs:disable WordPress.Security.NonceVerification $values = array( 'swatch_size' => isset( $_POST['attribute_swatch_size'] ) ? sanitize_text_field( wp_unslash( $_POST['attribute_swatch_size'] ) ) : '', 'swatch_shape' => isset( $_POST['attribute_swatch_shape'] ) ? sanitize_text_field( wp_unslash( $_POST['attribute_swatch_shape'] ) ) : '', 'swatch_variation_images' => isset( $_POST['attribute_swatch_variation_images'] ) ? isset( $_POST['attribute_swatch_variation_images'] ) : '', ); // phpcs:enable WordPress.Security.NonceVerification update_option( "flatsome_product_attribute-{$id}", $values ); } /** * Attribute deleted. * * @param int $id Added attribute ID. */ public function delete_attribute_option( $id ) { delete_option( "flatsome_product_attribute-{$id}" ); } /** * Add thumbnail column to column list * * @param array $columns Columns. * * @return array */ public function add_attribute_columns( $columns ) { if ( empty( $columns ) ) { return $columns; } $new_columns = array(); $new_columns['cb'] = $columns['cb']; $new_columns['ux_swatch_preview'] = __( 'Value', 'flatsome' ); unset( $columns['cb'] ); return array_merge( $new_columns, $columns ); } /** * Render thumbnail HTML depend on attribute type * * @param string $content Current content. * @param string $column Column name. * @param string|int $term_id Term ID. */ public function add_attribute_column_content( $content, $column, $term_id ) { if ( 'ux_swatch_preview' === $column ) { $classes = array( 'ux-swatch-preview' ); $attr = flatsome_swatches()->get_attribute( $_REQUEST['taxonomy'] ); // phpcs:ignore $value = get_term_meta( $term_id, $attr->attribute_type, true ); switch ( $attr->attribute_type ) { case 'ux_color': $color_classes = array( 'ux-swatch__color' ); $color = flatsome_swatches()->parse_ux_color_term_meta( $value ); $classes[] = 'ux-swatch--color'; $color_classes[] = $color['class']; printf( '
', esc_attr( implode( ' ', $classes ) ), esc_attr( implode( ' ', $color_classes ) ), $color['style'] // phpcs:ignore WordPress.Security.EscapeOutput ); break; case 'ux_image': $image = $value ? wp_get_attachment_image_src( $value ) : ''; $image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png'; $classes[] = 'ux-swatch--image'; printf( '
', esc_attr( implode( ' ', $classes ) ), esc_url( $image ) ); break; case 'ux_label': $classes[] = 'ux-swatch--label'; printf( '
%s
', esc_attr( implode( ' ', $classes ) ), esc_html( $value ) ); break; } } } }