Merge remote-tracking branch 'origin/master'

This commit is contained in:
Mike Jolley 2016-05-31 11:04:21 +01:00
commit 19c6b0fead
18 changed files with 105 additions and 47 deletions

View File

@ -90,6 +90,18 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
if ( ! empty( $items['create'] ) ) { if ( ! empty( $items['create'] ) ) {
foreach ( $items['create'] as $item ) { foreach ( $items['create'] as $item ) {
$_item = new WP_REST_Request( 'POST' ); $_item = new WP_REST_Request( 'POST' );
// Default parameters.
$defaults = array();
$schema = $this->get_public_item_schema();
foreach ( $schema['properties'] as $arg => $options ) {
if ( isset( $options['default'] ) ) {
$defaults[ $arg ] = $options['default'];
}
}
$_item->set_default_params( $defaults );
// Set request parameters.
$_item->set_body_params( $item ); $_item->set_body_params( $item );
$_response = $this->create_item( $_item ); $_response = $this->create_item( $_item );

View File

@ -666,12 +666,6 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
); );
} }
$params['slug'] = array(
'description' => __( 'Limit result set to posts with a specific slug.', 'woocommerce', 'woocommerce' ),
'type' => 'string',
'validate_callback' => 'rest_validate_request_arg',
);
$params['filter'] = array( $params['filter'] = array(
'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ), 'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ),
); );

View File

@ -188,7 +188,7 @@ class WC_Meta_Box_Order_Data {
} }
if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) { if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) {
echo __( 'Customer IP', 'woocommerce' ) . ': <span class="customer_ip">' . esc_html( $ip_address ) . '</span>'; echo __( 'Customer IP', 'woocommerce' ) . ': <span class="woocommerce-Order-customerIP customer-ip">' . esc_html( $ip_address ) . '</span>';
} }
?></p> ?></p>

View File

@ -66,11 +66,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
'methods' => WP_REST_Server::CREATABLE, 'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'create_item' ), 'callback' => array( $this, 'create_item' ),
'permission_callback' => array( $this, 'create_item_permissions_check' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
'email' => array(
'required' => true,
),
) ),
), ),
'schema' => array( $this, 'get_public_item_schema' ), 'schema' => array( $this, 'get_public_item_schema' ),
) ); ) );
@ -364,7 +360,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'reason' => array( 'reason' => array(
'description' => __( 'Reason for refund', 'woocommerce' ), 'description' => __( 'Reason for refund.', 'woocommerce' ),
'type' => 'string', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
@ -408,7 +404,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
), ),
'tax_class' => array( 'tax_class' => array(
'description' => __( 'Tax class of product.', 'woocommerce' ), 'description' => __( 'Tax class of product.', 'woocommerce' ),
'type' => 'integer', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,
), ),
@ -439,7 +435,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'taxes' => array( 'taxes' => array(
'description' => __( 'Line total tax.', 'woocommerce' ), 'description' => __( 'Line taxes.', 'woocommerce' ),
'type' => 'array', 'type' => 'array',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,

View File

@ -151,7 +151,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'customer_user_agent' => $order->customer_user_agent, 'customer_user_agent' => $order->customer_user_agent,
'created_via' => $order->created_via, 'created_via' => $order->created_via,
'customer_note' => $order->customer_note, 'customer_note' => $order->customer_note,
'date_completed' => wc_rest_prepare_date_response( $order->completed_date, true ), 'date_completed' => wc_rest_prepare_date_response( $order->completed_date ),
'date_paid' => $order->paid_date, 'date_paid' => $order->paid_date,
'cart_hash' => $order->cart_hash, 'cart_hash' => $order->cart_hash,
'line_items' => array(), 'line_items' => array(),
@ -546,11 +546,11 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 );
} }
if ( ! empty( $item['product_id'] ) ) { if ( ! empty( $item['sku'] ) ) {
$product_id = (int) $item['product_id'];
} else if ( ! empty( $item['sku'] ) ) {
$product_id = (int) wc_get_product_id_by_sku( $item['sku'] ); $product_id = (int) wc_get_product_id_by_sku( $item['sku'] );
} else if ( ! empty( $item['variation_id'] ) ) { } elseif ( ! empty( $item['product_id'] ) && empty( $item['variation_id'] ) ) {
$product_id = (int) $item['product_id'];
} elseif ( ! empty( $item['variation_id'] ) ) {
$product_id = (int) $item['variation_id']; $product_id = (int) $item['variation_id'];
} }
@ -1316,12 +1316,11 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ), 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ),
'type' => 'boolean', 'type' => 'boolean',
'default' => false, 'default' => false,
'context' => array( 'view', 'edit' ), 'context' => array( 'edit' ),
'writeonly' => true,
), ),
'transaction_id' => array( 'transaction_id' => array(
'description' => __( 'Unique transaction ID.', 'woocommerce' ), 'description' => __( 'Unique transaction ID.', 'woocommerce' ),
'type' => 'boolean', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'customer_ip_address' => array( 'customer_ip_address' => array(
@ -1361,7 +1360,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
), ),
'cart_hash' => array( 'cart_hash' => array(
'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ), 'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
'type' => 'float', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,
), ),
@ -1378,7 +1377,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
), ),
'name' => array( 'name' => array(
'description' => __( 'Product name.', 'woocommerce' ), 'description' => __( 'Product name.', 'woocommerce' ),
'type' => 'integer', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,
), ),
@ -1436,7 +1435,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'taxes' => array( 'taxes' => array(
'description' => __( 'Line total tax.', 'woocommerce' ), 'description' => __( 'Line taxes.', 'woocommerce' ),
'type' => 'array', 'type' => 'array',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,
@ -1557,7 +1556,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
), ),
'method_id' => array( 'method_id' => array(
'description' => __( 'Shipping method ID.', 'woocommerce' ), 'description' => __( 'Shipping method ID.', 'woocommerce' ),
'type' => 'integer', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'total' => array( 'total' => array(
@ -1572,7 +1571,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'readonly' => true, 'readonly' => true,
), ),
'taxes' => array( 'taxes' => array(
'description' => __( 'Line total tax.', 'woocommerce' ), 'description' => __( 'Line taxes.', 'woocommerce' ),
'type' => 'array', 'type' => 'array',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,
@ -1620,7 +1619,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'total' => array( 'total' => array(
'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), 'description' => __( 'Line total (after discounts).', 'woocommerce' ),
'type' => 'string', 'type' => 'string',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
@ -1630,7 +1629,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
), ),
'taxes' => array( 'taxes' => array(
'description' => __( 'Line total tax.', 'woocommerce' ), 'description' => __( 'Line taxes.', 'woocommerce' ),
'type' => 'array', 'type' => 'array',
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'readonly' => true, 'readonly' => true,

View File

@ -634,9 +634,9 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
protected function validate_attribute_slug( $slug, $new_data = true ) { protected function validate_attribute_slug( $slug, $new_data = true ) {
if ( strlen( $slug ) >= 28 ) { if ( strlen( $slug ) >= 28 ) {
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max).', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max).', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
} else if ( wc_check_if_attribute_name_is_reserved( $slug ) ) { } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) {
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
} else if ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) {
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
} }

View File

@ -1147,7 +1147,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
// Stock quantity. // Stock quantity.
if ( isset( $request['stock_quantity'] ) ) { if ( isset( $request['stock_quantity'] ) ) {
wc_update_product_stock( $product->id, wc_stock_amount( $request['stock_quantity'] ) ); wc_update_product_stock( $product->id, wc_stock_amount( $request['stock_quantity'] ) );
} else if ( isset( $request['inventory_delta'] ) ) { } elseif ( isset( $request['inventory_delta'] ) ) {
$stock_quantity = wc_stock_amount( get_post_meta( $product->id, '_stock', true ) ); $stock_quantity = wc_stock_amount( get_post_meta( $product->id, '_stock', true ) );
$stock_quantity += wc_stock_amount( $request['inventory_delta'] ); $stock_quantity += wc_stock_amount( $request['inventory_delta'] );
@ -1408,7 +1408,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
if ( isset( $variation['stock_quantity'] ) ) { if ( isset( $variation['stock_quantity'] ) ) {
wc_update_product_stock( $variation_id, wc_stock_amount( $variation['stock_quantity'] ) ); wc_update_product_stock( $variation_id, wc_stock_amount( $variation['stock_quantity'] ) );
} else if ( isset( $request['inventory_delta'] ) ) { } elseif ( isset( $request['inventory_delta'] ) ) {
$stock_quantity = wc_stock_amount( get_post_meta( $variation_id, '_stock', true ) ); $stock_quantity = wc_stock_amount( get_post_meta( $variation_id, '_stock', true ) );
$stock_quantity += wc_stock_amount( $request['inventory_delta'] ); $stock_quantity += wc_stock_amount( $request['inventory_delta'] );
@ -2509,6 +2509,11 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
public function get_collection_params() { public function get_collection_params() {
$params = parent::get_collection_params(); $params = parent::get_collection_params();
$params['slug'] = array(
'description' => __( 'Limit result set to posts with a specific slug.', 'woocommerce', 'woocommerce' ),
'type' => 'string',
'validate_callback' => 'rest_validate_request_arg',
);
$params['status'] = array( $params['status'] = array(
'default' => 'any', 'default' => 'any',
'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ),

View File

@ -520,7 +520,6 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'type' => 'string', 'type' => 'string',
'format' => 'uri', 'format' => 'uri',
'context' => array( 'edit' ), 'context' => array( 'edit' ),
'writeonly' => true,
), ),
'date_created' => array( 'date_created' => array(
'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ), 'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ),

View File

@ -2091,6 +2091,16 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
} }
} }
if ( ! function_exists( 'woocommerce_account_navigation' ) ) {
/**
* My Account navigation template.
*/
function woocommerce_account_navigation() {
wc_get_template( 'myaccount/navigation.php' );
}
}
if ( ! function_exists( 'woocommerce_account_orders' ) ) { if ( ! function_exists( 'woocommerce_account_orders' ) ) {
/** /**

View File

@ -256,6 +256,7 @@ add_filter( 'jetpack_comment_form_enabled_for_product', '__return_false' );
/** /**
* My Account. * My Account.
*/ */
add_action( 'woocommerce_account_navigation', 'woocommerce_account_navigation' );
add_action( 'woocommerce_account_orders_endpoint', 'woocommerce_account_orders' ); add_action( 'woocommerce_account_orders_endpoint', 'woocommerce_account_orders' );
add_action( 'woocommerce_account_view-order_endpoint', 'woocommerce_account_view_order' ); add_action( 'woocommerce_account_view-order_endpoint', 'woocommerce_account_view_order' );
add_action( 'woocommerce_account_downloads_endpoint', 'woocommerce_account_downloads' ); add_action( 'woocommerce_account_downloads_endpoint', 'woocommerce_account_downloads' );

View File

@ -25,9 +25,14 @@ if ( ! defined( 'ABSPATH' ) ) {
$downloads = WC()->customer->get_downloadable_products(); $downloads = WC()->customer->get_downloadable_products();
$has_downloads = (bool) $downloads; $has_downloads = (bool) $downloads;
wc_print_notices(); ?> wc_print_notices();
<?php wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">

View File

@ -20,7 +20,12 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">
<?php if ( $available_gateways = WC()->payment_gateways->get_available_payment_gateways() ) : ?> <?php if ( $available_gateways = WC()->payment_gateways->get_available_payment_gateways() ) : ?>

View File

@ -22,7 +22,12 @@ if ( ! defined( 'ABSPATH' ) ) {
wc_print_notices(); wc_print_notices();
wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">

View File

@ -24,7 +24,12 @@ $page_title = ( $load_address === 'billing' ) ? __( 'Billing Address', 'woocomme
wc_print_notices(); wc_print_notices();
wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">

View File

@ -20,9 +20,14 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
wc_print_notices(); ?> wc_print_notices();
<?php wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">
<p> <p>

View File

@ -23,7 +23,13 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
wc_print_notices(); wc_print_notices();
wc_get_template( 'myaccount/navigation.php' ); ?>
/**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">

View File

@ -25,9 +25,15 @@ if ( ! defined( 'ABSPATH' ) ) {
$saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() ); $saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() );
$has_methods = (bool) $saved_methods; $has_methods = (bool) $saved_methods;
$types = wc_get_account_payment_methods_types(); $types = wc_get_account_payment_methods_types();
wc_print_notices(); ?>
<?php wc_get_template( 'myaccount/navigation.php' ); ?> wc_print_notices();
/**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">

View File

@ -22,9 +22,14 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
wc_print_notices(); ?> wc_print_notices();
<?php wc_get_template( 'myaccount/navigation.php' ); ?> /**
* My Account navigation.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content"> <div class="woocommerce-MyAccount-content">
<p><?php <p><?php