* Remove shortcode filter

WC core handles category & attribute IDs as of 3.5

* Bump min requirements to 3.5+
This commit is contained in:
Kelly Dwan 2019-02-22 13:16:46 -05:00 committed by GitHub
parent ae42ecbae3
commit 930602bc8d
3 changed files with 4 additions and 104 deletions

View File

@ -10,9 +10,7 @@ Feature plugin for the Gutenberg Products block.
## Getting started with the development version: ## Getting started with the development version:
1. Make sure you have: 1. Make sure you have WordPress 5.0+ and WooCommerce 3.5.1+
- the latest version of the Gutenberg plugin and WooCommerce 3.3.1+ installed and active
- ***OR*** WordPress 5.0 (beta) and WooCommerce 3.5.1+
2. Get a copy of this plugin using the green "Clone or download" button on the right. 2. Get a copy of this plugin using the green "Clone or download" button on the right.
3. `npm install` to install the dependencies. 3. `npm install` to install the dependencies.
4. `npm run build` (build once) or `npm start` (keep watching for changes) to compile the code. 4. `npm run build` (build once) or `npm start` (keep watching for changes) to compile the code.

View File

@ -42,15 +42,7 @@ We've also improved the category selection filter. If you select two or more cat
= Minimum Requirements = = Minimum Requirements =
* WordPress 4.9.x * WordPress 5.0
* Gutenberg plugin 4.6 or greater
* WooCommerce 3.3.1 or greater
* PHP version 5.2.4 or greater (PHP 7.2 or greater is recommended)
* MySQL version 5.0 or greater (MySQL 5.6 or greater is recommended)
OR
* WordPress 5.0.x
* WooCommerce 3.5.1 or greater * WooCommerce 3.5.1 or greater
* PHP version 5.2.4 or greater (PHP 7.2 or greater is recommended) * PHP version 5.2.4 or greater (PHP 7.2 or greater is recommended)
* MySQL version 5.0 or greater (MySQL 5.6 or greater is recommended) * MySQL version 5.0 or greater (MySQL 5.6 or greater is recommended)

View File

@ -7,8 +7,8 @@
* Author: Automattic * Author: Automattic
* Author URI: https://woocommerce.com * Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block * Text Domain: woo-gutenberg-products-block
* WC requires at least: 3.3 * WC requires at least: 3.5
* WC tested up to: 3.5 * WC tested up to: 3.6
* *
* @package WooCommerce\Blocks * @package WooCommerce\Blocks
*/ */
@ -415,93 +415,3 @@ function wgpb_register_api_routes() {
$attribute_terms = new WGPB_Product_Attribute_Terms_Controller(); $attribute_terms = new WGPB_Product_Attribute_Terms_Controller();
$attribute_terms->register_routes(); $attribute_terms->register_routes();
} }
/**
* Brings some extra required shortcode features from WC core 3.4+ to this feature plugin.
*
* @todo Remove this function when merging into core because it won't be necessary.
*
* @param array $args WP_Query args.
* @param array $attributes Shortcode attributes.
* @param string $type Type of shortcode currently processing.
*/
function wgpb_extra_shortcode_features( $args, $attributes, $type ) {
if ( 'products' !== $type ) {
return $args;
}
// Enable term ids in the category shortcode.
if ( ! empty( $attributes['category'] ) ) {
$categories = array_map( 'sanitize_title', explode( ',', $attributes['category'] ) );
$field = 'slug';
if ( empty( $args['tax_query'] ) ) {
$args['tax_query'] = array(); // WPCS: slow query ok.
}
// Unset old category tax query.
foreach ( $args['tax_query'] as $index => $tax_query ) {
if ( 'product_cat' === $tax_query['taxonomy'] ) {
unset( $args['tax_query'][ $index ] );
}
}
if ( is_numeric( $categories[0] ) ) {
$categories = array_map( 'absint', $categories );
$field = 'term_id';
}
$args['tax_query'][] = array(
'taxonomy' => 'product_cat',
'terms' => $categories,
'field' => $field,
'operator' => $attributes['cat_operator'],
// See https://github.com/woocommerce/woocommerce/pull/20207/files#diff-9982e2749834d5232f1ed411b6c20312.
'include_children' => 'AND' === $attributes['cat_operator'] ? false : true,
);
}
// Enable term ids in the attributes shortcode and just-attribute queries.
if ( ! empty( $attributes['attribute'] ) || ! empty( $attributes['terms'] ) ) {
$taxonomy = strstr( $attributes['attribute'], 'pa_' ) ? sanitize_title( $attributes['attribute'] ) : 'pa_' . sanitize_title( $attributes['attribute'] );
$terms = $attributes['terms'] ? array_map( 'sanitize_title', explode( ',', $attributes['terms'] ) ) : array();
$field = 'slug';
if ( empty( $args['tax_query'] ) ) {
$args['tax_query'] = array(); // WPCS: slow query ok.
}
// Unset old attribute tax query.
foreach ( $args['tax_query'] as $index => $tax_query ) {
if ( $taxonomy === $tax_query['taxonomy'] ) {
unset( $args['tax_query'][ $index ] );
}
}
if ( $terms && is_numeric( $terms[0] ) ) {
$terms = array_map( 'absint', $terms );
$field = 'term_id';
}
// If no terms were specified get all products that are in the attribute taxonomy.
if ( ! $terms ) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'fields' => 'ids',
)
);
$field = 'term_id';
}
$args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'terms' => $terms,
'field' => $field,
'operator' => $attributes['terms_operator'],
);
}
return $args;
}
add_filter( 'woocommerce_shortcode_products_query', 'wgpb_extra_shortcode_features', 10, 3 );