plugin updates
This commit is contained in:
@@ -64,13 +64,14 @@ class WC_REST_Customer_Downloads_V1_Controller extends WC_REST_Controller {
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
$customer = get_user_by( 'id', (int) $request['customer_id'] );
|
||||
$customer = new WC_Customer( (int) $request['customer_id'] );
|
||||
$customer_id = $customer->get_id();
|
||||
|
||||
if ( ! $customer ) {
|
||||
if ( ! $customer_id ) {
|
||||
return new WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) {
|
||||
if ( ! wc_rest_check_user_permissions( 'read', $customer_id ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -1951,7 +1951,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
||||
),
|
||||
'stock_quantity' => array(
|
||||
'description' => __( 'Stock quantity.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'type' => has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'integer' : 'number',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'in_stock' => array(
|
||||
|
||||
@@ -586,7 +586,7 @@ class WC_REST_Order_Refunds_V2_Controller extends WC_REST_Orders_V2_Controller {
|
||||
),
|
||||
'rate_id' => array(
|
||||
'description' => __( 'Tax rate ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
|
||||
@@ -930,6 +930,11 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
|
||||
$this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted );
|
||||
$this->maybe_set_item_meta_data( $item, $posted );
|
||||
|
||||
if ( 'update' === $action ) {
|
||||
require_once WC_ABSPATH . 'includes/admin/wc-admin-functions.php';
|
||||
wc_maybe_adjust_line_item_product_stock( $item );
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
@@ -1619,7 +1624,7 @@ class WC_REST_Orders_V2_Controller extends WC_REST_CRUD_Controller {
|
||||
),
|
||||
'rate_id' => array(
|
||||
'description' => __( 'Tax rate ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
|
||||
@@ -462,8 +462,12 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
|
||||
protected function get_attribute_taxonomy_name( $slug, $product ) {
|
||||
// Format slug so it matches attributes of the product.
|
||||
$slug = wc_attribute_taxonomy_slug( $slug );
|
||||
$attributes = $product->get_attributes();
|
||||
$attribute = false;
|
||||
$attributes = array_combine(
|
||||
array_map( 'wc_sanitize_taxonomy_name', array_keys( $product->get_attributes() ) ),
|
||||
array_values( $product->get_attributes() )
|
||||
);
|
||||
|
||||
$attribute = false;
|
||||
|
||||
// pa_ attributes.
|
||||
if ( isset( $attributes[ wc_attribute_taxonomy_name( $slug ) ] ) ) {
|
||||
@@ -1904,7 +1908,7 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
|
||||
),
|
||||
'stock_quantity' => array(
|
||||
'description' => __( 'Stock quantity.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'type' => has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'integer' : 'number',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'in_stock' => array(
|
||||
|
||||
@@ -231,13 +231,16 @@ class WC_REST_Shipping_Zone_Methods_V2_Controller extends WC_REST_Shipping_Zones
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after a product review is deleted via the REST API.
|
||||
* Fires after a shipping zone is deleted via the REST API.
|
||||
*
|
||||
* @param object $method
|
||||
* @param WP_REST_Response $response The response data.
|
||||
* @param WP_REST_Request $request The request sent to the API.
|
||||
* @since 9.1.0
|
||||
*
|
||||
* @param WC_Shipping_Method $method The shipping zone method being deleted.
|
||||
* @param WC_Shipping_Zone $zone The shipping zone the method belonged to.
|
||||
* @param WP_REST_Response $response The response data.
|
||||
* @param WP_REST_Request $request The request sent to the API.
|
||||
*/
|
||||
do_action( 'rest_delete_product_review', $method, $response, $request );
|
||||
do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $zone, $response, $request );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -1407,36 +1407,39 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
||||
$shortcode_required = false;
|
||||
$block_present = false;
|
||||
$block_required = false;
|
||||
$page = false;
|
||||
|
||||
// Page checks.
|
||||
if ( $page_id ) {
|
||||
$page_set = true;
|
||||
}
|
||||
if ( get_post( $page_id ) ) {
|
||||
$page_exists = true;
|
||||
}
|
||||
if ( 'publish' === get_post_status( $page_id ) ) {
|
||||
$page_visible = true;
|
||||
$page = get_post( $page_id );
|
||||
|
||||
if ( $page ) {
|
||||
$page_exists = true;
|
||||
|
||||
if ( 'publish' === $page->post_status ) {
|
||||
$page_visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcode checks.
|
||||
if ( $values['shortcode'] && get_post( $page_id ) ) {
|
||||
if ( $values['shortcode'] && $page ) {
|
||||
$shortcode_required = true;
|
||||
$page = get_post( $page_id );
|
||||
if ( strstr( $page->post_content, $values['shortcode'] ) ) {
|
||||
if ( has_shortcode( $page->post_content, trim( $values['shortcode'], '[]' ) ) ) {
|
||||
$shortcode_present = true;
|
||||
}
|
||||
|
||||
// Compatibility with the classic shortcode block which can be used instead of shortcodes.
|
||||
if ( ! $shortcode_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) {
|
||||
$shortcode_present = has_block( 'woocommerce/classic-shortcode', $page->post_content );
|
||||
}
|
||||
}
|
||||
|
||||
// Block checks.
|
||||
if ( $values['block'] && get_post( $page_id ) ) {
|
||||
if ( $values['block'] && $page ) {
|
||||
$block_required = true;
|
||||
$block_present = WC_Blocks_Utils::has_block_in_page( $page_id, $values['block'] );
|
||||
|
||||
// Compatibility with the classic shortcode block which can be used instead of shortcodes.
|
||||
if ( ! $block_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) {
|
||||
$block_present = WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/classic-shortcode', true );
|
||||
}
|
||||
$block_present = has_block( $values['block'], $page->post_content );
|
||||
}
|
||||
|
||||
// Wrap up our findings into an output array.
|
||||
|
||||
@@ -24,4 +24,61 @@ class WC_REST_Product_Shipping_Classes_Controller extends WC_REST_Product_Shippi
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Register the routes for product reviews.
|
||||
*/
|
||||
public function register_routes() {
|
||||
parent::register_routes();
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/slug-suggestion',
|
||||
array(
|
||||
'args' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Suggest a slug for the term.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'suggest_slug' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback fuction for the slug-suggestion endpoint.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return string The suggested slug.
|
||||
*/
|
||||
public function suggest_slug( $request ) {
|
||||
$name = $request['name'];
|
||||
$slug = sanitize_title( $name ); // potential slug.
|
||||
$term = get_term_by( 'slug', $slug, $this->taxonomy );
|
||||
|
||||
/*
|
||||
* If the term exists, creates a unique slug
|
||||
* based on the name provided.
|
||||
* Otherwise, returns the sanitized name.
|
||||
*/
|
||||
if ( isset( $term->slug ) ) {
|
||||
/*
|
||||
* Pass a Term object that has only the taxonomy property,
|
||||
* to induce the wp_unique_term_slug() function to generate a unique slug.
|
||||
* Otherwise, the function will return the same slug.
|
||||
* @see https://core.trac.wordpress.org/browser/tags/6.5/src/wp-includes/taxonomy.php#L3130
|
||||
* @see https://github.com/WordPress/wordpress-develop/blob/a1b1e0339eb6dfa72a30933cac2a1c6ad2bbfe96/src/wp-includes/taxonomy.php#L3078-L3156
|
||||
*/
|
||||
$slug = wp_unique_term_slug( $slug, (object) array( 'taxonomy' => $this->taxonomy ) );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $slug );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1131,7 +1131,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
||||
),
|
||||
'stock_quantity' => array(
|
||||
'description' => __( 'Stock quantity.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'type' => has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'integer' : 'number',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'stock_status' => array(
|
||||
|
||||
Reference in New Issue
Block a user