Plugin Directory

Changeset 3075625


Ignore:
Timestamp:
04/23/2024 10:35:47 AM (2 years ago)
Author:
EmranAhmed
Message:

Update to 2.0.31

Location:
woo-variation-swatches
Files:
60 added
11 edited

Legend:

Unmodified
Added
Removed
  • woo-variation-swatches/trunk/README.txt

    r3021867 r3075625  
    44Requires PHP: 7.4
    55Requires at least: 5.6
    6 Tested up to: 6.4
     6Tested up to: 6.5
    77WC requires at least: 5.6
    8 WC tested up to: 8.4
    9 Stable tag: 2.0.30
     8WC tested up to: 8.8
     9Stable tag: 2.0.31
    1010License: GPLv3
    1111License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    615615== Changelog ==
    616616
     617= 2.0.31 - 23-04-2024 =
     618
     619* Update: WordPress 6.5+ Compatibility.
     620* Update: WooCommerce 8.8+ Compatibility.
     621
    617622= 2.0.30 - 15-01-2023 =
    618623
  • woo-variation-swatches/trunk/assets/css/admin.css

    r3021867 r3075625  
    33 *
    44 * Author: Emran Ahmed ( emran.bd.08@gmail.com )
    5  * Date: 1/15/2024, 5:59:37 PM
     5 * Date: 4/23/2024, 3:54:19 PM
    66 * Released under the GPLv3 license.
    77 */
  • woo-variation-swatches/trunk/assets/css/frontend.css

    r3021867 r3075625  
    33 *
    44 * Author: Emran Ahmed ( emran.bd.08@gmail.com )
    5  * Date: 1/15/2024, 5:59:37 PM
     5 * Date: 4/23/2024, 3:54:19 PM
    66 * Released under the GPLv3 license.
    77 */
  • woo-variation-swatches/trunk/assets/js/admin.js

    r3021867 r3075625  
    33 *
    44 * Author: Emran Ahmed ( emran.bd.08@gmail.com )
    5  * Date: 1/15/2024, 5:59:37 PM
     5 * Date: 4/23/2024, 3:54:19 PM
    66 * Released under the GPLv3 license.
    77 */
  • woo-variation-swatches/trunk/assets/js/frontend.js

    r3021867 r3075625  
    33 *
    44 * Author: Emran Ahmed ( emran.bd.08@gmail.com )
    5  * Date: 1/15/2024, 5:59:37 PM
     5 * Date: 4/23/2024, 3:54:19 PM
    66 * Released under the GPLv3 license.
    77 */
  • woo-variation-swatches/trunk/assets/js/wp-color-picker-alpha.js

    r3021867 r3075625  
    33 *
    44 * Author: Emran Ahmed ( emran.bd.08@gmail.com )
    5  * Date: 1/15/2024, 5:59:37 PM
     5 * Date: 4/23/2024, 3:54:19 PM
    66 * Released under the GPLv3 license.
    77 */
  • woo-variation-swatches/trunk/includes/class-woo-variation-swatches-term-meta.php

    r2850234 r3075625  
    11<?php
     2   
     3    defined( 'ABSPATH' ) or die( 'Keep Silent' );
     4   
     5    if ( ! class_exists( 'Woo_Variation_Swatches_Term_Meta' ) ):
     6        class Woo_Variation_Swatches_Term_Meta {
     7           
     8            private $taxonomy;
     9            private $post_type;
     10            private $fields = array();
     11           
     12            public function __construct( $taxonomy, $post_type, $fields = array() ) {
     13               
     14                $this->taxonomy  = $taxonomy;
     15                $this->post_type = $post_type;
     16                $this->fields    = $fields;
     17               
     18                // Category/term ordering
     19                // add_action( 'create_term', array( $this, 'create_term' ), 5, 3 );
     20               
     21                add_action( 'delete_term', array( $this, 'delete_term' ), 5, 4 );
     22               
     23                // Add form
     24                add_action( "{$this->taxonomy}_add_form_fields", array( $this, 'add' ) );
     25                add_action( "{$this->taxonomy}_edit_form_fields", array( $this, 'edit' ), 10 );
     26                add_action( "created_term", array( $this, 'save' ), 10, 3 );
     27                add_action( "edit_term", array( $this, 'save' ), 10, 3 );
     28                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
     29               
     30                // Add columns
     31                add_filter( "manage_edit-{$this->taxonomy}_columns", array( $this, 'taxonomy_columns' ) );
     32                add_filter( "manage_{$this->taxonomy}_custom_column", array( $this, 'taxonomy_column_preview' ), 10, 3 );
     33                add_filter( "manage_{$this->taxonomy}_custom_column", array( $this, 'taxonomy_column_group' ), 10, 3 );
     34               
     35                do_action( 'woo_variation_swatches_term_meta_loaded', $this );
     36            }
     37           
     38            public function preview( $attribute_type, $term_id, $fields ) {
     39               
     40                $meta_key = $fields[ 0 ][ 'id' ]; // take first key for preview
     41               
     42                $this->color_preview( $attribute_type, $term_id, $meta_key );
     43                $this->image_preview( $attribute_type, $term_id, $meta_key );
     44               
     45            }
     46           
     47            public function color_preview( $attribute_type, $term_id, $key ) {
     48               
     49                if ( 'color' === $attribute_type ) {
     50                    $primary_color = sanitize_hex_color( get_term_meta( $term_id, $key, true ) );
     51                   
     52                    $is_dual_color   = wc_string_to_bool( get_term_meta( $term_id, 'is_dual_color', true ) );
     53                    $secondary_color = sanitize_hex_color( get_term_meta( $term_id, 'secondary_color', true ) );
     54                   
     55                    if ( $is_dual_color && woo_variation_swatches()->is_pro() ) {
     56                        $angle = woo_variation_swatches()->get_frontend()->get_dual_color_gradient_angle();
     57                        printf( '<div class="wvs-preview wvs-color-preview wvs-dual-color-preview" style="background: linear-gradient(%3$s, %1$s 0%%, %1$s 50%%, %2$s 50%%, %2$s 100%%);"></div>', esc_attr( $secondary_color ), esc_attr( $primary_color ), esc_attr( $angle ) );
     58                    } else {
     59                        printf( '<div class="wvs-preview wvs-color-preview" style="background-color:%s;"></div>', esc_attr( $primary_color ) );
     60                    }
     61                }
     62            }
     63           
     64            public function group_name( $attribute_type, $term_id ) {
     65               
     66                if ( ! woo_variation_swatches()->is_pro() ) {
     67                    return '';
     68                }
     69               
     70                $group = sanitize_text_field( get_term_meta( $term_id, 'group_name', true ) );
     71                if ( $group ) {
     72                    return sanitize_text_field( woo_variation_swatches()->get_backend()->get_group()->get( $group ) );
     73                }
     74               
     75                return '';
     76            }
     77           
     78            public function image_preview( $attribute_type, $term_id, $key ) {
     79                if ( 'image' == $attribute_type ) {
     80                    $attachment_id = absint( get_term_meta( $term_id, $key, true ) );
     81                    $image         = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
     82                   
     83                    if ( is_array( $image ) ) {
     84                        printf( '<img src="%s" alt="" width="%d" height="%d" class="wvs-preview wvs-image-preview" />', esc_url( $image[ 0 ] ), $image[ 1 ], $image[ 2 ] );
     85                    }
     86                }
     87            }
     88           
     89            public function taxonomy_columns( $columns ) {
     90                $new_columns = array();
     91               
     92                if ( isset( $columns[ 'cb' ] ) ) {
     93                    $new_columns[ 'cb' ] = $columns[ 'cb' ];
     94                }
     95               
     96                $new_columns[ 'wvs-meta-preview' ] = '';
     97               
     98                if ( isset( $columns[ 'cb' ] ) ) {
     99                    unset( $columns[ 'cb' ] );
     100                }
     101               
     102                if ( woo_variation_swatches()->is_pro() ) {
     103                    $columns[ 'wvs-meta-group' ] = esc_html__( 'Group', 'woo-variation-swatches' );
     104                }
     105               
     106                return array_merge( $new_columns, $columns );
     107            }
     108           
     109            public function taxonomy_column_preview( $columns, $column, $term_id ) {
     110               
     111                if ( 'wvs-meta-preview' !== $column ) {
     112                    return $columns;
     113                }
     114               
     115                $attribute      = woo_variation_swatches()->get_backend()->get_attribute_taxonomy( $this->taxonomy );
     116                $attribute_type = $attribute->attribute_type;
     117                $this->preview( $attribute_type, $term_id, $this->fields );
     118               
     119                return $columns;
     120            }
     121           
     122            public function taxonomy_column_group( $columns, $column, $term_id ) {
     123               
     124                if ( 'wvs-meta-group' !== $column ) {
     125                    return $columns;
     126                }
     127               
     128                $attribute = woo_variation_swatches()->get_backend()->get_attribute_taxonomy( $this->taxonomy );
     129               
     130                $attribute_type = $attribute->attribute_type;
     131               
     132                echo $this->group_name( $attribute_type, $term_id );
     133               
     134                return $columns;
     135            }
     136           
     137            public function delete_term( $term_id, $tt_id, $taxonomy, $deleted_term ) {
     138                global $wpdb;
     139               
     140                $term_id = absint( $term_id );
     141                if ( $term_id and $taxonomy == $this->taxonomy ) {
     142                    $wpdb->delete( $wpdb->termmeta, array( 'term_id' => $term_id ), array( '%d' ) );
     143                }
     144            }
     145           
     146            public function enqueue_scripts() {
     147                wp_enqueue_media();
     148                wp_enqueue_style( 'wp-color-picker' );
     149                wp_enqueue_script( 'wp-color-picker' );
     150            }
     151           
     152            public function save( $term_id, $tt_id = '', $taxonomy = '' ) {
     153               
     154                if ( $taxonomy == $this->taxonomy ) {
     155                    foreach ( $this->fields as $field ) {
     156                        foreach ( $_POST as $post_key => $post_value ) {
     157                            if ( $field[ 'id' ] == $post_key ) {
     158                                switch ( $field[ 'type' ] ) {
     159                                    case 'text':
     160                                    case 'color':
     161                                        $post_value = esc_html( $post_value );
     162                                        break;
     163                                    case 'url':
     164                                        $post_value = esc_url( $post_value );
     165                                        break;
     166                                    case 'image':
     167                                        $post_value = absint( $post_value );
     168                                        break;
     169                                    case 'textarea':
     170                                        $post_value = esc_textarea( $post_value );
     171                                        break;
     172                                    case 'editor':
     173                                        $post_value = wp_kses_post( $post_value );
     174                                        break;
     175                                    case 'select':
     176                                    case 'select2':
     177                                        $post_value = sanitize_key( $post_value );
     178                                        break;
     179                                    case 'checkbox':
     180                                        $post_value = sanitize_key( $post_value );
     181                                        break;
     182                                    default:
     183                                        do_action( 'woo_variation_swatches_save_term_meta', $term_id, $field, $post_value, $taxonomy );
     184                                        break;
     185                                }
     186                                update_term_meta( $term_id, $field[ 'id' ], $post_value );
     187                            }
     188                        }
     189                    }
     190                    do_action( 'woo_variation_swatches_after_term_meta_saved', $term_id, $taxonomy );
     191                }
     192            }
     193           
     194            public function add() {
     195                $this->generate_fields();
     196            }
     197           
     198            private function generate_fields( $term = false ) {
     199               
     200                $screen           = get_current_screen();
     201                $screen_post_type = $screen ? $screen->post_type : '';
     202                $screen_taxonomy  = $screen ? $screen->taxonomy : '';
     203               
     204                if ( ( $screen_post_type === $this->post_type ) and ( $screen_taxonomy === $this->taxonomy ) ) {
     205                    self::generate_form_fields( $this->fields, $term );
     206                }
     207            }
     208           
     209            public static function generate_form_fields( $fields, $term ) {
     210               
     211                $fields = apply_filters( 'woo_variation_swatches_term_meta_fields', $fields, $term );
     212               
     213                if ( empty( $fields ) ) {
     214                    return;
     215                }
     216               
     217                foreach ( $fields as $field ) {
     218                   
     219                    $field = apply_filters( 'woo_variation_swatches_term_meta_field', $field, $term );
     220                   
     221                    $field[ 'id' ] = esc_html( $field[ 'id' ] );
     222                   
     223                    if ( ! $term ) {
     224                        $field[ 'value' ] = isset( $field[ 'default' ] ) ? $field[ 'default' ] : '';
     225                    } else {
     226                        $field[ 'value' ] = get_term_meta( $term->term_id, $field[ 'id' ], true );
     227                    }
     228                   
     229                   
     230                    $field[ 'size' ]        = isset( $field[ 'size' ] ) ? $field[ 'size' ] : '40';
     231                    $field[ 'required' ]    = ( isset( $field[ 'required' ] ) and $field[ 'required' ] == true ) ? ' aria-required="true"' : '';
     232                    $field[ 'placeholder' ] = ( isset( $field[ 'placeholder' ] ) ) ? ' placeholder="' . esc_attr( $field[ 'placeholder' ] ) . '" data-placeholder="' . esc_attr( $field[ 'placeholder' ] ) . '"' : '';
     233                    $field[ 'desc' ]        = ( isset( $field[ 'desc' ] ) ) ? $field[ 'desc' ] : '';
     234                   
     235                    $field[ 'dependency' ]       = ( isset( $field[ 'dependency' ] ) ) ? $field[ 'dependency' ] : array();
     236                   
     237                    self::field_start( $field, $term );
     238                    switch ( $field[ 'type' ] ) {
     239                        case 'text':
     240                        case 'url':
     241                            ob_start();
     242                            ?>
     243                            <input name="<?php echo esc_attr( $field[ 'id' ] ) ?>" id="<?php echo esc_attr( $field[ 'id' ] ) ?>"
     244                                   type="<?php echo esc_attr( $field[ 'type' ] ) ?>"
     245                                   value="<?php echo esc_attr( $field[ 'value' ] ) ?>"
     246                                   size="<?php echo esc_attr( $field[ 'size' ] ) ?>" <?php echo $field[ 'required' ] . $field[ 'placeholder' ] ?>>
     247                            <?php
     248                            echo ob_get_clean();
     249                            break;
     250                        case 'color':
     251                            ob_start();
     252                            ?>
     253                            <input name="<?php echo esc_attr( $field[ 'id' ] ) ?>" id="<?php echo esc_attr( $field[ 'id' ] ) ?>" type="text"
     254                                   class="wvs-color-picker" value="<?php echo esc_attr( $field[ 'value' ] ) ?>"
     255                                   data-default-color="<?php echo esc_attr( $field[ 'value' ] ) ?>"
     256                                   size="<?php echo esc_attr( $field[ 'size' ] ) ?>" <?php echo $field[ 'required' ] . $field[ 'placeholder' ] ?>>
     257                            <?php
     258                            echo ob_get_clean();
     259                            break;
     260                        case 'textarea':
     261                            ob_start();
     262                            ?>
     263                            <textarea name="<?php echo esc_attr( $field[ 'id' ] ) ?>" id="<?php echo esc_attr( $field[ 'id' ] ) ?>" rows="5"
     264                                      cols="<?php echo esc_attr( $field[ 'size' ] ) ?>" <?php echo $field[ 'required' ] . $field[ 'placeholder' ] ?>><?php echo esc_textarea( $field[ 'value' ] ) ?></textarea>
     265                            <?php
     266                            echo ob_get_clean();
     267                            break;
     268                        case 'editor':
     269                            $field[ 'settings' ] = isset( $field[ 'settings' ] )
     270                                ? $field[ 'settings' ]
     271                                : array(
     272                                    'textarea_rows' => 8,
     273                                    'quicktags'     => false,
     274                                    'media_buttons' => false
     275                                );
     276                            ob_start();
     277                            wp_editor( $field[ 'value' ], $field[ 'id' ], $field[ 'settings' ] );
     278                            echo ob_get_clean();
     279                            break;
     280                        case 'select':
     281                        case 'select2':
     282                           
     283                            $field[ 'options' ] = isset( $field[ 'options' ] ) ? $field[ 'options' ] : array();
     284                            $field[ 'multiple' ] = isset( $field[ 'multiple' ] ) ? ' multiple="multiple"' : '';
     285                            $css_class           = ( $field[ 'type' ] == 'select2' ) ? 'wc-enhanced-select' : '';
     286                           
     287                            ob_start();
     288                            ?>
     289                            <select name="<?php echo esc_attr( $field[ 'id' ] ) ?>" id="<?php echo esc_attr( $field[ 'id' ] ) ?>"
     290                                    class="<?php echo esc_attr( $css_class ) ?>" <?php echo $field[ 'multiple' ] ?>>
     291                                <?php
     292                                    foreach ( $field[ 'options' ] as $key => $option ) {
     293                                        echo '<option' . selected( $field[ 'value' ], $key, false ) . ' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
     294                                    }
     295                                ?>
     296                            </select>
     297                            <?php
     298                            echo ob_get_clean();
     299                            break;
     300                        case 'image':
     301                            ob_start();
     302                            ?>
     303                            <div class="meta-image-field-wrapper">
     304                                <div class="image-preview">
     305                                    <img data-placeholder="<?php echo esc_url( self::placeholder_img_src() ); ?>"
     306                                         src="<?php echo esc_url( self::get_img_src( $field[ 'value' ] ) ); ?>"
     307                                         width="60px" height="60px"/>
     308                                </div>
     309                                <div class="button-wrapper">
     310                                    <input type="hidden" id="<?php echo esc_attr( $field[ 'id' ] ) ?>"
     311                                           name="<?php echo esc_attr( $field[ 'id' ] ) ?>"
     312                                           value="<?php echo esc_attr( $field[ 'value' ] ) ?>"/>
     313                                    <button type="button"
     314                                            class="wvs_upload_image_button button button-primary button-small"><?php esc_html_e( 'Upload / Add image', 'woo-variation-swatches' ); ?></button>
     315                                    <button type="button"
     316                                            style="<?php echo( empty( $field[ 'value' ] ) ? 'display:none' : '' ) ?>"
     317                                            class="wvs_remove_image_button button button-danger button-small"><?php esc_html_e( 'Remove image', 'woo-variation-swatches' ); ?></button>
     318                                </div>
     319                            </div>
     320                            <?php
     321                            echo ob_get_clean();
     322                            break;
     323                        case 'checkbox':
     324                           
     325                            ob_start();
     326                            ?>
     327                            <label for="<?php echo esc_attr( $field[ 'id' ] ) ?>">
    2328
    3 defined( 'ABSPATH' ) or die( 'Keep Silent' );
    4 
    5 if ( ! class_exists( 'Woo_Variation_Swatches_Term_Meta' ) ):
    6     class Woo_Variation_Swatches_Term_Meta {
    7 
    8         private $taxonomy;
    9         private $post_type;
    10         private $fields = array();
    11 
    12         public function __construct( $taxonomy, $post_type, $fields = array() ) {
    13 
    14             $this->taxonomy  = $taxonomy;
    15             $this->post_type = $post_type;
    16             $this->fields    = $fields;
    17 
    18             // Category/term ordering
    19             // add_action( 'create_term', array( $this, 'create_term' ), 5, 3 );
    20 
    21             add_action( 'delete_term', array( $this, 'delete_term' ), 5, 4 );
    22 
    23             // Add form
    24             add_action( "{$this->taxonomy}_add_form_fields", array( $this, 'add' ) );
    25             add_action( "{$this->taxonomy}_edit_form_fields", array( $this, 'edit' ), 10 );
    26             add_action( "created_term", array( $this, 'save' ), 10, 3 );
    27             add_action( "edit_term", array( $this, 'save' ), 10, 3 );
    28             add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    29 
    30             // Add columns
    31             add_filter( "manage_edit-{$this->taxonomy}_columns", array( $this, 'taxonomy_columns' ) );
    32             add_filter( "manage_{$this->taxonomy}_custom_column", array( $this, 'taxonomy_column_preview' ), 10, 3 );
    33             add_filter( "manage_{$this->taxonomy}_custom_column", array( $this, 'taxonomy_column_group' ), 10, 3 );
    34 
    35             do_action( 'woo_variation_swatches_term_meta_loaded', $this );
    36         }
    37 
    38         public function preview( $attribute_type, $term_id, $fields ) {
    39 
    40             $meta_key = $fields[0]['id']; // take first key for preview
    41 
    42             $this->color_preview( $attribute_type, $term_id, $meta_key );
    43             $this->image_preview( $attribute_type, $term_id, $meta_key );
    44 
    45         }
    46 
    47         public function color_preview( $attribute_type, $term_id, $key ) {
    48 
    49             if ( 'color' === $attribute_type ) {
    50                 $primary_color = sanitize_hex_color( get_term_meta( $term_id, $key, true ) );
    51 
    52                 $is_dual_color   = wc_string_to_bool( get_term_meta( $term_id, 'is_dual_color', true ) );
    53                 $secondary_color = sanitize_hex_color( get_term_meta( $term_id, 'secondary_color', true ) );
    54 
    55                 if ( $is_dual_color && woo_variation_swatches()->is_pro() ) {
    56                     $angle = woo_variation_swatches()->get_frontend()->get_dual_color_gradient_angle();
    57                     printf( '<div class="wvs-preview wvs-color-preview wvs-dual-color-preview" style="background: linear-gradient(%3$s, %1$s 0%%, %1$s 50%%, %2$s 50%%, %2$s 100%%);"></div>', esc_attr( $secondary_color ), esc_attr( $primary_color ), esc_attr( $angle ) );
    58                 } else {
    59                     printf( '<div class="wvs-preview wvs-color-preview" style="background-color:%s;"></div>', esc_attr( $primary_color ) );
    60                 }
    61             }
    62         }
    63 
    64         public function group_name( $attribute_type, $term_id ) {
    65 
    66             if ( ! woo_variation_swatches()->is_pro() ) {
    67                 return '';
    68             }
    69 
    70             $group = sanitize_text_field( get_term_meta( $term_id, 'group_name', true ) );
    71             if ( $group ) {
    72                 return sanitize_text_field( woo_variation_swatches()->get_backend()->get_group()->get( $group ) );
    73             }
    74 
    75             return '';
    76         }
    77 
    78         public function image_preview( $attribute_type, $term_id, $key ) {
    79             if ( 'image' == $attribute_type ) {
    80                 $attachment_id = absint( get_term_meta( $term_id, $key, true ) );
    81                 $image         = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
    82 
    83                 if ( is_array( $image ) ) {
    84                     printf( '<img src="%s" alt="" width="%d" height="%d" class="wvs-preview wvs-image-preview" />', esc_url( $image[0] ), $image[1], $image[2] );
    85                 }
    86             }
    87         }
    88 
    89         public function taxonomy_columns( $columns ) {
    90             $new_columns = array();
    91 
    92             if ( isset( $columns['cb'] ) ) {
    93                 $new_columns['cb'] = $columns['cb'];
    94             }
    95 
    96             $new_columns['wvs-meta-preview'] = '';
    97 
    98             if ( isset( $columns['cb'] ) ) {
    99                 unset( $columns['cb'] );
    100             }
    101 
    102             if ( woo_variation_swatches()->is_pro() ) {
    103                 $columns['wvs-meta-group'] = esc_html__( 'Group', 'woo-variation-swatches' );
    104             }
    105 
    106             return array_merge( $new_columns, $columns );
    107         }
    108 
    109         public function taxonomy_column_preview( $columns, $column, $term_id ) {
    110 
    111             if ( 'wvs-meta-preview' !== $column ) {
    112                 return $columns;
    113             }
    114 
    115             $attribute      = woo_variation_swatches()->get_backend()->get_attribute_taxonomy( $this->taxonomy );
    116             $attribute_type = $attribute->attribute_type;
    117             $this->preview( $attribute_type, $term_id, $this->fields );
    118 
    119             return $columns;
    120         }
    121 
    122         public function taxonomy_column_group( $columns, $column, $term_id ) {
    123 
    124             if ( 'wvs-meta-group' !== $column ) {
    125                 return $columns;
    126             }
    127 
    128             $attribute = woo_variation_swatches()->get_backend()->get_attribute_taxonomy( $this->taxonomy );
    129 
    130             $attribute_type = $attribute->attribute_type;
    131 
    132             echo $this->group_name( $attribute_type, $term_id );
    133 
    134             return $columns;
    135         }
    136 
    137         public function delete_term( $term_id, $tt_id, $taxonomy, $deleted_term ) {
    138             global $wpdb;
    139 
    140             $term_id = absint( $term_id );
    141             if ( $term_id and $taxonomy == $this->taxonomy ) {
    142                 $wpdb->delete( $wpdb->termmeta, array( 'term_id' => $term_id ), array( '%d' ) );
    143             }
    144         }
    145 
    146         public function enqueue_scripts() {
    147             wp_enqueue_media();
    148             wp_enqueue_style( 'wp-color-picker' );
    149             wp_enqueue_script( 'wp-color-picker' );
    150         }
    151 
    152         public function save( $term_id, $tt_id = '', $taxonomy = '' ) {
    153 
    154             if ( $taxonomy == $this->taxonomy ) {
    155                 foreach ( $this->fields as $field ) {
    156                     foreach ( $_POST as $post_key => $post_value ) {
    157                         if ( $field['id'] == $post_key ) {
    158                             switch ( $field['type'] ) {
    159                                 case 'text':
    160                                 case 'color':
    161                                     $post_value = esc_html( $post_value );
    162                                     break;
    163                                 case 'url':
    164                                     $post_value = esc_url( $post_value );
    165                                     break;
    166                                 case 'image':
    167                                     $post_value = absint( $post_value );
    168                                     break;
    169                                 case 'textarea':
    170                                     $post_value = esc_textarea( $post_value );
    171                                     break;
    172                                 case 'editor':
    173                                     $post_value = wp_kses_post( $post_value );
    174                                     break;
    175                                 case 'select':
    176                                 case 'select2':
    177                                     $post_value = sanitize_key( $post_value );
    178                                     break;
    179                                 case 'checkbox':
    180                                     $post_value = sanitize_key( $post_value );
    181                                     break;
    182                                 default:
    183                                     do_action( 'woo_variation_swatches_save_term_meta', $term_id, $field, $post_value, $taxonomy );
    184                                     break;
    185                             }
    186                             update_term_meta( $term_id, $field['id'], $post_value );
    187                         }
    188                     }
    189                 }
    190                 do_action( 'woo_variation_swatches_after_term_meta_saved', $term_id, $taxonomy );
    191             }
    192         }
    193 
    194         public function add() {
    195             $this->generate_fields();
    196         }
    197 
    198         private function generate_fields( $term = false ) {
    199 
    200             $screen = get_current_screen();
    201 
    202             if ( ( $screen->post_type == $this->post_type ) and ( $screen->taxonomy == $this->taxonomy ) ) {
    203                 self::generate_form_fields( $this->fields, $term );
    204             }
    205         }
    206 
    207         public static function generate_form_fields( $fields, $term ) {
    208 
    209             $fields = apply_filters( 'woo_variation_swatches_term_meta_fields', $fields, $term );
    210 
    211             if ( empty( $fields ) ) {
    212                 return;
    213             }
    214 
    215             foreach ( $fields as $field ) {
    216 
    217                 $field = apply_filters( 'woo_variation_swatches_term_meta_field', $field, $term );
    218 
    219                 $field['id'] = esc_html( $field['id'] );
    220 
    221                 if ( ! $term ) {
    222                     $field['value'] = isset( $field['default'] ) ? $field['default'] : '';
    223                 } else {
    224                     $field['value'] = get_term_meta( $term->term_id, $field['id'], true );
    225                 }
    226 
    227 
    228                 $field['size']        = isset( $field['size'] ) ? $field['size'] : '40';
    229                 $field['required']    = ( isset( $field['required'] ) and $field['required'] == true ) ? ' aria-required="true"' : '';
    230                 $field['placeholder'] = ( isset( $field['placeholder'] ) ) ? ' placeholder="' . esc_attr( $field['placeholder'] ) . '" data-placeholder="' . esc_attr( $field['placeholder'] ) . '"' : '';
    231                 $field['desc']        = ( isset( $field['desc'] ) ) ? $field['desc'] : '';
    232 
    233                 $field['dependency']       = ( isset( $field['dependency'] ) ) ? $field['dependency'] : array();
    234 
    235                 self::field_start( $field, $term );
    236                 switch ( $field['type'] ) {
    237                     case 'text':
    238                     case 'url':
    239                         ob_start();
    240                         ?>
    241                         <input name="<?php echo esc_attr( $field['id'] ) ?>" id="<?php echo esc_attr( $field['id'] ) ?>"
    242                                type="<?php echo esc_attr( $field['type'] ) ?>"
    243                                value="<?php echo esc_attr( $field['value'] ) ?>"
    244                                size="<?php echo esc_attr( $field['size'] ) ?>" <?php echo $field['required'] . $field['placeholder'] ?>>
    245                         <?php
    246                         echo ob_get_clean();
    247                         break;
    248                     case 'color':
    249                         ob_start();
    250                         ?>
    251                         <input name="<?php echo esc_attr( $field['id'] ) ?>" id="<?php echo esc_attr( $field['id'] ) ?>" type="text"
    252                                class="wvs-color-picker" value="<?php echo esc_attr( $field['value'] ) ?>"
    253                                data-default-color="<?php echo esc_attr( $field['value'] ) ?>"
    254                                size="<?php echo esc_attr( $field['size'] ) ?>" <?php echo $field['required'] . $field['placeholder'] ?>>
    255                         <?php
    256                         echo ob_get_clean();
    257                         break;
    258                     case 'textarea':
    259                         ob_start();
    260                         ?>
    261                         <textarea name="<?php echo esc_attr( $field['id'] ) ?>" id="<?php echo esc_attr( $field['id'] ) ?>" rows="5"
    262                                   cols="<?php echo esc_attr( $field['size'] ) ?>" <?php echo $field['required'] . $field['placeholder'] ?>><?php echo esc_textarea( $field['value'] ) ?></textarea>
    263                         <?php
    264                         echo ob_get_clean();
    265                         break;
    266                     case 'editor':
    267                         $field['settings'] = isset( $field['settings'] )
    268                             ? $field['settings']
    269                             : array(
    270                                 'textarea_rows' => 8,
    271                                 'quicktags'     => false,
    272                                 'media_buttons' => false
    273                             );
    274                         ob_start();
    275                         wp_editor( $field['value'], $field['id'], $field['settings'] );
    276                         echo ob_get_clean();
    277                         break;
    278                     case 'select':
    279                     case 'select2':
    280 
    281                         $field['options'] = isset( $field['options'] ) ? $field['options'] : array();
    282                         $field['multiple'] = isset( $field['multiple'] ) ? ' multiple="multiple"' : '';
    283                         $css_class         = ( $field['type'] == 'select2' ) ? 'wc-enhanced-select' : '';
    284 
    285                         ob_start();
    286                         ?>
    287                         <select name="<?php echo esc_attr( $field['id'] ) ?>" id="<?php echo esc_attr( $field['id'] ) ?>"
    288                                 class="<?php echo esc_attr( $css_class ) ?>" <?php echo $field['multiple'] ?>>
    289                             <?php
    290                             foreach ( $field['options'] as $key => $option ) {
    291                                 echo '<option' . selected( $field['value'], $key, false ) . ' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
    292                             }
    293                             ?>
    294                         </select>
    295                         <?php
    296                         echo ob_get_clean();
    297                         break;
    298                     case 'image':
    299                         ob_start();
    300                         ?>
    301                         <div class="meta-image-field-wrapper">
    302                             <div class="image-preview">
    303                                 <img data-placeholder="<?php echo esc_url( self::placeholder_img_src() ); ?>"
    304                                      src="<?php echo esc_url( self::get_img_src( $field['value'] ) ); ?>"
    305                                      width="60px" height="60px" />
    306                             </div>
    307                             <div class="button-wrapper">
    308                                 <input type="hidden" id="<?php echo esc_attr( $field['id'] ) ?>"
    309                                        name="<?php echo esc_attr( $field['id'] ) ?>"
    310                                        value="<?php echo esc_attr( $field['value'] ) ?>" />
    311                                 <button type="button"
    312                                         class="wvs_upload_image_button button button-primary button-small"><?php esc_html_e( 'Upload / Add image', 'woo-variation-swatches' ); ?></button>
    313                                 <button type="button"
    314                                         style="<?php echo( empty( $field['value'] ) ? 'display:none' : '' ) ?>"
    315                                         class="wvs_remove_image_button button button-danger button-small"><?php esc_html_e( 'Remove image', 'woo-variation-swatches' ); ?></button>
    316                             </div>
    317                         </div>
    318                         <?php
    319                         echo ob_get_clean();
    320                         break;
    321                     case 'checkbox':
    322 
    323                         ob_start();
    324                         ?>
    325                         <label for="<?php echo esc_attr( $field['id'] ) ?>">
    326 
    327                             <input name="<?php echo esc_attr( $field['id'] ) ?>" id="<?php echo esc_attr( $field['id'] ) ?>"
    328                                 <?php checked( $field['value'], 'yes' ) ?>
    329                                    type="<?php echo esc_attr( $field['type'] ) ?>"
    330                                    value="yes" <?php echo $field['required'] . $field['placeholder'] ?>>
    331 
    332                             <?php echo esc_html( $field['label'] ) ?></label>
    333                         <?php
    334                         echo ob_get_clean();
    335                         break;
    336                     default:
    337                         do_action( 'woo_variation_swatches_term_meta_field', $field, $term );
    338                         break;
    339 
    340                 }
    341                 self::field_end( $field, $term );
    342 
    343             }
    344         }
    345 
    346         private static function field_start( $field, $term ) {
    347             // Example:
    348             // http://emranahmed.github.io/Form-Field-Dependency/
    349             /*'dependency' => array(
    350                 array( '#show_tooltip' => array( 'type' => 'equal', 'value' => 'yes' ) )
    351             )*/
    352 
    353             $depends = empty( $field['dependency'] ) ? '' : "data-gwp_dependency='" . wc_esc_json( wp_json_encode( $field['dependency'] ) ) . "'";
    354 
    355             ob_start();
    356             if ( ! $term ) {
    357                 ?>
    358                 <div <?php echo $depends ?> class="form-field <?php echo esc_attr( $field['id'] ) ?> <?php echo empty( $field['required'] ) ? '' : 'form-required' ?>">
    359                 <?php if ( $field['type'] !== 'checkbox' ) { ?>
    360                     <label for="<?php echo esc_attr( $field['id'] ) ?>"><?php echo $field['label'] ?></label>
    361                     <?php
    362                 }
    363             } else {
    364                 ?>
    365                 <tr <?php echo $depends ?> class="form-field  <?php echo esc_attr( $field['id'] ) ?> <?php echo empty( $field['required'] ) ? '' : 'form-required' ?>">
    366                 <th scope="row">
    367                     <label for="<?php echo esc_attr( $field['id'] ) ?>"><?php echo $field['label'] ?></label>
    368                 </th>
    369                 <td>
    370                 <?php
    371             }
    372             echo ob_get_clean();
    373         }
    374 
    375         private static function get_img_src( $thumbnail_id = false ) {
    376             if ( ! empty( $thumbnail_id ) ) {
    377                 $image = wp_get_attachment_thumb_url( $thumbnail_id );
    378             } else {
    379                 $image = self::placeholder_img_src();
    380             }
    381 
    382             return $image;
    383         }
    384 
    385         public static function placeholder_img_src() {
    386             return woo_variation_swatches()->images_url( '/placeholder.png' );
    387         }
    388 
    389         private static function field_end( $field, $term ) {
    390 
    391             ob_start();
    392             if ( ! $term ) {
    393                 ?>
    394                 <p><?php echo wp_kses_post( $field['desc'] ) ?></p>
    395                 </div>
    396                 <?php
    397             } else {
    398                 ?>
    399                 <p class="description"><?php echo wp_kses_post( $field['desc'] ) ?></p></td>
    400                 </tr>
    401                 <?php
    402             }
    403             echo ob_get_clean();
    404         }
    405 
    406         public function edit( $term ) {
    407             $this->generate_fields( $term );
    408         }
    409     }
    410 endif;
     329                                <input name="<?php echo esc_attr( $field[ 'id' ] ) ?>" id="<?php echo esc_attr( $field[ 'id' ] ) ?>"
     330                                    <?php checked( $field[ 'value' ], 'yes' ) ?>
     331                                       type="<?php echo esc_attr( $field[ 'type' ] ) ?>"
     332                                       value="yes" <?php echo $field[ 'required' ] . $field[ 'placeholder' ] ?>>
     333                               
     334                                <?php echo esc_html( $field[ 'label' ] ) ?></label>
     335                            <?php
     336                            echo ob_get_clean();
     337                            break;
     338                        default:
     339                            do_action( 'woo_variation_swatches_term_meta_field', $field, $term );
     340                            break;
     341                       
     342                    }
     343                    self::field_end( $field, $term );
     344                   
     345                }
     346            }
     347           
     348            private static function field_start( $field, $term ) {
     349                // Example:
     350                // http://emranahmed.github.io/Form-Field-Dependency/
     351                /*'dependency' => array(
     352                    array( '#show_tooltip' => array( 'type' => 'equal', 'value' => 'yes' ) )
     353                )*/
     354               
     355                $depends = empty( $field[ 'dependency' ] ) ? '' : "data-gwp_dependency='" . wc_esc_json( wp_json_encode( $field[ 'dependency' ] ) ) . "'";
     356               
     357                ob_start();
     358                if ( ! $term ) {
     359                    ?>
     360                    <div <?php echo $depends ?> class="form-field <?php echo esc_attr( $field[ 'id' ] ) ?> <?php echo empty( $field[ 'required' ] ) ? '' : 'form-required' ?>">
     361                    <?php if ( $field[ 'type' ] !== 'checkbox' ) { ?>
     362                        <label for="<?php echo esc_attr( $field[ 'id' ] ) ?>"><?php echo $field[ 'label' ] ?></label>
     363                        <?php
     364                    }
     365                } else {
     366                    ?>
     367                    <tr <?php echo $depends ?> class="form-field  <?php echo esc_attr( $field[ 'id' ] ) ?> <?php echo empty( $field[ 'required' ] ) ? '' : 'form-required' ?>">
     368                    <th scope="row">
     369                        <label for="<?php echo esc_attr( $field[ 'id' ] ) ?>"><?php echo $field[ 'label' ] ?></label>
     370                    </th>
     371                    <td>
     372                    <?php
     373                }
     374                echo ob_get_clean();
     375            }
     376           
     377            private static function get_img_src( $thumbnail_id = false ) {
     378                if ( ! empty( $thumbnail_id ) ) {
     379                    $image = wp_get_attachment_thumb_url( $thumbnail_id );
     380                } else {
     381                    $image = self::placeholder_img_src();
     382                }
     383               
     384                return $image;
     385            }
     386           
     387            public static function placeholder_img_src() {
     388                return woo_variation_swatches()->images_url( '/placeholder.png' );
     389            }
     390           
     391            private static function field_end( $field, $term ) {
     392               
     393                ob_start();
     394                if ( ! $term ) {
     395                    ?>
     396                    <p><?php echo wp_kses_post( $field[ 'desc' ] ) ?></p>
     397                    </div>
     398                    <?php
     399                } else {
     400                    ?>
     401                    <p class="description"><?php echo wp_kses_post( $field[ 'desc' ] ) ?></p></td>
     402                    </tr>
     403                    <?php
     404                }
     405                echo ob_get_clean();
     406            }
     407           
     408            public function edit( $term ) {
     409                $this->generate_fields( $term );
     410            }
     411        }
     412    endif;
  • woo-variation-swatches/trunk/includes/getwooplugins/class-getwooplugins-plugin-deactivate-feedback.php

    r2850234 r3075625  
    6666
    6767        public function dialog() {
    68 
    69             if ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ) {
     68           
     69            $screen    = get_current_screen();
     70            $screen_id = $screen ? $screen->id : '';
     71
     72            if ( in_array( $screen_id, array( 'plugins', 'plugins-network' ), true ) ) {
    7073
    7174                $deactivate_reasons = $this->reasons();
  • woo-variation-swatches/trunk/languages/woo-variation-swatches.pot

    r3021867 r3075625  
    88"Content-Transfer-Encoding: 8bit\n"
    99"Language-Team: Emran Ahmed <emran.bd.08@gmail.com>\n"
    10 "POT-Creation-Date: 2024-01-15 11:59+0000\n"
     10"POT-Creation-Date: 2024-04-23 09:54+0000\n"
    1111"X-Poedit-Basepath: ..\n"
    1212"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
     
    706706msgstr ""
    707707
    708 #: ../includes/class-woo-variation-swatches-term-meta.php:312
     708#: ../includes/class-woo-variation-swatches-term-meta.php:314
    709709msgid "Upload / Add image"
    710710msgstr ""
    711711
    712 #: ../includes/class-woo-variation-swatches-term-meta.php:315
     712#: ../includes/class-woo-variation-swatches-term-meta.php:317
    713713msgid "Remove image"
    714714msgstr ""
     
    10151015msgstr ""
    10161016
    1017 #: ../woo-variation-swatches.php:37
     1017#: ../woo-variation-swatches.php:38
    10181018msgid "WooCommerce"
    10191019msgstr ""
    10201020
    1021 #: ../woo-variation-swatches.php:48
     1021#: ../woo-variation-swatches.php:49
    10221022msgid "<strong>Variation Swatches for WooCommerce</strong> is an add-on of "
    10231023msgstr ""
  • woo-variation-swatches/trunk/uninstall.php

    r2850234 r3075625  
    55
    66// If uninstall not called from WordPress exit
    7 defined( 'WP_UNINSTALL_PLUGIN' ) or die( 'Keep Silent' );
     7defined( 'WP_UNINSTALL_PLUGIN' ) || die( 'Keep Silent' );
    88
    99global $wpdb;
  • woo-variation-swatches/trunk/woo-variation-swatches.php

    r3021867 r3075625  
    55     * Description: Beautiful colors, images and buttons variation swatches for woocommerce product attributes. Requires WooCommerce 5.6+
    66     * Author: Emran Ahmed
    7      * Version: 2.0.30
     7     * Version: 2.0.31
    88     * Domain Path: /languages
    99     * Requires PHP: 7.4
    1010     * Requires at least: 5.6
    11      * Tested up to: 6.4
     11     * Tested up to: 6.5
    1212     * WC requires at least: 5.6
    13      * WC tested up to: 8.4
     13     * WC tested up to: 8.8
    1414     * Text Domain: woo-variation-swatches
    1515     * Author URI: https://getwooplugins.com/
     16     * Requires Plugins: woocommerce
    1617     */
    1718   
     
    1920   
    2021    if ( ! defined( 'WOO_VARIATION_SWATCHES_PLUGIN_VERSION' ) ) {
    21         define( 'WOO_VARIATION_SWATCHES_PLUGIN_VERSION', '2.0.30' );
     22        define( 'WOO_VARIATION_SWATCHES_PLUGIN_VERSION', '2.0.31' );
    2223    }
    2324   
Note: See TracChangeset for help on using the changeset viewer.