Plugin Directory

Changeset 3112271


Ignore:
Timestamp:
07/04/2024 08:55:45 AM (21 months ago)
Author:
setaryapp
Message:

Update to version 1.13.0 from GitHub

Location:
setary
Files:
2 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • setary/tags/1.13.0/README.md

    r3095206 r3112271  
    55Tested up to: 6.5.3
    66Requires PHP: 7.1
    7 Stable tag: 1.12.1
     7Stable tag: 1.13.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    9090
    9191== Changelog ==
     92
     93= v1.13.0 (2024-07-04) =
     94* [fix] Clashing of core and meta fields
     95* [update] Allow extension of Yoast SEO fields
    9296
    9397= v1.12.1 (2024-05-30) =
  • setary/tags/1.13.0/inc/bootstrap.php

    r3017317 r3112271  
    2626}
    2727
     28function yoast_plugin_active() {
     29    return class_exists( '\Yoast_WooCommerce_SEO' );
     30}
     31
    2832/**
    2933 * Delcare HPOS compatibility.
     
    4751        // https://setary.wp.loc/wp-json/wc/setary/products/.
    4852        'products'        => __NAMESPACE__ . '\\Products_With_Variations',
     53        'product-variations' => __NAMESPACE__ . '\\Products_Variations',
    4954        'upload_image'    => __NAMESPACE__ . '\\Upload_Image',
    5055        'media_list'      => __NAMESPACE__ . '\\Media_List',
  • setary/tags/1.13.0/inc/class-meta-attributes.php

    r2979509 r3112271  
    2121        $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
    2222
    23         return array_values( $meta_data );
     23        if( yoast_plugin_active() ) {
     24            $yoast_global_identifier_types = [
     25                'gtin8',
     26                'gtin12',
     27                'gtin13',
     28                'gtin14',
     29                'mpn',
     30            ];
     31
     32            $yoast_global_identifier_types = array_map( fn($key) => '_yoast_seo_global_identifier_' . $key, $yoast_global_identifier_types );
     33
     34            $meta_data = array_merge( $meta_data, $yoast_global_identifier_types );
     35        }
     36
     37        $meta_data = array_values( $meta_data );
     38
     39        if( in_array( 'product_type', $meta_data, true ) ) {
     40            $meta_data = array_filter( $meta_data, fn($key) => $key !== 'product_type' );
     41            $meta_data[] = '___product_type';
     42        }
     43
     44        return $meta_data;
    2445    }
    2546
  • setary/tags/1.13.0/inc/class-product-controller.php

    r3093835 r3112271  
    148148     */
    149149    public function pre_insert_product_object( $product, $request, $creating ) {
    150        
    151150        if ( ! empty( $request['type'] ) && empty( $request['product_type'] ) ) {
    152151            $request['product_type'] = $request['type'];
     
    258257
    259258        // These keys are not saved by default, so let's process them here.
    260 
    261259        $keys = [
    262260            'width',
  • setary/tags/1.13.0/inc/class-product-tools.php

    r3028308 r3112271  
    7171        $wp_rest_server = rest_get_server();
    7272
    73         $request->set_route('/wc/v3/products');
     73        $request->set_route('/wc/setary/products');
    7474
    7575        $new_id = ! empty($request['id']) && strpos($request['id'], 'new') === 0 ? $request['id'] : false;
     
    9090
    9191        if( ! empty($request['parent_id']) ) {
    92             $request->set_route('/wc/v3/products/' . $request['parent_id'] . '/variations');
     92            $request->set_route('/wc/setary/product-variations/' . $request['parent_id'] . '/variations');
    9393            $request->offsetUnset('parent_id');
    9494        }
     
    102102                if( $product->is_type('variation') ) {
    103103                    $request->set_param('id', $product->get_id());
    104                     $prefix = '/wc/v3/products/' . $product->get_parent_id() . '/variations/' . $product->get_id();
     104                    $prefix = '/wc/setary/product-variations/' . $product->get_parent_id() . '/variations/' . $product->get_id();
    105105                    $request->set_route($prefix);
    106106                } else {
    107                     $prefix = '/wc/v3/products/' . $product->get_id();
     107                    $prefix = '/wc/setary/products/' . $product->get_id();
    108108                    $request->set_route($prefix);
    109109                    $request->set_method('PUT');
     
    117117
    118118                if( $product->is_type('variation') ) {
    119                     $request->set_route('/wc/v3/products/' . $product->get_parent_id() . '/variations/' . $product->get_id());
     119                    $request->set_route('/wc/setary/product-variations/' . $product->get_parent_id() . '/variations/' . $product->get_id());
    120120                    $request->offsetUnset('id');
    121121                    $request->offsetUnset('parent_id');
    122122                } else {
    123                     $request->set_route('/wc/v3/products/' . $id);
     123                    $request->set_route('/wc/setary/products/' . $id);
    124124                    $request->offsetUnset('id');
    125125                    $request->offsetUnset('parent_id');
  • setary/tags/1.13.0/inc/class-products-with-variations.php

    r3095206 r3112271  
    7575            ]
    7676        );
     77
     78        parent::register_routes();
    7779    }
    7880
     
    186188    }
    187189
     190   
     191    /**
     192     * Prepare a single product for create or update.
     193     *
     194     * @param  WP_REST_Request $request Request object.
     195     * @param  bool            $creating If is creating a new object.
     196     * @return WP_Error|WC_Data
     197     */
     198    protected function prepare_object_for_database( $request, $creating = false ) {
     199        $meta_data = $request->get_param('meta_data');
     200        $meta_data_updated = false;
     201
     202        $meta_to_save = [];
     203
     204        foreach( $meta_data as $index => $meta ) {
     205            $key = $meta['key'];
     206            $value = $meta['value'];
     207           
     208            if( strpos( $key, '___' ) === 0 ) {
     209                $meta_key = substr( $key, 3 );
     210                $meta_to_save[ $meta_key ] = $value;
     211                unset( $meta_data[ $index ] );
     212                $meta_data_updated = true;
     213            }
     214
     215            if( yoast_plugin_active() )  {
     216                if( strpos($key, '_yoast_seo_global_identifier_') !== 0 ) {
     217                    continue;
     218                }
     219
     220                $meta_to_save[ $key ] = $value;
     221                unset( $meta_data[ $index ] );
     222                $meta_data_updated = true;
     223            }
     224        }
     225
     226        if( $meta_data_updated ) {
     227            $request->set_param( 'meta_data', $meta_data );
     228        }
     229
     230        $product = parent::prepare_object_for_database( $request, $creating );
     231
     232        foreach( $meta_to_save as $meta_key => $meta_value ) {
     233            if( yoast_plugin_active() )  {
     234                $is_variation = $product->is_type( 'variation' );
     235
     236                $meta_key_yoast = ! $is_variation ? 'wpseo_global_identifier_values' : 'wpseo_variation_global_identifiers_values';
     237
     238                $global_identifier_values = get_post_meta( $product->get_id(), $meta_key_yoast, true );
     239
     240                if( strpos($meta_key, '_yoast_seo_global_identifier_') === 0 ) {
     241                    $indentifier_key = str_replace( '_yoast_seo_global_identifier_', '', $key );
     242
     243                    if( ! is_array( $global_identifier_values ) ) {
     244                        $global_identifier_values = [];
     245                    }
     246   
     247                    $global_identifier_values[$indentifier_key] = $value;
     248                   
     249                    update_post_meta( $product->get_id(), $meta_key_yoast, $global_identifier_values );
     250   
     251                    continue;   
     252                }
     253            }
     254
     255            update_post_meta( $product->get_id(), $meta_key, $meta_value );
     256        }
     257
     258        return $product;
     259    }
     260
    188261    /**
    189262     * Remove extra fields, it reduces execution time (-80%).
     
    193266     * @return array
    194267     */
    195     protected function get_product_data( $product, $context = 'view' ) {
     268    protected function get_product_data( $product, $context = 'view', $requestOriginal  = false ) {
    196269        // We want the 'edit' versions of each field.
    197270        $context = 'edit';
     
    211284        add_filter( 'woocommerce_product_related_posts_shuffle', '__return_false' );
    212285
    213         return parent::get_product_data( $product, $context, $request );
     286        $item = parent::get_product_data( $product, $context, $request );
     287   
     288        if( $requestOriginal && is_object( $requestOriginal ) ) {
     289            $fields = $requestOriginal->get_param( 'fields' );
     290
     291            foreach ( $fields as $field ) {
     292                if( strpos( $field, '___' ) === 0 ) {
     293                    $meta_key = substr( $field, 3 );
     294                    $value = get_post_meta( $item['id'], $meta_key, true );
     295                    $item[$field] = $value;
     296                }
     297            }
     298        }
     299
     300        return $item;
    214301    }
    215302
     
    438525        }
    439526
     527        if( yoast_plugin_active() ) {
     528            $is_variation = $item['product_type'] === 'variation';
     529
     530            $meta_key = ! $is_variation ? 'wpseo_global_identifier_values' : 'wpseo_variation_global_identifiers_values';
     531
     532            $variation_global_ids  = get_post_meta( $item['id'], $meta_key, true );
     533
     534            if( is_array($variation_global_ids) ) {
     535                foreach( $variation_global_ids as $key => $value ) {
     536                    $item[ '_yoast_seo_global_identifier_' . $key ] = $value;
     537                }
     538            }
     539        }
     540
    440541        return apply_filters( 'setary_filter_response_by_context', $item, $data, $context );
    441542    }
     
    481582
    482583            $key = isset($filter['filterData']) && !empty($filter['filterData']) ? $filter['filterData'] : $filter['data'];
     584            $originalKey = $key;
     585
     586            if( strpos( $key, '___' ) === 0 ) {
     587                $key = substr( $key, 3 );
     588            }
    483589
    484590            if( ! empty( $filter['taxonomy'] ) && 'query' === $filter['mode'] ) {
     
    603709                $field = $numeric_post_fields[ $key ];
    604710                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    605             } else if( 'product_type' === $key ) {
     711            } else if( 'product_type' === $key && $originalKey === $key ) {
    606712                if( in_array( 'variation', $filter['query'], true ) ) {
    607713                    $query_args['post_type'] = [ 'product_variation' ];
  • setary/tags/1.13.0/setary.php

    r3095206 r3112271  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.12.1
     13 * Version:              1.13.0
    1414 * WC requires at least: 6.0.0
    1515 * WC tested up to:      8.9.1
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.12.1' );
     25define( 'SETARY_VERSION', '1.13.0' );
    2626define( 'SETARY_SITE_URL', 'https://setary.com/' );
    2727define( 'SETARY_APP_URL', 'https://setary.com/app/' );
     
    4545    include_once __DIR__ . '/inc/class-product-controller.php';
    4646    include_once __DIR__ . '/inc/class-products-with-variations.php';
     47    include_once __DIR__ . '/inc/class-products-variations.php';
    4748    include_once __DIR__ . '/inc/class-upload-image.php';
    4849    include_once __DIR__ . '/inc/class-media-list.php';
  • setary/trunk/README.md

    r3095206 r3112271  
    55Tested up to: 6.5.3
    66Requires PHP: 7.1
    7 Stable tag: 1.12.1
     7Stable tag: 1.13.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    9090
    9191== Changelog ==
     92
     93= v1.13.0 (2024-07-04) =
     94* [fix] Clashing of core and meta fields
     95* [update] Allow extension of Yoast SEO fields
    9296
    9397= v1.12.1 (2024-05-30) =
  • setary/trunk/inc/bootstrap.php

    r3017317 r3112271  
    2626}
    2727
     28function yoast_plugin_active() {
     29    return class_exists( '\Yoast_WooCommerce_SEO' );
     30}
     31
    2832/**
    2933 * Delcare HPOS compatibility.
     
    4751        // https://setary.wp.loc/wp-json/wc/setary/products/.
    4852        'products'        => __NAMESPACE__ . '\\Products_With_Variations',
     53        'product-variations' => __NAMESPACE__ . '\\Products_Variations',
    4954        'upload_image'    => __NAMESPACE__ . '\\Upload_Image',
    5055        'media_list'      => __NAMESPACE__ . '\\Media_List',
  • setary/trunk/inc/class-meta-attributes.php

    r2979509 r3112271  
    2121        $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
    2222
    23         return array_values( $meta_data );
     23        if( yoast_plugin_active() ) {
     24            $yoast_global_identifier_types = [
     25                'gtin8',
     26                'gtin12',
     27                'gtin13',
     28                'gtin14',
     29                'mpn',
     30            ];
     31
     32            $yoast_global_identifier_types = array_map( fn($key) => '_yoast_seo_global_identifier_' . $key, $yoast_global_identifier_types );
     33
     34            $meta_data = array_merge( $meta_data, $yoast_global_identifier_types );
     35        }
     36
     37        $meta_data = array_values( $meta_data );
     38
     39        if( in_array( 'product_type', $meta_data, true ) ) {
     40            $meta_data = array_filter( $meta_data, fn($key) => $key !== 'product_type' );
     41            $meta_data[] = '___product_type';
     42        }
     43
     44        return $meta_data;
    2445    }
    2546
  • setary/trunk/inc/class-product-controller.php

    r3093835 r3112271  
    148148     */
    149149    public function pre_insert_product_object( $product, $request, $creating ) {
    150        
    151150        if ( ! empty( $request['type'] ) && empty( $request['product_type'] ) ) {
    152151            $request['product_type'] = $request['type'];
     
    258257
    259258        // These keys are not saved by default, so let's process them here.
    260 
    261259        $keys = [
    262260            'width',
  • setary/trunk/inc/class-product-tools.php

    r3028308 r3112271  
    7171        $wp_rest_server = rest_get_server();
    7272
    73         $request->set_route('/wc/v3/products');
     73        $request->set_route('/wc/setary/products');
    7474
    7575        $new_id = ! empty($request['id']) && strpos($request['id'], 'new') === 0 ? $request['id'] : false;
     
    9090
    9191        if( ! empty($request['parent_id']) ) {
    92             $request->set_route('/wc/v3/products/' . $request['parent_id'] . '/variations');
     92            $request->set_route('/wc/setary/product-variations/' . $request['parent_id'] . '/variations');
    9393            $request->offsetUnset('parent_id');
    9494        }
     
    102102                if( $product->is_type('variation') ) {
    103103                    $request->set_param('id', $product->get_id());
    104                     $prefix = '/wc/v3/products/' . $product->get_parent_id() . '/variations/' . $product->get_id();
     104                    $prefix = '/wc/setary/product-variations/' . $product->get_parent_id() . '/variations/' . $product->get_id();
    105105                    $request->set_route($prefix);
    106106                } else {
    107                     $prefix = '/wc/v3/products/' . $product->get_id();
     107                    $prefix = '/wc/setary/products/' . $product->get_id();
    108108                    $request->set_route($prefix);
    109109                    $request->set_method('PUT');
     
    117117
    118118                if( $product->is_type('variation') ) {
    119                     $request->set_route('/wc/v3/products/' . $product->get_parent_id() . '/variations/' . $product->get_id());
     119                    $request->set_route('/wc/setary/product-variations/' . $product->get_parent_id() . '/variations/' . $product->get_id());
    120120                    $request->offsetUnset('id');
    121121                    $request->offsetUnset('parent_id');
    122122                } else {
    123                     $request->set_route('/wc/v3/products/' . $id);
     123                    $request->set_route('/wc/setary/products/' . $id);
    124124                    $request->offsetUnset('id');
    125125                    $request->offsetUnset('parent_id');
  • setary/trunk/inc/class-products-with-variations.php

    r3095206 r3112271  
    7575            ]
    7676        );
     77
     78        parent::register_routes();
    7779    }
    7880
     
    186188    }
    187189
     190   
     191    /**
     192     * Prepare a single product for create or update.
     193     *
     194     * @param  WP_REST_Request $request Request object.
     195     * @param  bool            $creating If is creating a new object.
     196     * @return WP_Error|WC_Data
     197     */
     198    protected function prepare_object_for_database( $request, $creating = false ) {
     199        $meta_data = $request->get_param('meta_data');
     200        $meta_data_updated = false;
     201
     202        $meta_to_save = [];
     203
     204        foreach( $meta_data as $index => $meta ) {
     205            $key = $meta['key'];
     206            $value = $meta['value'];
     207           
     208            if( strpos( $key, '___' ) === 0 ) {
     209                $meta_key = substr( $key, 3 );
     210                $meta_to_save[ $meta_key ] = $value;
     211                unset( $meta_data[ $index ] );
     212                $meta_data_updated = true;
     213            }
     214
     215            if( yoast_plugin_active() )  {
     216                if( strpos($key, '_yoast_seo_global_identifier_') !== 0 ) {
     217                    continue;
     218                }
     219
     220                $meta_to_save[ $key ] = $value;
     221                unset( $meta_data[ $index ] );
     222                $meta_data_updated = true;
     223            }
     224        }
     225
     226        if( $meta_data_updated ) {
     227            $request->set_param( 'meta_data', $meta_data );
     228        }
     229
     230        $product = parent::prepare_object_for_database( $request, $creating );
     231
     232        foreach( $meta_to_save as $meta_key => $meta_value ) {
     233            if( yoast_plugin_active() )  {
     234                $is_variation = $product->is_type( 'variation' );
     235
     236                $meta_key_yoast = ! $is_variation ? 'wpseo_global_identifier_values' : 'wpseo_variation_global_identifiers_values';
     237
     238                $global_identifier_values = get_post_meta( $product->get_id(), $meta_key_yoast, true );
     239
     240                if( strpos($meta_key, '_yoast_seo_global_identifier_') === 0 ) {
     241                    $indentifier_key = str_replace( '_yoast_seo_global_identifier_', '', $key );
     242
     243                    if( ! is_array( $global_identifier_values ) ) {
     244                        $global_identifier_values = [];
     245                    }
     246   
     247                    $global_identifier_values[$indentifier_key] = $value;
     248                   
     249                    update_post_meta( $product->get_id(), $meta_key_yoast, $global_identifier_values );
     250   
     251                    continue;   
     252                }
     253            }
     254
     255            update_post_meta( $product->get_id(), $meta_key, $meta_value );
     256        }
     257
     258        return $product;
     259    }
     260
    188261    /**
    189262     * Remove extra fields, it reduces execution time (-80%).
     
    193266     * @return array
    194267     */
    195     protected function get_product_data( $product, $context = 'view' ) {
     268    protected function get_product_data( $product, $context = 'view', $requestOriginal  = false ) {
    196269        // We want the 'edit' versions of each field.
    197270        $context = 'edit';
     
    211284        add_filter( 'woocommerce_product_related_posts_shuffle', '__return_false' );
    212285
    213         return parent::get_product_data( $product, $context, $request );
     286        $item = parent::get_product_data( $product, $context, $request );
     287   
     288        if( $requestOriginal && is_object( $requestOriginal ) ) {
     289            $fields = $requestOriginal->get_param( 'fields' );
     290
     291            foreach ( $fields as $field ) {
     292                if( strpos( $field, '___' ) === 0 ) {
     293                    $meta_key = substr( $field, 3 );
     294                    $value = get_post_meta( $item['id'], $meta_key, true );
     295                    $item[$field] = $value;
     296                }
     297            }
     298        }
     299
     300        return $item;
    214301    }
    215302
     
    438525        }
    439526
     527        if( yoast_plugin_active() ) {
     528            $is_variation = $item['product_type'] === 'variation';
     529
     530            $meta_key = ! $is_variation ? 'wpseo_global_identifier_values' : 'wpseo_variation_global_identifiers_values';
     531
     532            $variation_global_ids  = get_post_meta( $item['id'], $meta_key, true );
     533
     534            if( is_array($variation_global_ids) ) {
     535                foreach( $variation_global_ids as $key => $value ) {
     536                    $item[ '_yoast_seo_global_identifier_' . $key ] = $value;
     537                }
     538            }
     539        }
     540
    440541        return apply_filters( 'setary_filter_response_by_context', $item, $data, $context );
    441542    }
     
    481582
    482583            $key = isset($filter['filterData']) && !empty($filter['filterData']) ? $filter['filterData'] : $filter['data'];
     584            $originalKey = $key;
     585
     586            if( strpos( $key, '___' ) === 0 ) {
     587                $key = substr( $key, 3 );
     588            }
    483589
    484590            if( ! empty( $filter['taxonomy'] ) && 'query' === $filter['mode'] ) {
     
    603709                $field = $numeric_post_fields[ $key ];
    604710                add_filter( 'posts_where', [ new FilterByBetween(" AND {$wpdb->prefix}posts.{$field} BETWEEN %d AND %d", array( floatval($filter['from']), floatval($filter['to']) )), 'filter' ]);
    605             } else if( 'product_type' === $key ) {
     711            } else if( 'product_type' === $key && $originalKey === $key ) {
    606712                if( in_array( 'variation', $filter['query'], true ) ) {
    607713                    $query_args['post_type'] = [ 'product_variation' ];
  • setary/trunk/setary.php

    r3095206 r3112271  
    1111 * Author URI:           https://setary.com/
    1212 *
    13  * Version:              1.12.1
     13 * Version:              1.13.0
    1414 * WC requires at least: 6.0.0
    1515 * WC tested up to:      8.9.1
     
    2323define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) );
    2424define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) );
    25 define( 'SETARY_VERSION', '1.12.1' );
     25define( 'SETARY_VERSION', '1.13.0' );
    2626define( 'SETARY_SITE_URL', 'https://setary.com/' );
    2727define( 'SETARY_APP_URL', 'https://setary.com/app/' );
     
    4545    include_once __DIR__ . '/inc/class-product-controller.php';
    4646    include_once __DIR__ . '/inc/class-products-with-variations.php';
     47    include_once __DIR__ . '/inc/class-products-variations.php';
    4748    include_once __DIR__ . '/inc/class-upload-image.php';
    4849    include_once __DIR__ . '/inc/class-media-list.php';
Note: See TracChangeset for help on using the changeset viewer.