Changeset 3112271
- Timestamp:
- 07/04/2024 08:55:45 AM (21 months ago)
- Location:
- setary
- Files:
-
- 2 added
- 14 edited
- 1 copied
-
tags/1.13.0 (copied) (copied from setary/trunk)
-
tags/1.13.0/README.md (modified) (2 diffs)
-
tags/1.13.0/inc/bootstrap.php (modified) (2 diffs)
-
tags/1.13.0/inc/class-meta-attributes.php (modified) (1 diff)
-
tags/1.13.0/inc/class-product-controller.php (modified) (2 diffs)
-
tags/1.13.0/inc/class-product-tools.php (modified) (4 diffs)
-
tags/1.13.0/inc/class-products-variations.php (added)
-
tags/1.13.0/inc/class-products-with-variations.php (modified) (7 diffs)
-
tags/1.13.0/setary.php (modified) (3 diffs)
-
trunk/README.md (modified) (2 diffs)
-
trunk/inc/bootstrap.php (modified) (2 diffs)
-
trunk/inc/class-meta-attributes.php (modified) (1 diff)
-
trunk/inc/class-product-controller.php (modified) (2 diffs)
-
trunk/inc/class-product-tools.php (modified) (4 diffs)
-
trunk/inc/class-products-variations.php (added)
-
trunk/inc/class-products-with-variations.php (modified) (7 diffs)
-
trunk/setary.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
setary/tags/1.13.0/README.md
r3095206 r3112271 5 5 Tested up to: 6.5.3 6 6 Requires PHP: 7.1 7 Stable tag: 1.1 2.17 Stable tag: 1.13.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 90 90 91 91 == 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 92 96 93 97 = v1.12.1 (2024-05-30) = -
setary/tags/1.13.0/inc/bootstrap.php
r3017317 r3112271 26 26 } 27 27 28 function yoast_plugin_active() { 29 return class_exists( '\Yoast_WooCommerce_SEO' ); 30 } 31 28 32 /** 29 33 * Delcare HPOS compatibility. … … 47 51 // https://setary.wp.loc/wp-json/wc/setary/products/. 48 52 'products' => __NAMESPACE__ . '\\Products_With_Variations', 53 'product-variations' => __NAMESPACE__ . '\\Products_Variations', 49 54 'upload_image' => __NAMESPACE__ . '\\Upload_Image', 50 55 'media_list' => __NAMESPACE__ . '\\Media_List', -
setary/tags/1.13.0/inc/class-meta-attributes.php
r2979509 r3112271 21 21 $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); 22 22 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; 24 45 } 25 46 -
setary/tags/1.13.0/inc/class-product-controller.php
r3093835 r3112271 148 148 */ 149 149 public function pre_insert_product_object( $product, $request, $creating ) { 150 151 150 if ( ! empty( $request['type'] ) && empty( $request['product_type'] ) ) { 152 151 $request['product_type'] = $request['type']; … … 258 257 259 258 // These keys are not saved by default, so let's process them here. 260 261 259 $keys = [ 262 260 'width', -
setary/tags/1.13.0/inc/class-product-tools.php
r3028308 r3112271 71 71 $wp_rest_server = rest_get_server(); 72 72 73 $request->set_route('/wc/ v3/products');73 $request->set_route('/wc/setary/products'); 74 74 75 75 $new_id = ! empty($request['id']) && strpos($request['id'], 'new') === 0 ? $request['id'] : false; … … 90 90 91 91 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'); 93 93 $request->offsetUnset('parent_id'); 94 94 } … … 102 102 if( $product->is_type('variation') ) { 103 103 $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(); 105 105 $request->set_route($prefix); 106 106 } else { 107 $prefix = '/wc/ v3/products/' . $product->get_id();107 $prefix = '/wc/setary/products/' . $product->get_id(); 108 108 $request->set_route($prefix); 109 109 $request->set_method('PUT'); … … 117 117 118 118 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()); 120 120 $request->offsetUnset('id'); 121 121 $request->offsetUnset('parent_id'); 122 122 } else { 123 $request->set_route('/wc/ v3/products/' . $id);123 $request->set_route('/wc/setary/products/' . $id); 124 124 $request->offsetUnset('id'); 125 125 $request->offsetUnset('parent_id'); -
setary/tags/1.13.0/inc/class-products-with-variations.php
r3095206 r3112271 75 75 ] 76 76 ); 77 78 parent::register_routes(); 77 79 } 78 80 … … 186 188 } 187 189 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 188 261 /** 189 262 * Remove extra fields, it reduces execution time (-80%). … … 193 266 * @return array 194 267 */ 195 protected function get_product_data( $product, $context = 'view' ) {268 protected function get_product_data( $product, $context = 'view', $requestOriginal = false ) { 196 269 // We want the 'edit' versions of each field. 197 270 $context = 'edit'; … … 211 284 add_filter( 'woocommerce_product_related_posts_shuffle', '__return_false' ); 212 285 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; 214 301 } 215 302 … … 438 525 } 439 526 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 440 541 return apply_filters( 'setary_filter_response_by_context', $item, $data, $context ); 441 542 } … … 481 582 482 583 $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 } 483 589 484 590 if( ! empty( $filter['taxonomy'] ) && 'query' === $filter['mode'] ) { … … 603 709 $field = $numeric_post_fields[ $key ]; 604 710 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 ) { 606 712 if( in_array( 'variation', $filter['query'], true ) ) { 607 713 $query_args['post_type'] = [ 'product_variation' ]; -
setary/tags/1.13.0/setary.php
r3095206 r3112271 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1.1 2.113 * Version: 1.13.0 14 14 * WC requires at least: 6.0.0 15 15 * WC tested up to: 8.9.1 … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1.1 2.1' );25 define( 'SETARY_VERSION', '1.13.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' ); … … 45 45 include_once __DIR__ . '/inc/class-product-controller.php'; 46 46 include_once __DIR__ . '/inc/class-products-with-variations.php'; 47 include_once __DIR__ . '/inc/class-products-variations.php'; 47 48 include_once __DIR__ . '/inc/class-upload-image.php'; 48 49 include_once __DIR__ . '/inc/class-media-list.php'; -
setary/trunk/README.md
r3095206 r3112271 5 5 Tested up to: 6.5.3 6 6 Requires PHP: 7.1 7 Stable tag: 1.1 2.17 Stable tag: 1.13.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 90 90 91 91 == 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 92 96 93 97 = v1.12.1 (2024-05-30) = -
setary/trunk/inc/bootstrap.php
r3017317 r3112271 26 26 } 27 27 28 function yoast_plugin_active() { 29 return class_exists( '\Yoast_WooCommerce_SEO' ); 30 } 31 28 32 /** 29 33 * Delcare HPOS compatibility. … … 47 51 // https://setary.wp.loc/wp-json/wc/setary/products/. 48 52 'products' => __NAMESPACE__ . '\\Products_With_Variations', 53 'product-variations' => __NAMESPACE__ . '\\Products_Variations', 49 54 'upload_image' => __NAMESPACE__ . '\\Upload_Image', 50 55 'media_list' => __NAMESPACE__ . '\\Media_List', -
setary/trunk/inc/class-meta-attributes.php
r2979509 r3112271 21 21 $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); 22 22 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; 24 45 } 25 46 -
setary/trunk/inc/class-product-controller.php
r3093835 r3112271 148 148 */ 149 149 public function pre_insert_product_object( $product, $request, $creating ) { 150 151 150 if ( ! empty( $request['type'] ) && empty( $request['product_type'] ) ) { 152 151 $request['product_type'] = $request['type']; … … 258 257 259 258 // These keys are not saved by default, so let's process them here. 260 261 259 $keys = [ 262 260 'width', -
setary/trunk/inc/class-product-tools.php
r3028308 r3112271 71 71 $wp_rest_server = rest_get_server(); 72 72 73 $request->set_route('/wc/ v3/products');73 $request->set_route('/wc/setary/products'); 74 74 75 75 $new_id = ! empty($request['id']) && strpos($request['id'], 'new') === 0 ? $request['id'] : false; … … 90 90 91 91 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'); 93 93 $request->offsetUnset('parent_id'); 94 94 } … … 102 102 if( $product->is_type('variation') ) { 103 103 $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(); 105 105 $request->set_route($prefix); 106 106 } else { 107 $prefix = '/wc/ v3/products/' . $product->get_id();107 $prefix = '/wc/setary/products/' . $product->get_id(); 108 108 $request->set_route($prefix); 109 109 $request->set_method('PUT'); … … 117 117 118 118 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()); 120 120 $request->offsetUnset('id'); 121 121 $request->offsetUnset('parent_id'); 122 122 } else { 123 $request->set_route('/wc/ v3/products/' . $id);123 $request->set_route('/wc/setary/products/' . $id); 124 124 $request->offsetUnset('id'); 125 125 $request->offsetUnset('parent_id'); -
setary/trunk/inc/class-products-with-variations.php
r3095206 r3112271 75 75 ] 76 76 ); 77 78 parent::register_routes(); 77 79 } 78 80 … … 186 188 } 187 189 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 188 261 /** 189 262 * Remove extra fields, it reduces execution time (-80%). … … 193 266 * @return array 194 267 */ 195 protected function get_product_data( $product, $context = 'view' ) {268 protected function get_product_data( $product, $context = 'view', $requestOriginal = false ) { 196 269 // We want the 'edit' versions of each field. 197 270 $context = 'edit'; … … 211 284 add_filter( 'woocommerce_product_related_posts_shuffle', '__return_false' ); 212 285 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; 214 301 } 215 302 … … 438 525 } 439 526 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 440 541 return apply_filters( 'setary_filter_response_by_context', $item, $data, $context ); 441 542 } … … 481 582 482 583 $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 } 483 589 484 590 if( ! empty( $filter['taxonomy'] ) && 'query' === $filter['mode'] ) { … … 603 709 $field = $numeric_post_fields[ $key ]; 604 710 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 ) { 606 712 if( in_array( 'variation', $filter['query'], true ) ) { 607 713 $query_args['post_type'] = [ 'product_variation' ]; -
setary/trunk/setary.php
r3095206 r3112271 11 11 * Author URI: https://setary.com/ 12 12 * 13 * Version: 1.1 2.113 * Version: 1.13.0 14 14 * WC requires at least: 6.0.0 15 15 * WC tested up to: 8.9.1 … … 23 23 define( 'SETARY_PATH', \plugin_dir_path( __FILE__ ) ); 24 24 define( 'SETARY_URL', \plugins_url( '/', __FILE__ ) ); 25 define( 'SETARY_VERSION', '1.1 2.1' );25 define( 'SETARY_VERSION', '1.13.0' ); 26 26 define( 'SETARY_SITE_URL', 'https://setary.com/' ); 27 27 define( 'SETARY_APP_URL', 'https://setary.com/app/' ); … … 45 45 include_once __DIR__ . '/inc/class-product-controller.php'; 46 46 include_once __DIR__ . '/inc/class-products-with-variations.php'; 47 include_once __DIR__ . '/inc/class-products-variations.php'; 47 48 include_once __DIR__ . '/inc/class-upload-image.php'; 48 49 include_once __DIR__ . '/inc/class-media-list.php';
Note: See TracChangeset
for help on using the changeset viewer.