From c2f857a4d83c1c9cb248294feedb144e7040d83b Mon Sep 17 00:00:00 2001 From: Sergey Ratushnuy Date: Wed, 29 Jan 2020 13:09:27 +0200 Subject: [PATCH 001/115] Fix duplicated custom fields after import products from .csv file --- .../admin/importers/class-wc-product-csv-importer-controller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 22b7055591704..2e1a6d4143dc6 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -577,7 +577,6 @@ protected function auto_map_columns( $raw_headers, $num_indexes = true ) { $headers = array(); foreach ( $raw_headers as $key => $field ) { - $field = strtolower( $field ); $index = $num_indexes ? $key : $field; $headers[ $index ] = $field; From 6295534fbb11fc6899ac5c629b50002ba253dc87 Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Tue, 4 Feb 2020 12:57:31 -0800 Subject: [PATCH 002/115] Adds support for group_description for privacy exporters which was added in WP5.3 through WPCoreChangeset#45825 and WPCoreTracTicket#45491 --- includes/class-wc-privacy-exporters.php | 45 ++++++++++++++----------- tests/unit-tests/privacy/export.php | 9 ++--- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/includes/class-wc-privacy-exporters.php b/includes/class-wc-privacy-exporters.php index 7d519c2f0a14d..b248de85d8303 100644 --- a/includes/class-wc-privacy-exporters.php +++ b/includes/class-wc-privacy-exporters.php @@ -27,10 +27,11 @@ public static function customer_data_exporter( $email_address ) { $customer_personal_data = self::get_customer_personal_data( $user ); if ( ! empty( $customer_personal_data ) ) { $data_to_export[] = array( - 'group_id' => 'woocommerce_customer', - 'group_label' => __( 'Customer Data', 'woocommerce' ), - 'item_id' => 'user', - 'data' => $customer_personal_data, + 'group_id' => 'woocommerce_customer', + 'group_label' => __( 'Customer Data', 'woocommerce' ), + 'group_description' => __( 'User’s WooCommerce customer data.', 'woocommerce' ), + 'item_id' => 'user', + 'data' => $customer_personal_data, ); } } @@ -71,10 +72,11 @@ public static function order_data_exporter( $email_address, $page ) { if ( 0 < count( $orders ) ) { foreach ( $orders as $order ) { $data_to_export[] = array( - 'group_id' => 'woocommerce_orders', - 'group_label' => __( 'Orders', 'woocommerce' ), - 'item_id' => 'order-' . $order->get_id(), - 'data' => self::get_order_personal_data( $order ), + 'group_id' => 'woocommerce_orders', + 'group_label' => __( 'Orders', 'woocommerce' ), + 'group_description' => __( 'User’s WooCommerce orders data.', 'woocommerce' ), + 'item_id' => 'order-' . $order->get_id(), + 'data' => self::get_order_personal_data( $order ), ); } $done = 10 > count( $orders ); @@ -118,22 +120,24 @@ public static function download_data_exporter( $email_address, $page ) { if ( 0 < count( $downloads ) ) { foreach ( $downloads as $download ) { $data_to_export[] = array( - 'group_id' => 'woocommerce_downloads', + 'group_id' => 'woocommerce_downloads', /* translators: This is the headline for a list of downloads purchased from the store for a given user. */ - 'group_label' => __( 'Purchased Downloads', 'woocommerce' ), - 'item_id' => 'download-' . $download->get_id(), - 'data' => self::get_download_personal_data( $download ), + 'group_label' => __( 'Purchased Downloads', 'woocommerce' ), + 'group_description' => __( 'User’s WooCommerce purchased downloads data.', 'woocommerce' ), + 'item_id' => 'download-' . $download->get_id(), + 'data' => self::get_download_personal_data( $download ), ); $download_logs = $customer_download_log_data_store->get_download_logs_for_permission( $download->get_id() ); foreach ( $download_logs as $download_log ) { $data_to_export[] = array( - 'group_id' => 'woocommerce_download_logs', + 'group_id' => 'woocommerce_download_logs', /* translators: This is the headline for a list of access logs for downloads purchased from the store for a given user. */ - 'group_label' => __( 'Access to Purchased Downloads', 'woocommerce' ), - 'item_id' => 'download-log-' . $download_log->get_id(), - 'data' => array( + 'group_label' => __( 'Access to Purchased Downloads', 'woocommerce' ), + 'group_description' => __( 'User’s WooCommerce access to purchased downloads data.', 'woocommerce' ), + 'item_id' => 'download-log-' . $download_log->get_id(), + 'data' => array( array( 'name' => __( 'Download ID', 'woocommerce' ), 'value' => $download_log->get_permission_id(), @@ -413,10 +417,11 @@ public static function customer_tokens_exporter( $email_address, $page ) { if ( 0 < count( $tokens ) ) { foreach ( $tokens as $token ) { $data_to_export[] = array( - 'group_id' => 'woocommerce_tokens', - 'group_label' => __( 'Payment Tokens', 'woocommerce' ), - 'item_id' => 'token-' . $token->get_id(), - 'data' => array( + 'group_id' => 'woocommerce_tokens', + 'group_label' => __( 'Payment Tokens', 'woocommerce' ), + 'group_description' => __( 'User’s WooCommerce payment tokens data.', 'woocommerce' ), + 'item_id' => 'token-' . $token->get_id(), + 'data' => array( array( 'name' => __( 'Token', 'woocommerce' ), 'value' => $token->get_display_name(), diff --git a/tests/unit-tests/privacy/export.php b/tests/unit-tests/privacy/export.php index 2a9a8fb1ffdf1..0d8db0ee39eaa 100644 --- a/tests/unit-tests/privacy/export.php +++ b/tests/unit-tests/privacy/export.php @@ -71,10 +71,11 @@ public function test_customer_data_exporter() { $this->assertEquals( array( array( - 'group_id' => 'woocommerce_customer', - 'group_label' => 'Customer Data', - 'item_id' => 'user', - 'data' => array( + 'group_id' => 'woocommerce_customer', + 'group_label' => 'Customer Data', + 'group_description' => 'User’s WooCommerce customer data.', + 'item_id' => 'user', + 'data' => array( array( 'name' => 'Billing Address 1', 'value' => '123 South Street', From 3dd6489c692cc1aa69127d0c9de8fb44daa6cfff Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Tue, 4 Feb 2020 13:24:55 -0800 Subject: [PATCH 003/115] Update Suggested Privacy Policy text to utilize css class instead of as it was deprecated. Also wrap the contents in the div to style the section to match WordPress. This follows from WPCoreTrac#49282 and although back-compat is being introduced in WP5.4 as of WPChangeset#47112 this change will better support users of WP5.1-5.4 --- includes/class-wc-privacy.php | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/includes/class-wc-privacy.php b/includes/class-wc-privacy.php index 516b24ff63878..5ffed57c6f3dc 100644 --- a/includes/class-wc-privacy.php +++ b/includes/class-wc-privacy.php @@ -66,12 +66,10 @@ public function __construct() { * @since 3.4.0 */ public function get_privacy_message() { - $content = ' -
' . - '

' . - __( 'This sample language includes the basics around what personal data your store may be collecting, storing and sharing, as well as who may have access to that data. Depending on what settings are enabled and which additional plugins are used, the specific information shared by your store will vary. We recommend consulting with a lawyer when deciding what information to disclose on your privacy policy.', 'woocommerce' ) . - '

' . - '
' . + $content = '
' . + '

' . + __( 'This sample language includes the basics around what personal data your store may be collecting, storing and sharing, as well as who may have access to that data. Depending on what settings are enabled and which additional plugins are used, the specific information shared by your store will vary. We recommend consulting with a lawyer when deciding what information to disclose on your privacy policy.', 'woocommerce' ) . + '

' . '

' . __( 'We collect information about you during the checkout process on our store.', 'woocommerce' ) . '

' . '

' . __( 'What we collect and store', 'woocommerce' ) . '

' . '

' . __( 'While you visit our site, we’ll track:', 'woocommerce' ) . '

' . @@ -81,9 +79,9 @@ public function get_privacy_message() { '
  • ' . __( 'Shipping address: we’ll ask you to enter this so we can, for instance, estimate shipping before you place an order, and send you the order!', 'woocommerce' ) . '
  • ' . '' . '

    ' . __( 'We’ll also use cookies to keep track of cart contents while you’re browsing our site.', 'woocommerce' ) . '

    ' . - '
    ' . - '

    ' . __( 'Note: you may want to further detail your cookie policy, and link to that section from here.', 'woocommerce' ) . '

    ' . - '
    ' . + '

    ' . + __( 'Note: you may want to further detail your cookie policy, and link to that section from here.', 'woocommerce' ) . + '

    ' . '

    ' . __( 'When you purchase from us, we’ll ask you to provide information including your name, billing address, shipping address, email address, phone number, credit card/payment details and optional account information like username and password. We’ll use this information for purposes, such as, to:', 'woocommerce' ) . '

    ' . '
      ' . '
    • ' . __( 'Send you information about your account and order', 'woocommerce' ) . '
    • ' . @@ -105,16 +103,17 @@ public function get_privacy_message() { '
    ' . '

    ' . __( 'Our team members have access to this information to help fulfill orders, process refunds and support you.', 'woocommerce' ) . '

    ' . '

    ' . __( 'What we share with others', 'woocommerce' ) . '

    ' . - '
    ' . - '

    ' . __( 'In this section you should list who you’re sharing data with, and for what purpose. This could include, but may not be limited to, analytics, marketing, payment gateways, shipping providers, and third party embeds.', 'woocommerce' ) . '

    ' . - '
    ' . + '

    ' . + __( 'In this section you should list who you’re sharing data with, and for what purpose. This could include, but may not be limited to, analytics, marketing, payment gateways, shipping providers, and third party embeds.', 'woocommerce' ) . + '

    ' . '

    ' . __( 'We share information with third parties who help us provide our orders and store services to you; for example --', 'woocommerce' ) . '

    ' . '

    ' . __( 'Payments', 'woocommerce' ) . '

    ' . - '
    ' . - '

    ' . __( 'In this subsection you should list which third party payment processors you’re using to take payments on your store since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'woocommerce' ) . '

    ' . - '
    ' . + '

    ' . + __( 'In this subsection you should list which third party payment processors you’re using to take payments on your store since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'woocommerce' ) . + '

    ' . '

    ' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'woocommerce' ) . '

    ' . - '

    ' . __( 'Please see the PayPal Privacy Policy for more details.', 'woocommerce' ) . '

    '; + '

    ' . __( 'Please see the PayPal Privacy Policy for more details.', 'woocommerce' ) . '

    ' . + '
    '; return apply_filters( 'wc_privacy_policy_content', $content ); } From f92bbf249a511e19e311d39f08595029a10bed1f Mon Sep 17 00:00:00 2001 From: John Date: Fri, 7 Feb 2020 02:10:38 +0200 Subject: [PATCH 004/115] Hide Germany's, Denmark's and Sweden's state field When you choose the country 'Germany'(or Denmark or Sweden) from a woocommerce website, the state field is hidden. So I added to be hidden in this class too. --- includes/class-wc-countries.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index a0e78164b2dfd..d0b78c0b84e47 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -908,6 +908,7 @@ public function get_country_locale() { ), 'state' => array( 'required' => false, + 'hidden' => true, ), ), 'DK' => array( @@ -916,6 +917,7 @@ public function get_country_locale() { ), 'state' => array( 'required' => false, + 'hidden' => true, ), ), 'EE' => array( @@ -1227,6 +1229,7 @@ public function get_country_locale() { ), 'state' => array( 'required' => false, + 'hidden' => true, ), ), 'TR' => array( From 89f07da20dc194bfd6ed719820d80db0d39dcf41 Mon Sep 17 00:00:00 2001 From: Remi Corson Date: Tue, 11 Feb 2020 10:46:32 +0100 Subject: [PATCH 005/115] Replace {sitde_address} by {site_url} for consistency Replace {sitde_address} by {site_url} for consistency in WooCommerce emails, for better consistency. --- includes/admin/settings/class-wc-settings-emails.php | 2 +- includes/class-wc-emails.php | 2 +- includes/emails/class-wc-email-customer-invoice.php | 2 +- includes/emails/class-wc-email-customer-processing-order.php | 2 +- includes/emails/class-wc-email.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/admin/settings/class-wc-settings-emails.php b/includes/admin/settings/class-wc-settings-emails.php index 5c5525bafd55c..00df31501968c 100644 --- a/includes/admin/settings/class-wc-settings-emails.php +++ b/includes/admin/settings/class-wc-settings-emails.php @@ -128,7 +128,7 @@ public function get_settings() { array( 'title' => __( 'Footer text', 'woocommerce' ), /* translators: %s: Available placeholders for use */ - 'desc' => __( 'The text to appear in the footer of all WooCommerce emails.', 'woocommerce' ) . ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title} {site_address}' ), + 'desc' => __( 'The text to appear in the footer of all WooCommerce emails.', 'woocommerce' ) . ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title} {site_url}' ), 'id' => 'woocommerce_email_footer_text', 'css' => 'width:400px; height: 75px;', 'placeholder' => __( 'N/A', 'woocommerce' ), diff --git a/includes/class-wc-emails.php b/includes/class-wc-emails.php index 3edef5e03f3fb..a7d98673910bc 100644 --- a/includes/class-wc-emails.php +++ b/includes/class-wc-emails.php @@ -289,7 +289,7 @@ public function replace_placeholders( $string ) { return str_replace( array( '{site_title}', - '{site_address}', + '{site_url}', '{woocommerce}', '{WooCommerce}', ), diff --git a/includes/emails/class-wc-email-customer-invoice.php b/includes/emails/class-wc-email-customer-invoice.php index 320509cb7a903..a1973bfbc3ed5 100644 --- a/includes/emails/class-wc-email-customer-invoice.php +++ b/includes/emails/class-wc-email-customer-invoice.php @@ -112,7 +112,7 @@ public function get_heading() { * @return string */ public function get_default_additional_content() { - return __( 'Thanks for using {site_address}!', 'woocommerce' ); + return __( 'Thanks for using {site_url}!', 'woocommerce' ); } /** diff --git a/includes/emails/class-wc-email-customer-processing-order.php b/includes/emails/class-wc-email-customer-processing-order.php index 589f4a7359c69..42fc858c03893 100644 --- a/includes/emails/class-wc-email-customer-processing-order.php +++ b/includes/emails/class-wc-email-customer-processing-order.php @@ -141,7 +141,7 @@ public function get_content_plain() { * @return string */ public function get_default_additional_content() { - return __( 'Thanks for using {site_address}!', 'woocommerce' ); + return __( 'Thanks for using {site_url}!', 'woocommerce' ); } } diff --git a/includes/emails/class-wc-email.php b/includes/emails/class-wc-email.php index 8e7aba1827070..9a72b00e577e5 100644 --- a/includes/emails/class-wc-email.php +++ b/includes/emails/class-wc-email.php @@ -232,7 +232,7 @@ public function __construct() { $this->placeholders = array_merge( array( '{site_title}' => $this->get_blogname(), - '{site_address}' => wp_parse_url( home_url(), PHP_URL_HOST ), + '{site_url}' => wp_parse_url( home_url(), PHP_URL_HOST ), ), $this->placeholders ); From c9092d5dbfb0cd2aaf0a620e3cac0d021451753d Mon Sep 17 00:00:00 2001 From: Remi Corson Date: Tue, 11 Feb 2020 16:35:40 +0100 Subject: [PATCH 006/115] backwards compatibility --- includes/class-wc-emails.php | 2 ++ includes/emails/class-wc-email.php | 1 + 2 files changed, 3 insertions(+) diff --git a/includes/class-wc-emails.php b/includes/class-wc-emails.php index a7d98673910bc..2d2f4d24c8dae 100644 --- a/includes/class-wc-emails.php +++ b/includes/class-wc-emails.php @@ -289,6 +289,7 @@ public function replace_placeholders( $string ) { return str_replace( array( '{site_title}', + '{site_address}', '{site_url}', '{woocommerce}', '{WooCommerce}', @@ -296,6 +297,7 @@ public function replace_placeholders( $string ) { array( $this->get_blogname(), $domain, + $domain, 'WooCommerce', 'WooCommerce', ), diff --git a/includes/emails/class-wc-email.php b/includes/emails/class-wc-email.php index 9a72b00e577e5..7aa736c791c4a 100644 --- a/includes/emails/class-wc-email.php +++ b/includes/emails/class-wc-email.php @@ -232,6 +232,7 @@ public function __construct() { $this->placeholders = array_merge( array( '{site_title}' => $this->get_blogname(), + '{site_address}' => wp_parse_url( home_url(), PHP_URL_HOST ), '{site_url}' => wp_parse_url( home_url(), PHP_URL_HOST ), ), $this->placeholders From 8ff17ddbd25a657a10e045e4d80100906a61912d Mon Sep 17 00:00:00 2001 From: Miguel Pinto Date: Thu, 13 Feb 2020 03:11:44 +0000 Subject: [PATCH 007/115] Add option to override element tag container in checkout forms --- assets/js/frontend/country-select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index d0cbe57ba9254..77b9655d2146a 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -93,7 +93,7 @@ jQuery( function( $ ) { var country = $( this ).val(), $statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' ), - $parent = $statebox.closest( 'p.form-row' ), + $parent = $statebox.closest( '.form-row' ), input_name = $statebox.attr( 'name' ), input_id = $statebox.attr('id'), input_classes = $statebox.attr('data-input-classes'), From 38e081e5907cb5bc7a3e2ea918864f7ac50aaa81 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Tue, 25 Feb 2020 13:12:27 -0700 Subject: [PATCH 008/115] Set adding_to_cart trigger to variable. If false, do not fire ajax. Closes #25759. --- assets/js/frontend/add-to-cart.js | 56 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index cbf6d11a02d13..237df206bf397 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -76,33 +76,35 @@ jQuery( function( $ ) { }); // Trigger event. - $( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); - - e.data.addToCartHandler.addRequest({ - type: 'POST', - url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), - data: data, - success: function( response ) { - if ( ! response ) { - return; - } - - if ( response.error && response.product_url ) { - window.location = response.product_url; - return; - } - - // Redirect to cart option - if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { - window.location = wc_add_to_cart_params.cart_url; - return; - } - - // Trigger event so themes can refresh other areas. - $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); - }, - dataType: 'json' - }); + var valid = $( document.body ).triggerHandler( 'adding_to_cart', [ $thisbutton, data ] ); + + if( valid !== false ) { + e.data.addToCartHandler.addRequest({ + type: 'POST', + url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), + data: data, + success: function( response ) { + if ( ! response ) { + return; + } + + if ( response.error && response.product_url ) { + window.location = response.product_url; + return; + } + + // Redirect to cart option + if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { + window.location = wc_add_to_cart_params.cart_url; + return; + } + + // Trigger event so themes can refresh other areas. + $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); + }, + dataType: 'json' + }); + } } }; From 6937baccce52304f2d2365b90c062229e2163fb1 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Fri, 13 Mar 2020 18:25:25 -0600 Subject: [PATCH 009/115] Revert "Set adding_to_cart trigger to variable. If false, do not fire ajax. Closes #25759." This reverts commit 38e081e5907cb5bc7a3e2ea918864f7ac50aaa81. --- assets/js/frontend/add-to-cart.js | 56 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index 237df206bf397..cbf6d11a02d13 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -76,35 +76,33 @@ jQuery( function( $ ) { }); // Trigger event. - var valid = $( document.body ).triggerHandler( 'adding_to_cart', [ $thisbutton, data ] ); - - if( valid !== false ) { - e.data.addToCartHandler.addRequest({ - type: 'POST', - url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), - data: data, - success: function( response ) { - if ( ! response ) { - return; - } - - if ( response.error && response.product_url ) { - window.location = response.product_url; - return; - } - - // Redirect to cart option - if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { - window.location = wc_add_to_cart_params.cart_url; - return; - } - - // Trigger event so themes can refresh other areas. - $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); - }, - dataType: 'json' - }); - } + $( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); + + e.data.addToCartHandler.addRequest({ + type: 'POST', + url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), + data: data, + success: function( response ) { + if ( ! response ) { + return; + } + + if ( response.error && response.product_url ) { + window.location = response.product_url; + return; + } + + // Redirect to cart option + if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { + window.location = wc_add_to_cart_params.cart_url; + return; + } + + // Trigger event so themes can refresh other areas. + $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); + }, + dataType: 'json' + }); } }; From 4ed91d9482f99dbf5b6fcd14a35023df67f40bf7 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Fri, 13 Mar 2020 18:26:37 -0600 Subject: [PATCH 010/115] quit early if should_send_ajax_request.adding_to_cart triggerHandler is false and trigger a custom event instead --- assets/js/frontend/add-to-cart.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index cbf6d11a02d13..fa4f546b8e8df 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -69,6 +69,12 @@ jQuery( function( $ ) { $thisbutton.removeClass( 'added' ); $thisbutton.addClass( 'loading' ); + // Allow 3rd parties to validate and quit early. + if( false === $( document.body ).triggerHandler( 'should_send_ajax_request.adding_to_cart', [ $thisbutton ] ) ) { + $( document.body ).trigger( 'ajax_request_not_sent.adding_to_cart', [ false, false, $thisbutton ] ); + return true; + } + var data = {}; $.each( $thisbutton[0].dataset, function( key, value ) { From 319395b0fad2af725ab2c968d15c48eb6f4211c3 Mon Sep 17 00:00:00 2001 From: Kathy Daring Date: Fri, 13 Mar 2020 18:27:45 -0600 Subject: [PATCH 011/115] update the add to cart button if ajax request not sent --- assets/js/frontend/add-to-cart.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index fa4f546b8e8df..cc2c9ba68a614 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -17,6 +17,7 @@ jQuery( function( $ ) { .on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart ) .on( 'click', '.remove_from_cart_button', { addToCartHandler: this }, this.onRemoveFromCart ) .on( 'added_to_cart', this.updateButton ) + .on( 'ajax_request_not_sent.adding_to_cart', this.updateButton ) .on( 'added_to_cart removed_from_cart', { addToCartHandler: this }, this.updateFragments ); }; @@ -158,10 +159,13 @@ jQuery( function( $ ) { if ( $button ) { $button.removeClass( 'loading' ); - $button.addClass( 'added' ); + + if( fragments ) { + $button.addClass( 'added' ); + } // View cart text. - if ( ! wc_add_to_cart_params.is_cart && $button.parent().find( '.added_to_cart' ).length === 0 ) { + if ( fragments && ! wc_add_to_cart_params.is_cart && $button.parent().find( '.added_to_cart' ).length === 0 ) { $button.after( ' ' + wc_add_to_cart_params.i18n_view_cart + '' ); } From 459b75701511b2e943dd887ae8b40f3fdf56b6a2 Mon Sep 17 00:00:00 2001 From: Sergey Ratushnuy Date: Fri, 27 Mar 2020 10:55:42 +0200 Subject: [PATCH 012/115] Always pass attribute name to a 'woocommerce_attribute_label' filter --- includes/wc-attribute-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/wc-attribute-functions.php b/includes/wc-attribute-functions.php index 3820b107a6200..24bbd1ef358fb 100644 --- a/includes/wc-attribute-functions.php +++ b/includes/wc-attribute-functions.php @@ -185,9 +185,9 @@ function wc_attribute_taxonomy_id_by_name( $name ) { */ function wc_attribute_label( $name, $product = '' ) { if ( taxonomy_is_product_attribute( $name ) ) { - $name = wc_attribute_taxonomy_slug( $name ); + $slug = wc_attribute_taxonomy_slug( $name ); $all_labels = wc_get_attribute_taxonomy_labels(); - $label = isset( $all_labels[ $name ] ) ? $all_labels[ $name ] : $name; + $label = isset( $all_labels[ $slug ] ) ? $all_labels[ $slug ] : $slug; } elseif ( $product ) { if ( $product->is_type( 'variation' ) ) { $product = wc_get_product( $product->get_parent_id() ); From f684c749fc6b8c7a794d2d1cef2c41b8c53387c2 Mon Sep 17 00:00:00 2001 From: "vedanshu.jain" Date: Fri, 27 Mar 2020 20:09:29 +0530 Subject: [PATCH 013/115] Add method to get base data from order object. This method can be used when we need basic data about the object without querying for lot more (and expensive) data from DB. --- includes/class-wc-order.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index b2ab190c50634..a43455d2fcbae 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -419,6 +419,19 @@ protected function status_transition() { | */ + /** + * Get basic order data in array format. + * + * @return array + */ + public function get_base_data() { + return array_merge( + array( 'id' => $this->get_id() ), + $this->data, + array( 'number' => $this->get_order_number() ) + ); + } + /** * Get all class data in array format. * @@ -427,12 +440,8 @@ protected function status_transition() { */ public function get_data() { return array_merge( + $this->get_base_data(), array( - 'id' => $this->get_id(), - ), - $this->data, - array( - 'number' => $this->get_order_number(), 'meta_data' => $this->get_meta_data(), 'line_items' => $this->get_items( 'line_item' ), 'tax_lines' => $this->get_items( 'tax' ), From 37a949f7bd53d9649e60959518304050f42511d4 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 1 Apr 2020 14:56:04 -0300 Subject: [PATCH 014/115] Fixed coding standards --- includes/emails/class-wc-email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/emails/class-wc-email.php b/includes/emails/class-wc-email.php index 7aa736c791c4a..d3bea4a66e78a 100644 --- a/includes/emails/class-wc-email.php +++ b/includes/emails/class-wc-email.php @@ -233,7 +233,7 @@ public function __construct() { array( '{site_title}' => $this->get_blogname(), '{site_address}' => wp_parse_url( home_url(), PHP_URL_HOST ), - '{site_url}' => wp_parse_url( home_url(), PHP_URL_HOST ), + '{site_url}' => wp_parse_url( home_url(), PHP_URL_HOST ), ), $this->placeholders ); From 89336488e9a483af19aeb315acc525ebd27cbda0 Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Wed, 1 Apr 2020 16:32:54 -0700 Subject: [PATCH 015/115] Introduced privacy.scss with custom back-compat shim for handling the ul elements of WooCommerce privacy policy content and ensuring consistent styling with the default WordPress content. --- assets/css/privacy.scss | 66 ++++++++++++++++++++++++ includes/admin/class-wc-admin-assets.php | 7 +++ 2 files changed, 73 insertions(+) create mode 100644 assets/css/privacy.scss diff --git a/assets/css/privacy.scss b/assets/css/privacy.scss new file mode 100644 index 0000000000000..7778a12a608f2 --- /dev/null +++ b/assets/css/privacy.scss @@ -0,0 +1,66 @@ +/** + * privacy.scss + * Styles applied to the Privacy Policy Guide to support WooCommerce content. + * Adds support for styling ul/ol elements. + */ + +/** + * Styling begins + */ + +// Support for indented bullet-lists. +.wp-suggested-text ul, +.policy-text ul { + list-style: disc; +} + +.wp-suggested-text ol, +.policy-text ol { + list-style: decimal; +} + +.wp-suggested-text ul li, +.wp-suggested-text ol li, +.policy-text ul li, +.policy-text ol li { + margin-left: 2em; +} + +// Pre-5.4 support for italics. +.branch-4-9 .wp-suggested-text ul, +.branch-4-9 .wp-suggested-text ol, +.branch-5-0 .wp-suggested-text ul, +.branch-5-0 .wp-suggested-text ol, +.branch-5-1 .wp-suggested-text ul, +.branch-5-1 .wp-suggested-text ol, +.branch-5-2 .wp-suggested-text ul, +.branch-5-2 .wp-suggested-text ol, +.branch-5-3 .wp-suggested-text ul, +.branch-5-3 .wp-suggested-text ol { + font-style: italic; +} + +// 5.4 support for white background and padding. +.branch-5-4 .policy-text ul:not(.privacy-policy-tutorial):not(.wp-policy-help), +.branch-5-4 .policy-text ol:not(.privacy-policy-tutorial):not(.wp-policy-help) { + background-color: #fff; + margin: 0; + padding: 1em; +} + +.branch-5-4 .hide-privacy-policy-tutorial ul:not(.privacy-policy-tutorial):not(.wp-policy-help), +.branch-5-4 .hide-privacy-policy-tutorial ol:not(.privacy-policy-tutorial):not(.wp-policy-help) { + margin: 1em 0; + padding: 0; +} + +.policy-text p:not(.privacy-policy-tutorial):not(.wp-policy-help) + ul:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text p:not(.privacy-policy-tutorial):not(.wp-policy-help) + ol:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ul:not(.privacy-policy-tutorial):not(.wp-policy-help) + p:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ul:not(.privacy-policy-tutorial):not(.wp-policy-help) + ul:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ul:not(.privacy-policy-tutorial):not(.wp-policy-help) + ol:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ol:not(.privacy-policy-tutorial):not(.wp-policy-help) + p:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ol:not(.privacy-policy-tutorial):not(.wp-policy-help) + ul:not(.privacy-policy-tutorial):not(.wp-policy-help), +.policy-text ol:not(.privacy-policy-tutorial):not(.wp-policy-help) + ol:not(.privacy-policy-tutorial):not(.wp-policy-help) { + padding-top: 0; +} diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index baabe2594c287..8cb5978409f9f 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -41,6 +41,7 @@ public function admin_styles() { wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION ); wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' ); wp_register_style( 'woocommerce_admin_marketplace_styles', WC()->plugin_url() . '/assets/css/marketplace-suggestions.css', array(), WC_VERSION ); + wp_register_style( 'woocommerce_admin_privacy_styles', WC()->plugin_url() . '/assets/css/privacy.css', array(), WC_VERSION ); // Add RTL support for admin styles. wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); @@ -48,6 +49,7 @@ public function admin_styles() { wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' ); wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' ); wp_style_add_data( 'woocommerce_admin_marketplace_styles', 'rtl', 'replace' ); + wp_style_add_data( 'woocommerce_admin_privacy_styles', 'rtl', 'replace' ); // Sitewide menu CSS. wp_enqueue_style( 'woocommerce_admin_menu_styles' ); @@ -67,6 +69,11 @@ public function admin_styles() { wp_enqueue_style( 'woocommerce_admin_print_reports_styles' ); } + // Privacy Policy Guide css for back-compat. + if ( in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) { + wp_enqueue_style( 'woocommerce_admin_privacy_styles' ); + } + // @deprecated 2.3. if ( has_action( 'woocommerce_admin_css' ) ) { do_action( 'woocommerce_admin_css' ); From a1ea941947c463925af9d710eed1b46db3049fa6 Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Thu, 2 Apr 2020 13:10:50 -0700 Subject: [PATCH 016/115] Updated CSS to use branch-5 instead of branch-5-0 after testing. Updated check to include privacy.css to account for core#43895 which reorganized the privacy files. --- assets/css/privacy.scss | 4 ++-- includes/admin/class-wc-admin-assets.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/css/privacy.scss b/assets/css/privacy.scss index 7778a12a608f2..bf0f1ed220fcf 100644 --- a/assets/css/privacy.scss +++ b/assets/css/privacy.scss @@ -29,8 +29,8 @@ // Pre-5.4 support for italics. .branch-4-9 .wp-suggested-text ul, .branch-4-9 .wp-suggested-text ol, -.branch-5-0 .wp-suggested-text ul, -.branch-5-0 .wp-suggested-text ol, +.branch-5 .wp-suggested-text ul, +.branch-5 .wp-suggested-text ol, .branch-5-1 .wp-suggested-text ul, .branch-5-1 .wp-suggested-text ol, .branch-5-2 .wp-suggested-text ul, diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index 8cb5978409f9f..bd4863136ffb5 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -70,7 +70,7 @@ public function admin_styles() { } // Privacy Policy Guide css for back-compat. - if ( in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) { + if ( isset( $_GET['wp-privacy-policy-guide'] ) || in_array( $screen_id, array( 'privacy-policy-guide' ) ) ) { wp_enqueue_style( 'woocommerce_admin_privacy_styles' ); } From af288e6ae1b8bd53493942552c3ede19018b8d03 Mon Sep 17 00:00:00 2001 From: Yoav Farhi Date: Sun, 5 Apr 2020 10:59:32 +0300 Subject: [PATCH 017/115] make sure the woocommerce-helper rtl css file is loaded --- includes/admin/helper/class-wc-helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 42500a0b983d4..aba21fbc4d4b9 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -471,6 +471,7 @@ public static function admin_enqueue_scripts() { if ( $wc_screen_id . '_page_wc-addons' === $screen_id && isset( $_GET['section'] ) && 'helper' === $_GET['section'] ) { wp_enqueue_style( 'woocommerce-helper', WC()->plugin_url() . '/assets/css/helper.css', array(), Constants::get_constant( 'WC_VERSION' ) ); + wp_style_add_data( 'woocommerce-helper', 'rtl', 'replace' ); } } From 60b7b42f23ffa039b5d654f4d379f9088d7c9360 Mon Sep 17 00:00:00 2001 From: Garrett Hyder Date: Tue, 7 Apr 2020 10:28:22 -0700 Subject: [PATCH 018/115] Remove support for pre-5.2 WP, also update wp-suggested-text to use .policy-text for better plugin support. --- assets/css/privacy.scss | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/assets/css/privacy.scss b/assets/css/privacy.scss index bf0f1ed220fcf..4636aca879bff 100644 --- a/assets/css/privacy.scss +++ b/assets/css/privacy.scss @@ -9,34 +9,24 @@ */ // Support for indented bullet-lists. -.wp-suggested-text ul, .policy-text ul { list-style: disc; } -.wp-suggested-text ol, .policy-text ol { list-style: decimal; } -.wp-suggested-text ul li, -.wp-suggested-text ol li, .policy-text ul li, .policy-text ol li { margin-left: 2em; } // Pre-5.4 support for italics. -.branch-4-9 .wp-suggested-text ul, -.branch-4-9 .wp-suggested-text ol, -.branch-5 .wp-suggested-text ul, -.branch-5 .wp-suggested-text ol, -.branch-5-1 .wp-suggested-text ul, -.branch-5-1 .wp-suggested-text ol, -.branch-5-2 .wp-suggested-text ul, -.branch-5-2 .wp-suggested-text ol, -.branch-5-3 .wp-suggested-text ul, -.branch-5-3 .wp-suggested-text ol { +.branch-5-2 .policy-text ul, +.branch-5-2 .policy-text ol, +.branch-5-3 .policy-text ul, +.branch-5-3 .policy-text ol { font-style: italic; } From 4fcb8921d585e36d99e9d8ffe43b072fa8aed9e5 Mon Sep 17 00:00:00 2001 From: Ameen Jalali Date: Wed, 8 Apr 2020 07:28:34 +0430 Subject: [PATCH 019/115] Fix wrong hooked function, issue #25996 --- templates/content-single-product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/content-single-product.php b/templates/content-single-product.php index 0487959388923..edcd3d19741d4 100644 --- a/templates/content-single-product.php +++ b/templates/content-single-product.php @@ -22,7 +22,7 @@ /** * Hook: woocommerce_before_single_product. * - * @hooked wc_print_notices - 10 + * @hooked woocommerce_output_all_notices - 10 */ do_action( 'woocommerce_before_single_product' ); From b234964a1c12e9e9540b4b9edf3febb5d3cb06b2 Mon Sep 17 00:00:00 2001 From: BrandynL Date: Wed, 8 Apr 2020 14:21:00 -0400 Subject: [PATCH 020/115] changed append show-password-span to prepend to fix bug with password strength hint --- assets/js/frontend/woocommerce.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/frontend/woocommerce.js b/assets/js/frontend/woocommerce.js index 6c6047558cd93..1913904b64acf 100644 --- a/assets/js/frontend/woocommerce.js +++ b/assets/js/frontend/woocommerce.js @@ -81,7 +81,7 @@ jQuery( function( $ ) { // Show password visiblity hover icon on woocommerce forms $( '.woocommerce form .woocommerce-Input[type="password"]' ).wrap( '' ); - $( '.password-input' ).append( '' ); + $( '.password-input' ).prepend( '' ); $( '.show-password-input' ).click( function() { From 8e2402292e9a752124e6e8dfde7c1930d00bdf45 Mon Sep 17 00:00:00 2001 From: Marcio Zebedeu Date: Sat, 11 Apr 2020 10:43:52 +0100 Subject: [PATCH 021/115] All provinces/states of Mozambique add this committee proposes to give the ability to make sales in different cities in Mozambique source: https://en.wikipedia.org/wiki/ISO_3166-2:MZ https://en.wikipedia.org/wiki/ISO_3166-2:MZ https://www.mozambiqueinformation.com/provinces-of-mozambique.html --- i18n/states.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/i18n/states.php b/i18n/states.php index 49aa9b6603ac0..cfdded2c1af14 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -828,6 +828,18 @@ 'PJY' => __( 'Putrajaya', 'woocommerce' ), 'KUL' => __( 'Kuala Lumpur', 'woocommerce' ), ), + 'MZ' => array( // Mozambique provinces. + 'MZ-P' => __( 'Cabo Delgado', 'woocommerce' ), + 'MZ-G' => __( 'Gaza', 'woocommerce' ), + 'MZ-I' => __( 'Inhambane', 'woocommerce' ), + 'MZ-B' => __( 'Manica', 'woocommerce' ), + 'MZ-L' => __( 'Maputo', 'woocommerce' ), + 'MZ-N' => __( 'Nampula', 'woocommerce' ), + 'MZ-A' => __( 'Niassa', 'woocommerce' ), + 'MZ-S' => __( 'Sofala', 'woocommerce' ), + 'MZ-T' => __( 'Tete', 'woocommerce' ), + 'MZ-Q' => __( 'Zambézia', 'woocommerce' ), + ), 'NG' => array( // Nigerian provinces. 'AB' => __( 'Abia', 'woocommerce' ), 'FC' => __( 'Abuja', 'woocommerce' ), From b049d29a8aa725a85043c214b444ed0fd007505b Mon Sep 17 00:00:00 2001 From: abhishek-pokhriyal Date: Sat, 11 Apr 2020 19:35:13 +0530 Subject: [PATCH 022/115] Change "though" to "through" --- includes/admin/class-wc-admin-settings.php | 4 ++-- includes/admin/wc-admin-functions.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-wc-admin-settings.php b/includes/admin/class-wc-admin-settings.php index 837ffbc82302e..d8c9d17b0a736 100644 --- a/includes/admin/class-wc-admin-settings.php +++ b/includes/admin/class-wc-admin-settings.php @@ -200,7 +200,7 @@ public static function get_option( $option_name, $default = '' ) { /** * Output admin fields. * - * Loops though the woocommerce options array and outputs each field. + * Loops through the woocommerce options array and outputs each field. * * @param array[] $options Opens array to output. */ @@ -726,7 +726,7 @@ public static function get_field_description( $value ) { /** * Save admin fields. * - * Loops though the woocommerce options array and outputs each field. + * Loops through the woocommerce options array and outputs each field. * * @param array $options Options array to output. * @param array $data Optional. Data to use for saving. Defaults to $_POST. diff --git a/includes/admin/wc-admin-functions.php b/includes/admin/wc-admin-functions.php index 288f34bec0722..57b9b31cb6b83 100644 --- a/includes/admin/wc-admin-functions.php +++ b/includes/admin/wc-admin-functions.php @@ -137,7 +137,7 @@ function wc_create_page( $slug, $option = '', $page_title = '', $page_content = /** * Output admin fields. * - * Loops though the woocommerce options array and outputs each field. + * Loops through the woocommerce options array and outputs each field. * * @param array $options Opens array to output. */ From f83e5d32a46b8f556e1d694b240125f60b87696c Mon Sep 17 00:00:00 2001 From: Fernando Marichal Date: Sun, 12 Apr 2020 13:49:38 -0300 Subject: [PATCH 023/115] Removed legacy notification to connect with WooCommerce Removed legacy JITM for connecting with WooCommerce.com --- includes/admin/helper/class-wc-helper.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 42500a0b983d4..92a39f8fdfc2c 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1527,12 +1527,6 @@ private static function _prompt_helper_connect( $screen_id ) { $active_woo_plugins = array_intersect_key( $woo_plugins, array_flip( $active_plugins ) ); - if ( count( $active_woo_plugins ) > 0 ) { - /* translators: %s: helper screen url */ - $notice = __( 'Connect your store to WooCommerce.com to receive extensions updates and support.', 'woocommerce' ); - $notice = sprintf( $notice, admin_url( 'admin.php?page=wc-addons§ion=helper' ) ); - echo '

    ' . wp_kses_post( $notice ) . '

    '; - } } /** From 134c0ea0db8fd934053906f7c68beedf5af2ea30 Mon Sep 17 00:00:00 2001 From: Fernando Marichal Date: Wed, 15 Apr 2020 13:35:56 -0300 Subject: [PATCH 024/115] The function '_prompt_helper_connect' was deleted After removing the legacy code the method '_prompt_helper_connect' wasn't useful anymore so it was removed. --- includes/admin/helper/class-wc-helper.php | 46 ----------------------- 1 file changed, 46 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 92a39f8fdfc2c..7a7743459a0dc 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1467,8 +1467,6 @@ public static function admin_notices() { $screen = get_current_screen(); $screen_id = $screen ? $screen->id : ''; - self::_prompt_helper_connect( $screen_id ); - if ( 'update-core' !== $screen_id ) { return; } @@ -1485,50 +1483,6 @@ public static function admin_notices() { } } - /** - * Prompt a Helper connection if the user has WooCommerce.com extensions. - * - * @param string $screen_id Current screen ID. - */ - private static function _prompt_helper_connect( $screen_id ) { - if ( apply_filters( 'woocommerce_helper_suppress_connect_notice', false ) ) { - return; - } - - $screens = wc_get_screen_ids(); - $screens[] = 'plugins'; - - if ( ! in_array( $screen_id, $screens, true ) ) { - return; - } - - // Don't show the notice on the Helper screens. - $screen_addons = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ) . '_page_wc-addons'; - - if ( $screen_addons === $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' === $_REQUEST['section'] ) { - return; - } - - // We believe we have an active connection. - $auth = WC_Helper_Options::get( 'auth' ); - if ( ! empty( $auth['access_token'] ) ) { - return; - } - - $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); - if ( empty( $active_plugins ) ) { - return; - } - - $woo_plugins = self::get_local_woo_plugins(); - if ( empty( $woo_plugins ) ) { - return; - } - - $active_woo_plugins = array_intersect_key( $woo_plugins, array_flip( $active_plugins ) ); - - } - /** * Get an update notice if one or more Woo extensions has an update available. * From 5c90b5ecfe20c5fe4db4f83b3b1460e926412680 Mon Sep 17 00:00:00 2001 From: Marcio Zebedeu Date: Wed, 15 Apr 2020 18:10:11 +0100 Subject: [PATCH 025/115] remove hyphen in ISO code --- i18n/states.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/i18n/states.php b/i18n/states.php index cfdded2c1af14..4c416dcd19e8c 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -829,16 +829,17 @@ 'KUL' => __( 'Kuala Lumpur', 'woocommerce' ), ), 'MZ' => array( // Mozambique provinces. - 'MZ-P' => __( 'Cabo Delgado', 'woocommerce' ), - 'MZ-G' => __( 'Gaza', 'woocommerce' ), - 'MZ-I' => __( 'Inhambane', 'woocommerce' ), - 'MZ-B' => __( 'Manica', 'woocommerce' ), - 'MZ-L' => __( 'Maputo', 'woocommerce' ), - 'MZ-N' => __( 'Nampula', 'woocommerce' ), - 'MZ-A' => __( 'Niassa', 'woocommerce' ), - 'MZ-S' => __( 'Sofala', 'woocommerce' ), - 'MZ-T' => __( 'Tete', 'woocommerce' ), - 'MZ-Q' => __( 'Zambézia', 'woocommerce' ), + 'MZP' => __( 'Cabo Delgado', 'woocommerce' ), + 'MZG' => __( 'Gaza', 'woocommerce' ), + 'MZI' => __( 'Inhambane', 'woocommerce' ), + 'MZB' => __( 'Manica', 'woocommerce' ), + 'MZL' => __( 'Maputo Province', 'woocommerce' ), + 'MZMPM' => __( 'Maputo', 'woocommerce' ), + 'MZN' => __( 'Nampula', 'woocommerce' ), + 'MZA' => __( 'Niassa', 'woocommerce' ), + 'MZS' => __( 'Sofala', 'woocommerce' ), + 'MZT' => __( 'Tete', 'woocommerce' ), + 'MZQ' => __( 'Zambézia', 'woocommerce' ), ), 'NG' => array( // Nigerian provinces. 'AB' => __( 'Abia', 'woocommerce' ), From 0eae470c0f96bfedc4175a8aceeb50dc414aa091 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 17 Apr 2020 18:21:29 -0300 Subject: [PATCH 026/115] Added notice to check if uploads directoy is public --- includes/admin/class-wc-admin-notices.php | 42 +++++++++++++++++++ ...tml-notice-uploads-directory-is-public.php | 33 +++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 includes/admin/views/html-notice-uploads-directory-is-public.php diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 59939424c8acb..ec415415ad0d6 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -39,6 +39,7 @@ class WC_Admin_Notices { WC_PHP_MIN_REQUIREMENTS_NOTICE => 'wp_php_min_requirements_notice', 'maxmind_license_key' => 'maxmind_missing_license_key_notice', 'redirect_download_method' => 'redirect_download_method_notice', + 'uploads_directory_is_public' => 'uploads_directory_is_public_notice', ); /** @@ -92,6 +93,7 @@ public static function remove_all_notices() { public static function reset_admin_notices() { if ( ! self::is_ssl() ) { self::add_notice( 'no_secure_connection' ); + self::add_notice( 'uploads_directory_is_public' ); } self::add_notice( 'template_files' ); self::add_min_version_notice(); @@ -488,6 +490,20 @@ public static function redirect_download_method_notice() { include dirname( __FILE__ ) . '/views/html-notice-redirect-only-download.php'; } + /** + * Notice about uploads directory begin public. + * + * @since 4.2.0 + */ + public static function uploads_directory_is_public_notice() { + if ( ! self::is_uploads_directory_is_public() || get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) ) { + self::remove_notice( 'uploads_directory_is_public' ); + return; + } + + include dirname( __FILE__ ) . '/views/html-notice-uploads-directory-is-public.php'; + } + /** * Determine if the store is running SSL. * @@ -530,6 +546,32 @@ public static function simplify_commerce_notice() { public static function theme_check_notice() { wc_deprecated_function( 'WC_Admin_Notices::theme_check_notice', '3.3.0' ); } + + /** + * Check if uploads directory is public. + * + * @since 4.2.0 + * @return bool + */ + protected static function is_uploads_directory_is_public() { + $uploads = wp_upload_dir( null, true ); + + // Skip if returns an error. + if ( $uploads['error'] ) { + return true; + } + + // Check for uploads root. + $baseurl_response = wp_safe_remote_get( $uploads['baseurl'] ); + $baseurl_code = intval( wp_remote_retrieve_response_code( $baseurl_response ) ); + + // Check for latest uploads sub directory. + // Double check in case the uploads root is only protected by an index.php or index.html file. + $url_response = wp_safe_remote_get( $uploads['url'] ); + $url_code = intval( wp_remote_retrieve_response_code( $url_response ) ); + + return 200 === $baseurl_code && 200 === $url_code; + } } WC_Admin_Notices::init(); diff --git a/includes/admin/views/html-notice-uploads-directory-is-public.php b/includes/admin/views/html-notice-uploads-directory-is-public.php new file mode 100644 index 0000000000000..1b5f05894278f --- /dev/null +++ b/includes/admin/views/html-notice-uploads-directory-is-public.php @@ -0,0 +1,33 @@ + +
    + + +

    + %1$s) is public. We highly recommend serving your entire website over an HTTPS connection to help keep customer data secure. Learn more here.', 'woocommerce' ), + $uploads['basedir'], + 'https://docs.woocommerce.com/document/ssl-and-https/' + ) + ); + ?> +

    +
    From 67a0a68689e2b852abd58e4b46ab38863c7a548c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 17 Apr 2020 18:39:15 -0300 Subject: [PATCH 027/115] Fixed uploads_directory_is_public trigger --- includes/admin/class-wc-admin-notices.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index ec415415ad0d6..47b5eea7a9130 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -93,6 +93,8 @@ public static function remove_all_notices() { public static function reset_admin_notices() { if ( ! self::is_ssl() ) { self::add_notice( 'no_secure_connection' ); + } + if ( ! self::is_uploads_directory_is_public() ) { self::add_notice( 'uploads_directory_is_public' ); } self::add_notice( 'template_files' ); From a5d03828f4903c84b60bad1d7eb5f0e32114fcc0 Mon Sep 17 00:00:00 2001 From: Slavic Dragovtev Date: Wed, 22 Apr 2020 20:19:50 +0300 Subject: [PATCH 028/115] Fix DocBlock in email template Fixes issue [#26244](https://github.com/woocommerce/woocommerce/issues/26244) --- templates/emails/plain/email-customer-details.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/emails/plain/email-customer-details.php b/templates/emails/plain/email-customer-details.php index d9f9672b7290f..f5b0ebf91f0fc 100644 --- a/templates/emails/plain/email-customer-details.php +++ b/templates/emails/plain/email-customer-details.php @@ -4,7 +4,7 @@ * * This is extra customer data which can be filtered by plugins. It outputs below the order item table. * - * This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/email-addresses.php. + * This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/email-customer-details.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to From dfee6ab2e4dcd5843e8d3d5a9f6d446efb3c1c15 Mon Sep 17 00:00:00 2001 From: xristos3490 Date: Wed, 22 Apr 2020 23:32:26 +0300 Subject: [PATCH 029/115] Add body class and change styles --- assets/css/admin.scss | 10 +++++----- assets/css/wc-setup.scss | 4 ++-- includes/admin/class-wc-admin.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 67ae21ee00f78..b78e3429fa021 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -637,7 +637,7 @@ mark.amount { } } -.branch-5-3 { +.wc-wp-version-gte-53 { .woocommerce-help-tip { font-size: 1.2em; @@ -2167,7 +2167,7 @@ ul.wc_coupon_list_block { } } -.branch-5-3 { +.wc-wp-version-gte-53 { .widefat { @@ -4123,7 +4123,7 @@ img.help_tip { } } -.branch-5-3 { +.wc-wp-version-gte-53 { .woocommerce { @@ -6694,7 +6694,7 @@ table.bar_chart { min-width: 400px !important; } -.branch-5-3 { +.wc-wp-version-gte-53 { .select2-results { @@ -6831,7 +6831,7 @@ table.bar_chart { @each $name, $color in $wp_admin_colors { - &-#{$name}.branch-5-3 { + &-#{$name}.wc-wp-version-gte-53 { .select2-dropdown { border-color: $color; diff --git a/assets/css/wc-setup.scss b/assets/css/wc-setup.scss index d6d26e38f32d8..ccb0f2691d1b2 100644 --- a/assets/css/wc-setup.scss +++ b/assets/css/wc-setup.scss @@ -1185,7 +1185,7 @@ h3.jetpack-reasons { } .branch-5-2, -.branch-5-3 { +.wc-wp-version-gte-53 { .location-input { margin: 0; @@ -1415,7 +1415,7 @@ p.jetpack-terms { } .branch-5-2, -.branch-5-3 { +.wc-wp-version-gte-53 { .wc-wizard-service-setting-stripe_create_account, .wc-wizard-service-setting-ppec_paypal_reroute_requests { diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 23d27e5bd736b..a5f7fd7c79e1f 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -33,6 +33,9 @@ public function __construct() { // Disable WXR export of schedule action posts. add_filter( 'action_scheduler_post_type_args', array( $this, 'disable_webhook_post_export' ) ); + + // Add body class for WP 5.3+ compatibility. + add_filter( 'admin_body_class', array( $this, 'include_admin_body_classes' ) ); } /** @@ -306,6 +309,32 @@ public function disable_webhook_post_export( $args ) { $args['can_export'] = false; return $args; } + + /** + * Include admin classes. + * + * @since 4.1.1 + * + * @param String $classes + * @return String + */ + public function include_admin_body_classes( $classes ) { + + // Add WP 5.3+ compatibility class. + if ( strpos( $classes, 'wc-wp-version-gte-53' ) !== false ) { + return $classes; + } + + global $wp_version; + $version_parts = explode( '-', $wp_version ); + $version = sizeof( $version_parts ) > 1 ? $version_parts[ 0 ] : $wp_version; + + if ( $wp_version && version_compare( $version, '5.3', '>=' ) ) { + $classes .= ' wc-wp-version-gte-53'; + } + + return $classes; + } } return new WC_Admin(); From b6b6bba1a0335f368dabd7c68b15ff2e2aabec4a Mon Sep 17 00:00:00 2001 From: xristos3490 Date: Thu, 23 Apr 2020 01:17:40 +0300 Subject: [PATCH 030/115] minor updates --- includes/admin/class-wc-admin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index a5f7fd7c79e1f..704a33acf350e 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -318,17 +318,17 @@ public function disable_webhook_post_export( $args ) { * @param String $classes * @return String */ - public function include_admin_body_classes( $classes ) { + public function include_admin_body_class( $classes ) { - // Add WP 5.3+ compatibility class. - if ( strpos( $classes, 'wc-wp-version-gte-53' ) !== false ) { + if ( false !== strpos( $classes, 'wc-wp-version-gte-53' ) ) { return $classes; } global $wp_version; $version_parts = explode( '-', $wp_version ); - $version = sizeof( $version_parts ) > 1 ? $version_parts[ 0 ] : $wp_version; + $version = count( $version_parts ) > 1 ? $version_parts[0] : $wp_version; + // Add WP 5.3+ compatibility class. if ( $wp_version && version_compare( $version, '5.3', '>=' ) ) { $classes .= ' wc-wp-version-gte-53'; } From f43426c46e4d8b70ca22cc068011cbc2ab8308e7 Mon Sep 17 00:00:00 2001 From: xristos3490 Date: Thu, 23 Apr 2020 01:19:27 +0300 Subject: [PATCH 031/115] Fix typo --- includes/admin/class-wc-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 704a33acf350e..5d1e4d885a9a5 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -35,7 +35,7 @@ public function __construct() { add_filter( 'action_scheduler_post_type_args', array( $this, 'disable_webhook_post_export' ) ); // Add body class for WP 5.3+ compatibility. - add_filter( 'admin_body_class', array( $this, 'include_admin_body_classes' ) ); + add_filter( 'admin_body_class', array( $this, 'include_admin_body_class' ) ); } /** From cab7c5b8a1cd26781052d224e05d313e70218c99 Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Fri, 24 Apr 2020 00:23:30 +0100 Subject: [PATCH 032/115] hide postcode field for Ghana addresses --- includes/class-wc-countries.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index fb8e34c69ee9e..c7451b95c961e 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -944,6 +944,16 @@ public function get_country_locale() { 'required' => false, ), ), + 'GH' => array( + 'postcode' => array( + 'label' => __( 'Postcode', 'woocommerce' ), + 'required' => false, + 'hidden' => true, + ), + 'state' => array( + 'label' => __( 'State', 'woocommerce' ), + ), + ), 'GP' => array( 'state' => array( 'required' => false, From 972c4eabf154bfbe103f130679131aaacf179839 Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Fri, 24 Apr 2020 01:52:44 +0100 Subject: [PATCH 033/115] add ghana regions/states --- i18n/states.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/i18n/states.php b/i18n/states.php index 49aa9b6603ac0..8248ae0f5db42 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -349,6 +349,24 @@ ), 'FI' => array(), 'FR' => array(), + 'GH' => array( + 'AF' => __('Ahafo', 'woocommerce'), + 'AH' => __('Ashanti', 'woocommerce'), + 'BO' => __('Bono', 'woocommerce'), + 'BE' => __('Bono East', 'woocommerce'), + 'CP' => __('Central', 'woocommerce'), + 'EP' => __('Eastern', 'woocommerce'), + 'AA' => __('Greater Accra', 'woocommerce'), + 'NE' => __('North East', 'woocommerce'), + 'NP' => __('Northern', 'woocommerce'), + 'OT' => __('Oti', 'woocommerce'), + 'SV' => __('Savannah', 'woocommerce'), + 'UE' => __('Upper East', 'woocommerce'), + 'UW' => __('Upper West', 'woocommerce'), + 'TV' => __('Volta', 'woocommerce'), + 'WP' => __('Western', 'woocommerce'), + 'WN' => __('Western North', 'woocommerce'), + ), 'GP' => array(), 'GR' => array( // Greek Regions. 'I' => __( 'Αττική', 'woocommerce' ), From 43db909665c2663525502a032841743f475b268a Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Fri, 24 Apr 2020 10:08:11 +0100 Subject: [PATCH 034/115] removed postcode label and changed state label --- includes/class-wc-countries.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index c7451b95c961e..33b0137a340b3 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -946,12 +946,11 @@ public function get_country_locale() { ), 'GH' => array( 'postcode' => array( - 'label' => __( 'Postcode', 'woocommerce' ), 'required' => false, 'hidden' => true, ), 'state' => array( - 'label' => __( 'State', 'woocommerce' ), + 'label' => __( 'Region', 'woocommerce' ), ), ), 'GP' => array( From 968fbe02289500d1444807e2ad3f913c49d9d67a Mon Sep 17 00:00:00 2001 From: abhishek-pokhriyal Date: Sun, 26 Apr 2020 16:01:40 +0530 Subject: [PATCH 035/115] Correct argument count for action hooked on `woocommerce_process_shop_order_meta` --- includes/admin/class-wc-admin-meta-boxes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-wc-admin-meta-boxes.php b/includes/admin/class-wc-admin-meta-boxes.php index dd50c90d3a52c..32e037975916f 100644 --- a/includes/admin/class-wc-admin-meta-boxes.php +++ b/includes/admin/class-wc-admin-meta-boxes.php @@ -49,9 +49,9 @@ public function __construct() { * Save order data - also updates status and sends out admin emails if needed. Last to show latest data. * Save actions - sends out other emails. Last to show latest data. */ - add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Items::save', 10, 2 ); + add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Items::save', 10 ); add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Downloads::save', 30, 2 ); - add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2 ); + add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40 ); add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Actions::save', 50, 2 ); // Save Product Meta Boxes. From a151c110422e3b966f2fa9cf0683491167fd3b26 Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Mon, 27 Apr 2020 16:53:51 +0100 Subject: [PATCH 036/115] made postcode field visible but not required --- includes/class-wc-countries.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 33b0137a340b3..16ae7b49f3430 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -947,7 +947,6 @@ public function get_country_locale() { 'GH' => array( 'postcode' => array( 'required' => false, - 'hidden' => true, ), 'state' => array( 'label' => __( 'Region', 'woocommerce' ), From 07eef2d717c21fd532156862b369bf457fb276f8 Mon Sep 17 00:00:00 2001 From: Susanna <8512388+vandekul@users.noreply.github.com> Date: Mon, 27 Apr 2020 18:31:52 +0200 Subject: [PATCH 037/115] Fix matching zones query for working with sqlite And probably other databases too. --- includes/data-stores/class-wc-shipping-zone-data-store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-shipping-zone-data-store.php b/includes/data-stores/class-wc-shipping-zone-data-store.php index e4a55322bef2f..453ec877f15b0 100644 --- a/includes/data-stores/class-wc-shipping-zone-data-store.php +++ b/includes/data-stores/class-wc-shipping-zone-data-store.php @@ -282,7 +282,7 @@ public function get_zone_id_from_package( $package ) { "SELECT zones.zone_id FROM {$wpdb->prefix}woocommerce_shipping_zones as zones LEFT OUTER JOIN {$wpdb->prefix}woocommerce_shipping_zone_locations as locations ON zones.zone_id = locations.zone_id AND location_type != 'postcode' WHERE " . implode( ' ', $criteria ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared - . ' ORDER BY zone_order ASC, zone_id ASC LIMIT 1' + . ' ORDER BY zone_order ASC, zones.zone_id ASC LIMIT 1' ); } From 7750a44da00c03c0fdf41abb7bdf6b857caeabb2 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 27 Apr 2020 20:08:08 -0300 Subject: [PATCH 038/115] Allow generate pot as a root user --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 85d4e1443388c..c907f960be9d0 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "phpcbf -p" ], "makepot-audit": [ - "wp i18n make-pot . --exclude=\".github,.wordpress-org,bin,sample-data,node_modules,tests\" --slug=woocommerce" + "wp --allow-root i18n make-pot . --exclude=\".github,.wordpress-org,bin,sample-data,node_modules,tests\" --slug=woocommerce" ], "makepot": [ "@makepot-audit --skip-audit" From e4e63e95bd3b19e65a2c69c1e447d84f7f280d9a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 27 Apr 2020 20:08:41 -0300 Subject: [PATCH 039/115] Introduced .distignore file and updated .gitignore --- .distignore | 26 ++++++++++++++++++++++++++ .gitignore | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 .distignore diff --git a/.distignore b/.distignore new file mode 100644 index 0000000000000..c43c7b91ef8bb --- /dev/null +++ b/.distignore @@ -0,0 +1,26 @@ +.* +.*/ +*.lock +*.md +*.zip +apigen.neon +apigen/ +babel.config.js +bin/ +build/ +CHANGELOG.txt +composer.* +docker-compose.yaml +Dockerfile +Gruntfile.js +node_modules/ +none +package-lock.json +package.json +packages/woocommerce-admin/docs +phpcs.xml +phpunit.xml +phpunit.xml.dist +README.md +renovate.json +tests diff --git a/.gitignore b/.gitignore index 9b99f73835d6d..d5697305442f0 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,6 @@ contributors.md # Language files i18n/languages/woocommerce.pot + +# Build +build/ From 5dc20e9fc8592cf813adf8d8183411996c7e2e07 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 27 Apr 2020 20:09:29 -0300 Subject: [PATCH 040/115] Introduced build release workflow --- .github/workflows/build-release.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/build-release.yml diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000000000..543cc4e540191 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,25 @@ +name: Build release asset +on: + release: + types: [published] +jobs: + build: + name: Build release asset + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build + id: build + uses: woocommerce/woocommerce-build-action@master + with: + generate-zip: true + - name: Upload release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ steps.build.outputs.zip_path }} + asset_name: ${{ github.event.repository.name }}.zip + asset_content_type: application/zip From f7a1ccafce117548d9aaf96e0da2486dd87fac6d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 27 Apr 2020 20:18:38 -0300 Subject: [PATCH 041/115] Remove apigen --- .distignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.distignore b/.distignore index c43c7b91ef8bb..e27e472d6168b 100644 --- a/.distignore +++ b/.distignore @@ -3,8 +3,6 @@ *.lock *.md *.zip -apigen.neon -apigen/ babel.config.js bin/ build/ From 5c2bf5f2b4bc4ee8bc881f68173f2025513173dd Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 28 Apr 2020 11:52:16 -0300 Subject: [PATCH 042/115] Make sure the zip file is called woocommerce.zip --- .github/workflows/build-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 543cc4e540191..45581a28126d9 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -21,5 +21,5 @@ jobs: with: upload_url: ${{ github.event.release.upload_url }} asset_path: ${{ steps.build.outputs.zip_path }} - asset_name: ${{ github.event.repository.name }}.zip + asset_name: woocommerce.zip asset_content_type: application/zip From e4d6d0545fafba9171f955543b2deb359c3878d3 Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Wed, 29 Apr 2020 15:55:43 +0100 Subject: [PATCH 043/115] adjusted to meet coding standards --- i18n/states.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/i18n/states.php b/i18n/states.php index 8248ae0f5db42..bf79bbf29d0be 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -349,23 +349,23 @@ ), 'FI' => array(), 'FR' => array(), - 'GH' => array( - 'AF' => __('Ahafo', 'woocommerce'), - 'AH' => __('Ashanti', 'woocommerce'), - 'BO' => __('Bono', 'woocommerce'), - 'BE' => __('Bono East', 'woocommerce'), - 'CP' => __('Central', 'woocommerce'), - 'EP' => __('Eastern', 'woocommerce'), - 'AA' => __('Greater Accra', 'woocommerce'), - 'NE' => __('North East', 'woocommerce'), - 'NP' => __('Northern', 'woocommerce'), - 'OT' => __('Oti', 'woocommerce'), - 'SV' => __('Savannah', 'woocommerce'), - 'UE' => __('Upper East', 'woocommerce'), - 'UW' => __('Upper West', 'woocommerce'), - 'TV' => __('Volta', 'woocommerce'), - 'WP' => __('Western', 'woocommerce'), - 'WN' => __('Western North', 'woocommerce'), + 'GH' => array( // Ghanaian Regions + 'AF' => __( 'Ahafo', 'woocommerce' ), + 'AH' => __( 'Ashanti', 'woocommerce' ), + 'BO' => __( 'Bono', 'woocommerce' ), + 'BE' => __( 'Bono East', 'woocommerce' ), + 'CP' => __( 'Central', 'woocommerce' ), + 'EP' => __( 'Eastern', 'woocommerce' ), + 'AA' => __( 'Greater Accra', 'woocommerce' ), + 'NE' => __( 'North East', 'woocommerce' ), + 'NP' => __( 'Northern', 'woocommerce' ), + 'OT' => __( 'Oti', 'woocommerce' ), + 'SV' => __( 'Savannah', 'woocommerce' ), + 'UE' => __( 'Upper East', 'woocommerce' ), + 'UW' => __( 'Upper West', 'woocommerce' ), + 'TV' => __( 'Volta', 'woocommerce' ), + 'WP' => __( 'Western', 'woocommerce' ), + 'WN' => __( 'Western North', 'woocommerce' ), ), 'GP' => array(), 'GR' => array( // Greek Regions. From 516d6f937216fc39da00398ad802de7fefc8a1a5 Mon Sep 17 00:00:00 2001 From: tolu-paystack Date: Wed, 29 Apr 2020 16:44:15 +0100 Subject: [PATCH 044/115] added 2 new Ghanaian regions --- i18n/states.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/i18n/states.php b/i18n/states.php index bf79bbf29d0be..bbed3288419f6 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -349,9 +349,11 @@ ), 'FI' => array(), 'FR' => array(), - 'GH' => array( // Ghanaian Regions + 'GH' => array( // Ghanaian Regions. 'AF' => __( 'Ahafo', 'woocommerce' ), 'AH' => __( 'Ashanti', 'woocommerce' ), + 'AV' => __( 'Avannaata Kommunia', 'woocommerce' ), + 'BA' => __( 'Brong-Ahafo', 'woocommerce' ), 'BO' => __( 'Bono', 'woocommerce' ), 'BE' => __( 'Bono East', 'woocommerce' ), 'CP' => __( 'Central', 'woocommerce' ), From c5eb5545ea3acfdd578460f9b96b8115ade68067 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 29 Apr 2020 13:35:11 -0300 Subject: [PATCH 045/115] Updated build package name --- .github/workflows/build-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 45581a28126d9..3cfefb166e201 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -11,7 +11,7 @@ jobs: uses: actions/checkout@v2 - name: Build id: build - uses: woocommerce/woocommerce-build-action@master + uses: woocommerce/action-build@master with: generate-zip: true - name: Upload release asset From 09b55f7390fdbe02457bb72becda2989456bf324 Mon Sep 17 00:00:00 2001 From: xristos3490 Date: Thu, 30 Apr 2020 11:04:40 +0300 Subject: [PATCH 046/115] fix CS on docblock --- includes/admin/class-wc-admin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 5d1e4d885a9a5..46ea9bc57539c 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -313,9 +313,10 @@ public function disable_webhook_post_export( $args ) { /** * Include admin classes. * - * @since 4.1.1 + * @since 4.1.1 + * + * @param String $classes * - * @param String $classes * @return String */ public function include_admin_body_class( $classes ) { From cb9dc9ed44af4323f4d5d64d0c7d9e9e86b10b0c Mon Sep 17 00:00:00 2001 From: xristos3490 Date: Thu, 30 Apr 2020 11:34:01 +0300 Subject: [PATCH 047/115] Add param doc comment --- includes/admin/class-wc-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 46ea9bc57539c..af6f46edcb03d 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -315,7 +315,7 @@ public function disable_webhook_post_export( $args ) { * * @since 4.1.1 * - * @param String $classes + * @param String $classes Body classes string. * * @return String */ From 57e2e829612fc6295b8485990823063045ecd0f5 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Fri, 1 May 2020 21:14:21 +0530 Subject: [PATCH 048/115] Clear plugin cache if WC header are not present to load with WC headers. WC headers are added in filter `extra_plugin_headers`, however, in case when WooCommerce is activated/updated, `get_plugins` will be called and cache will be set before this filter can be cached. Also, `get_plugins` call is expensive even with update cache present, so we should clear it very conservatively. --- includes/admin/helper/class-wc-helper.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index e131b8e52e58a..d6a72f1d0033f 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1149,9 +1149,17 @@ public static function get_local_woo_plugins() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - // Reset plugin cache before retrieving plugin list. - wp_clean_plugins_cache(); - $plugins = get_plugins(); + $plugins = get_plugins(); + + /** + * Check if plugins have WC headers, if not then clear cache and fetch again. + * WC Headers will not be present if `wc_enable_wc_plugin_headers` hook was added after a `get_plugins` call. + */ + $first_plugin = array_keys( $plugins )[0]; + if ( $first_plugin && ! array_key_exists( 'Woo', $plugins[ $first_plugin ] ) ) { + wp_clean_plugins_cache( false ); + $plugins = get_plugins(); + } $woo_plugins = array(); // Backwards compatibility for woothemes_queue_update(). From e97fd683c6502ab0deac1f91a13abb6cbbcb4e7c Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Fri, 1 May 2020 21:19:25 +0530 Subject: [PATCH 049/115] Add extra comments --- includes/admin/helper/class-wc-helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index d6a72f1d0033f..bb889a8ddf5be 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1153,13 +1153,15 @@ public static function get_local_woo_plugins() { /** * Check if plugins have WC headers, if not then clear cache and fetch again. - * WC Headers will not be present if `wc_enable_wc_plugin_headers` hook was added after a `get_plugins` call. + * WC Headers will not be present if `wc_enable_wc_plugin_headers` hook was added after a `get_plugins` call -- for example when WC is activated/updated. + * Also, get_plugins call is expensive so we should clear this cache very conservatively. */ $first_plugin = array_keys( $plugins )[0]; if ( $first_plugin && ! array_key_exists( 'Woo', $plugins[ $first_plugin ] ) ) { wp_clean_plugins_cache( false ); $plugins = get_plugins(); } + $woo_plugins = array(); // Backwards compatibility for woothemes_queue_update(). From 13dfb8180fb9ee2541d0f6d09ff6b55a281951e2 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Fri, 1 May 2020 22:47:08 +0530 Subject: [PATCH 050/115] Add unit test and a sample Woo plugin file --- sample-woo-plugin.php | 6 ++++ tests/legacy/bootstrap.php | 9 +++++ tests/legacy/data/sample-woo-plugin.php | 6 ++++ .../admin/helper/class-tests-wc-helper.php | 33 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 sample-woo-plugin.php create mode 100644 tests/legacy/data/sample-woo-plugin.php create mode 100644 tests/php/includes/admin/helper/class-tests-wc-helper.php diff --git a/sample-woo-plugin.php b/sample-woo-plugin.php new file mode 100644 index 0000000000000..2810783a3cf6c --- /dev/null +++ b/sample-woo-plugin.php @@ -0,0 +1,6 @@ +plugin_dir = dirname( dirname( $this->tests_dir ) ); $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; + if ( ! defined( 'WP_PLUGIN_DIR' ) ) { + define( 'WP_PLUGIN_DIR', $this->plugin_dir ); + } + + if ( file_exists( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ) ) { + unlink( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); + } + copy( __DIR__ . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); + // load test function so tests_add_filter() is available. require_once $this->wp_tests_dir . '/includes/functions.php'; diff --git a/tests/legacy/data/sample-woo-plugin.php b/tests/legacy/data/sample-woo-plugin.php new file mode 100644 index 0000000000000..2810783a3cf6c --- /dev/null +++ b/tests/legacy/data/sample-woo-plugin.php @@ -0,0 +1,6 @@ +assertArrayHasKey( $woocommerce_key, $woo_plugins ); + } + +} From 28fd8850fa84b42d38d116e7aed35c9d0d537322 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Fri, 1 May 2020 23:16:32 +0530 Subject: [PATCH 051/115] Deleted accidently added file --- sample-woo-plugin.php | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 sample-woo-plugin.php diff --git a/sample-woo-plugin.php b/sample-woo-plugin.php deleted file mode 100644 index 2810783a3cf6c..0000000000000 --- a/sample-woo-plugin.php +++ /dev/null @@ -1,6 +0,0 @@ - Date: Sat, 2 May 2020 00:27:17 +0530 Subject: [PATCH 052/115] Moved test specific logic from bootstrap to test file --- tests/legacy/bootstrap.php | 9 --------- .../php/includes/admin/helper/class-tests-wc-helper.php | 5 +++++ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/legacy/bootstrap.php b/tests/legacy/bootstrap.php index f841d0660deba..c0a91df0ec384 100644 --- a/tests/legacy/bootstrap.php +++ b/tests/legacy/bootstrap.php @@ -44,15 +44,6 @@ public function __construct() { $this->plugin_dir = dirname( dirname( $this->tests_dir ) ); $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; - if ( ! defined( 'WP_PLUGIN_DIR' ) ) { - define( 'WP_PLUGIN_DIR', $this->plugin_dir ); - } - - if ( file_exists( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ) ) { - unlink( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); - } - copy( __DIR__ . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); - // load test function so tests_add_filter() is available. require_once $this->wp_tests_dir . '/includes/functions.php'; diff --git a/tests/php/includes/admin/helper/class-tests-wc-helper.php b/tests/php/includes/admin/helper/class-tests-wc-helper.php index 2ebc01b581bad..8778c48773f4f 100644 --- a/tests/php/includes/admin/helper/class-tests-wc-helper.php +++ b/tests/php/includes/admin/helper/class-tests-wc-helper.php @@ -20,6 +20,11 @@ public function test_get_local_woo_plugins_without_woo_header_cache() { wp_clean_plugins_cache( false ); get_plugins(); + if ( file_exists( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ) ) { + unlink( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); + } + copy( WC_Unit_Tests_Bootstrap::instance()->tests_dir . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); + add_filter( 'extra_plugin_headers', 'wc_enable_wc_plugin_headers' ); $woo_plugins = WC_Helper::get_local_woo_plugins(); From 62ef1699407655e66fb3cc00e9580fa6d49966f1 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Sat, 2 May 2020 00:30:25 +0530 Subject: [PATCH 053/115] Simplified logic for better readability. --- includes/admin/helper/class-wc-helper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index bb889a8ddf5be..b9aa440daec7f 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1156,8 +1156,7 @@ public static function get_local_woo_plugins() { * WC Headers will not be present if `wc_enable_wc_plugin_headers` hook was added after a `get_plugins` call -- for example when WC is activated/updated. * Also, get_plugins call is expensive so we should clear this cache very conservatively. */ - $first_plugin = array_keys( $plugins )[0]; - if ( $first_plugin && ! array_key_exists( 'Woo', $plugins[ $first_plugin ] ) ) { + if ( ! empty( $plugins ) && ! array_key_exists( 'Woo', current( $plugins ) ) ) { wp_clean_plugins_cache( false ); $plugins = get_plugins(); } From c38e059ce87addfea8a6ea58e7e5183402a9510f Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 1 May 2020 13:49:55 -0700 Subject: [PATCH 054/115] Pass $customer to woocommerce_match_rates hook. This allows tax related plugins to get more data on the customer and make better decisions on the correct tax rate to apply. Fixes #25787 --- includes/class-wc-tax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 53b9cabc18a70..a7784c3e70218 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -495,7 +495,7 @@ public static function get_rates( $tax_class = '', $customer = null ) { ); } - return apply_filters( 'woocommerce_matched_rates', $matched_tax_rates, $tax_class ); + return apply_filters( 'woocommerce_matched_rates', $matched_tax_rates, $tax_class, $customer ); } /** From 15f71015e60238f1d89d27c4e47d4356c2f4abd8 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 4 May 2020 22:11:02 -0300 Subject: [PATCH 055/115] Improved method naming --- includes/admin/class-wc-admin-notices.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 47b5eea7a9130..56612d7b8810c 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -94,7 +94,7 @@ public static function reset_admin_notices() { if ( ! self::is_ssl() ) { self::add_notice( 'no_secure_connection' ); } - if ( ! self::is_uploads_directory_is_public() ) { + if ( ! self::is_uploads_directory_public() ) { self::add_notice( 'uploads_directory_is_public' ); } self::add_notice( 'template_files' ); @@ -498,7 +498,7 @@ public static function redirect_download_method_notice() { * @since 4.2.0 */ public static function uploads_directory_is_public_notice() { - if ( ! self::is_uploads_directory_is_public() || get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) ) { + if ( ! self::is_uploads_directory_public() || get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) ) { self::remove_notice( 'uploads_directory_is_public' ); return; } @@ -555,7 +555,7 @@ public static function theme_check_notice() { * @since 4.2.0 * @return bool */ - protected static function is_uploads_directory_is_public() { + protected static function is_uploads_directory_public() { $uploads = wp_upload_dir( null, true ); // Skip if returns an error. From 54625f97121504f4460b4a8528429fecb8e32332 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 4 May 2020 22:11:56 -0300 Subject: [PATCH 056/115] Fixed check --- includes/admin/class-wc-admin-notices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 56612d7b8810c..0c597d49d1d8f 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -572,7 +572,7 @@ protected static function is_uploads_directory_public() { $url_response = wp_safe_remote_get( $uploads['url'] ); $url_code = intval( wp_remote_retrieve_response_code( $url_response ) ); - return 200 === $baseurl_code && 200 === $url_code; + return 200 === $baseurl_code || 200 === $url_code; } } From fdea6de3478b1ad52cb006abe30bdb5bc9fda9bc Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 4 May 2020 22:12:24 -0300 Subject: [PATCH 057/115] Check for user meta data first --- includes/admin/class-wc-admin-notices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 0c597d49d1d8f..85b638b1fc523 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -498,7 +498,7 @@ public static function redirect_download_method_notice() { * @since 4.2.0 */ public static function uploads_directory_is_public_notice() { - if ( ! self::is_uploads_directory_public() || get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) ) { + if ( get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) || ! self::is_uploads_directory_public() ) { self::remove_notice( 'uploads_directory_is_public' ); return; } From 040944fda630e73ff61561c846efa35192dc9321 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 4 May 2020 22:20:03 -0300 Subject: [PATCH 058/115] Updated notice --- .../admin/views/html-notice-uploads-directory-is-public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/views/html-notice-uploads-directory-is-public.php b/includes/admin/views/html-notice-uploads-directory-is-public.php index 1b5f05894278f..360d2c2429ce4 100644 --- a/includes/admin/views/html-notice-uploads-directory-is-public.php +++ b/includes/admin/views/html-notice-uploads-directory-is-public.php @@ -23,7 +23,7 @@ echo wp_kses_post( sprintf( /* translators: 1: uploads directory path 2: documentation URL */ - __( 'Your store\'s uploads directory (%1$s) is public. We highly recommend serving your entire website over an HTTPS connection to help keep customer data secure. Learn more here.', 'woocommerce' ), + __( 'Your store\'s uploads directory (%1$s) is public. We highly recommend securing your uploads directory against indexing. Learn more here.', 'woocommerce' ), $uploads['basedir'], 'https://docs.woocommerce.com/document/ssl-and-https/' ) From ae68e160704af8dde9c79a947d4611e5733f685d Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Tue, 5 May 2020 18:50:54 +0530 Subject: [PATCH 059/115] Add back phpcs for legacy because we still want it tested. There are lots of tests in legacy folder which we might update from time to time. Its still a good idea to keep phpcs for the folder. --- phpcs.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index f437ec8b333a5..c8196e3167e02 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -6,7 +6,6 @@ tests/cli/ - tests/legacy/ includes/libraries/ includes/legacy/ includes/api/legacy/ From 27ad4a552e343a176a857f2e1f078310fca78c15 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Tue, 5 May 2020 19:19:37 +0530 Subject: [PATCH 060/115] Rename file and class to resemble PSR4 like convention for consistency. --- .../{class-tests-wc-helper.php => WCHelperTest.php} | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) rename tests/php/includes/admin/helper/{class-tests-wc-helper.php => WCHelperTest.php} (74%) diff --git a/tests/php/includes/admin/helper/class-tests-wc-helper.php b/tests/php/includes/admin/helper/WCHelperTest.php similarity index 74% rename from tests/php/includes/admin/helper/class-tests-wc-helper.php rename to tests/php/includes/admin/helper/WCHelperTest.php index 8778c48773f4f..2580610b15fa8 100644 --- a/tests/php/includes/admin/helper/class-tests-wc-helper.php +++ b/tests/php/includes/admin/helper/WCHelperTest.php @@ -5,10 +5,12 @@ * @package WooCommerce|Tests|WC_Helper. */ +namespace Automattic\WooCommerce; + /** * Class WC_Tests_WC_Helper. */ -class WC_Tests_WC_Helper extends WC_Unit_Test_Case { +class WCHelperTest extends \WC_Unit_Test_Case { /** * Test that woo plugins are loaded correctly even if incorrect cache is intially set. @@ -23,11 +25,11 @@ public function test_get_local_woo_plugins_without_woo_header_cache() { if ( file_exists( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ) ) { unlink( WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); } - copy( WC_Unit_Tests_Bootstrap::instance()->tests_dir . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); + copy( \WC_Unit_Tests_Bootstrap::instance()->tests_dir . '/data/sample-woo-plugin.php', WP_PLUGIN_DIR . '/sample-woo-plugin.php' ); add_filter( 'extra_plugin_headers', 'wc_enable_wc_plugin_headers' ); - $woo_plugins = WC_Helper::get_local_woo_plugins(); + $woo_plugins = \WC_Helper::get_local_woo_plugins(); // Restore previous state. wp_clean_plugins_cache( false ); From a74f06f3379d3cb5bfe44204a1e447095f312a9d Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Tue, 5 May 2020 19:22:21 +0530 Subject: [PATCH 061/115] Add exception for tests/php for filename sniff because it conflicts with PSR4. --- phpcs.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml b/phpcs.xml index c8196e3167e02..b1d14b43537a9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -58,5 +58,6 @@ i18n/ src/ + tests/php From d8b8601601db276548c4bd1a892a127832cd8a22 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 May 2020 14:03:12 -0300 Subject: [PATCH 062/115] Updated uploads directory check and saved results on transients --- includes/admin/class-wc-admin-notices.php | 89 ++++++++++++------- ...tml-notice-uploads-directory-is-public.php | 33 ------- 2 files changed, 59 insertions(+), 63 deletions(-) delete mode 100644 includes/admin/views/html-notice-uploads-directory-is-public.php diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 85b638b1fc523..1c2532eb842d1 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -28,18 +28,18 @@ class WC_Admin_Notices { * @var array */ private static $core_notices = array( - 'install' => 'install_notice', - 'update' => 'update_notice', - 'template_files' => 'template_file_check_notice', - 'legacy_shipping' => 'legacy_shipping_notice', - 'no_shipping_methods' => 'no_shipping_methods_notice', - 'regenerating_thumbnails' => 'regenerating_thumbnails_notice', - 'regenerating_lookup_table' => 'regenerating_lookup_table_notice', - 'no_secure_connection' => 'secure_connection_notice', - WC_PHP_MIN_REQUIREMENTS_NOTICE => 'wp_php_min_requirements_notice', - 'maxmind_license_key' => 'maxmind_missing_license_key_notice', - 'redirect_download_method' => 'redirect_download_method_notice', - 'uploads_directory_is_public' => 'uploads_directory_is_public_notice', + 'install' => 'install_notice', + 'update' => 'update_notice', + 'template_files' => 'template_file_check_notice', + 'legacy_shipping' => 'legacy_shipping_notice', + 'no_shipping_methods' => 'no_shipping_methods_notice', + 'regenerating_thumbnails' => 'regenerating_thumbnails_notice', + 'regenerating_lookup_table' => 'regenerating_lookup_table_notice', + 'no_secure_connection' => 'secure_connection_notice', + WC_PHP_MIN_REQUIREMENTS_NOTICE => 'wp_php_min_requirements_notice', + 'maxmind_license_key' => 'maxmind_missing_license_key_notice', + 'redirect_download_method' => 'redirect_download_method_notice', + 'uploads_directory_is_unprotected' => 'uploads_directory_is_unprotected_notice', ); /** @@ -94,8 +94,8 @@ public static function reset_admin_notices() { if ( ! self::is_ssl() ) { self::add_notice( 'no_secure_connection' ); } - if ( ! self::is_uploads_directory_public() ) { - self::add_notice( 'uploads_directory_is_public' ); + if ( ! self::is_uploads_directory_protected() ) { + self::add_notice( 'uploads_directory_is_unprotected' ); } self::add_notice( 'template_files' ); self::add_min_version_notice(); @@ -493,17 +493,17 @@ public static function redirect_download_method_notice() { } /** - * Notice about uploads directory begin public. + * Notice about uploads directory begin unprotected. * * @since 4.2.0 */ - public static function uploads_directory_is_public_notice() { - if ( get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_public_notice', true ) || ! self::is_uploads_directory_public() ) { - self::remove_notice( 'uploads_directory_is_public' ); + public static function uploads_directory_is_unprotected_notice() { + if ( get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_unprotected_notice', true ) || self::is_uploads_directory_protected() ) { + self::remove_notice( 'uploads_directory_is_unprotected' ); return; } - include dirname( __FILE__ ) . '/views/html-notice-uploads-directory-is-public.php'; + include dirname( __FILE__ ) . '/views/html-notice-uploads-directory-is-unprotected.php'; } /** @@ -550,29 +550,58 @@ public static function theme_check_notice() { } /** - * Check if uploads directory is public. + * Check if uploads directory is protected. * * @since 4.2.0 * @return bool */ - protected static function is_uploads_directory_public() { + protected static function is_uploads_directory_protected() { + $cache_key = '_woocommerce_upload_directory_status'; + $status = get_transient( $cache_key ); + + // Check for cache. + if ( false !== $status ) { + return 'protected' === $status; + } + + // Get uploads directory data and allows to get created if doesn't exists. $uploads = wp_upload_dir( null, true ); // Skip if returns an error. if ( $uploads['error'] ) { - return true; + return false; } - // Check for uploads root. - $baseurl_response = wp_safe_remote_get( $uploads['baseurl'] ); - $baseurl_code = intval( wp_remote_retrieve_response_code( $baseurl_response ) ); + // Allow us to easily interact with the filesystem. + require_once ABSPATH . 'wp-admin/includes/file.php'; + WP_Filesystem(); + global $wp_filesystem; - // Check for latest uploads sub directory. - // Double check in case the uploads root is only protected by an index.php or index.html file. - $url_response = wp_safe_remote_get( $uploads['url'] ); - $url_code = intval( wp_remote_retrieve_response_code( $url_response ) ); + $is_protected = false; + $test_dir = 'woocommerce-uploads-test'; + $test_dir_path = trailingslashit( $uploads['basedir'] ) . $test_dir; + + // Clean up the test directory before we start. + if ( $wp_filesystem->exists( $test_dir_path ) ) { + $wp_filesystem->delete( $test_dir_path ); + } + + // Create a new directory to check in case the uploads root is only protected by an index.php or index.html file. + if ( $wp_filesystem->mkdir( $test_dir_path ) ) { + $response = wp_safe_remote_get( $uploads['baseurl'] . '/' . $test_dir ); + $response_code = intval( wp_remote_retrieve_response_code( $response ) ); + $response_content = wp_remote_retrieve_body( $response ); + + // Check if returns 200 with empty content in case there's some index.html, + // and check for non-200 codes in case the directory is protected. + $is_protected = 200 === $response_code && empty( $response_content ) || 200 !== $response_code; + + // Remove test directory. + $wp_filesystem->delete( $test_dir_path ); + set_transient( $cache_key, $is_protected ? 'protected' : 'unprotected', 1 * DAY_IN_SECONDS ); + } - return 200 === $baseurl_code || 200 === $url_code; + return $is_protected; } } diff --git a/includes/admin/views/html-notice-uploads-directory-is-public.php b/includes/admin/views/html-notice-uploads-directory-is-public.php deleted file mode 100644 index 360d2c2429ce4..0000000000000 --- a/includes/admin/views/html-notice-uploads-directory-is-public.php +++ /dev/null @@ -1,33 +0,0 @@ - -
    - - -

    - %1$s) is public. We highly recommend securing your uploads directory against indexing. Learn more here.', 'woocommerce' ), - $uploads['basedir'], - 'https://docs.woocommerce.com/document/ssl-and-https/' - ) - ); - ?> -

    -
    From 1208f79476c14f2c0da4b8b6b1e55e07e823051f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 May 2020 14:04:42 -0300 Subject: [PATCH 063/115] Included view --- ...otice-uploads-directory-is-unprotected.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 includes/admin/views/html-notice-uploads-directory-is-unprotected.php diff --git a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php new file mode 100644 index 0000000000000..6cbafb9e9769b --- /dev/null +++ b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php @@ -0,0 +1,33 @@ + +
    + + +

    + %1$s) is unprotected. We highly recommend securing your uploads directory against indexing. Learn more here.', 'woocommerce' ), + $uploads['basedir'], + 'https://docs.woocommerce.com/document/ssl-and-https/' + ) + ); + ?> +

    +
    From d6a17aad4ef082fc0b2ee9e698d631287674dad7 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 May 2020 14:05:53 -0300 Subject: [PATCH 064/115] Request is internal --- includes/admin/class-wc-admin-notices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 1c2532eb842d1..1634fc850be46 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -588,7 +588,7 @@ protected static function is_uploads_directory_protected() { // Create a new directory to check in case the uploads root is only protected by an index.php or index.html file. if ( $wp_filesystem->mkdir( $test_dir_path ) ) { - $response = wp_safe_remote_get( $uploads['baseurl'] . '/' . $test_dir ); + $response = wp_remote_get( $uploads['baseurl'] . '/' . $test_dir ); $response_code = intval( wp_remote_retrieve_response_code( $response ) ); $response_content = wp_remote_retrieve_body( $response ); From f3dc64679d915af908f4130bcfeb2a57b5e69c85 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 May 2020 15:56:16 -0300 Subject: [PATCH 065/115] Set an error ID for each WP_Error entry --- includes/class-wc-checkout.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php index 3a05d107527e3..5477531273d7f 100644 --- a/includes/class-wc-checkout.php +++ b/includes/class-wc-checkout.php @@ -748,14 +748,14 @@ protected function validate_posted_data( &$data, &$errors ) { /* translators: %s: field name */ $postcode_validation_notice = sprintf( __( '%s is not a valid postcode / ZIP.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ); } - $errors->add( 'validation', apply_filters( 'woocommerce_checkout_postcode_validation_notice', $postcode_validation_notice, $country, $data[ $key ] ), array( 'id' => $key ) ); + $errors->add( $key . '_validation', apply_filters( 'woocommerce_checkout_postcode_validation_notice', $postcode_validation_notice, $country, $data[ $key ] ), array( 'id' => $key ) ); } } if ( in_array( 'phone', $format, true ) ) { if ( $validate_fieldset && '' !== $data[ $key ] && ! WC_Validation::is_phone( $data[ $key ] ) ) { /* translators: %s: phone number */ - $errors->add( 'validation', sprintf( __( '%s is not a valid phone number.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), array( 'id' => $key ) ); + $errors->add( $key . '_validation', sprintf( __( '%s is not a valid phone number.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), array( 'id' => $key ) ); } } @@ -765,7 +765,7 @@ protected function validate_posted_data( &$data, &$errors ) { if ( $validate_fieldset && ! $email_is_valid ) { /* translators: %s: email address */ - $errors->add( 'validation', sprintf( __( '%s is not a valid email address.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), array( 'id' => $key ) ); + $errors->add( $key . '_validation', sprintf( __( '%s is not a valid email address.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), array( 'id' => $key ) ); continue; } } @@ -785,14 +785,14 @@ protected function validate_posted_data( &$data, &$errors ) { if ( $validate_fieldset && ! in_array( $data[ $key ], $valid_state_values, true ) ) { /* translators: 1: state field 2: valid states */ - $errors->add( 'validation', sprintf( __( '%1$s is not valid. Please enter one of the following: %2$s', 'woocommerce' ), '' . esc_html( $field_label ) . '', implode( ', ', $valid_states ) ), array( 'id' => $key ) ); + $errors->add( $key . '_validation', sprintf( __( '%1$s is not valid. Please enter one of the following: %2$s', 'woocommerce' ), '' . esc_html( $field_label ) . '', implode( ', ', $valid_states ) ), array( 'id' => $key ) ); } } } if ( $validate_fieldset && $required && '' === $data[ $key ] ) { /* translators: %s: field name */ - $errors->add( 'required-field', apply_filters( 'woocommerce_checkout_required_field_notice', sprintf( __( '%s is a required field.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), $field_label ), array( 'id' => $key ) ); + $errors->add( $key . '_required', apply_filters( 'woocommerce_checkout_required_field_notice', sprintf( __( '%s is a required field.', 'woocommerce' ), '' . esc_html( $field_label ) . '' ), $field_label ), array( 'id' => $key ) ); } } } From 85d7cdbbb446086bb7bb938027b3211bd0e76036 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 5 May 2020 16:35:10 -0300 Subject: [PATCH 066/115] Allow schedule coupons via CRUD --- includes/data-stores/class-wc-coupon-data-store-cpt.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-coupon-data-store-cpt.php b/includes/data-stores/class-wc-coupon-data-store-cpt.php index 4590a24c086be..dab16bfc1b92a 100644 --- a/includes/data-stores/class-wc-coupon-data-store-cpt.php +++ b/includes/data-stores/class-wc-coupon-data-store-cpt.php @@ -69,7 +69,9 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat * @param WC_Coupon $coupon Coupon object. */ public function create( &$coupon ) { - $coupon->set_date_created( time() ); + if ( ! $coupon->get_date_created( 'edit' ) ) { + $coupon->set_date_created( time() ); + } $coupon_id = wp_insert_post( apply_filters( From 191bc7f13473a89cd20e539f2a09ff768fd01c1a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 6 May 2020 21:41:04 -0300 Subject: [PATCH 067/115] Check if uploads/woocommerce_uploads is protected --- includes/admin/class-wc-admin-notices.php | 48 ++++++----------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 1634fc850be46..e966ee6b9f585 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -564,42 +564,18 @@ protected static function is_uploads_directory_protected() { return 'protected' === $status; } - // Get uploads directory data and allows to get created if doesn't exists. - $uploads = wp_upload_dir( null, true ); - - // Skip if returns an error. - if ( $uploads['error'] ) { - return false; - } - - // Allow us to easily interact with the filesystem. - require_once ABSPATH . 'wp-admin/includes/file.php'; - WP_Filesystem(); - global $wp_filesystem; - - $is_protected = false; - $test_dir = 'woocommerce-uploads-test'; - $test_dir_path = trailingslashit( $uploads['basedir'] ) . $test_dir; - - // Clean up the test directory before we start. - if ( $wp_filesystem->exists( $test_dir_path ) ) { - $wp_filesystem->delete( $test_dir_path ); - } - - // Create a new directory to check in case the uploads root is only protected by an index.php or index.html file. - if ( $wp_filesystem->mkdir( $test_dir_path ) ) { - $response = wp_remote_get( $uploads['baseurl'] . '/' . $test_dir ); - $response_code = intval( wp_remote_retrieve_response_code( $response ) ); - $response_content = wp_remote_retrieve_body( $response ); - - // Check if returns 200 with empty content in case there's some index.html, - // and check for non-200 codes in case the directory is protected. - $is_protected = 200 === $response_code && empty( $response_content ) || 200 !== $response_code; - - // Remove test directory. - $wp_filesystem->delete( $test_dir_path ); - set_transient( $cache_key, $is_protected ? 'protected' : 'unprotected', 1 * DAY_IN_SECONDS ); - } + // Get only data from the uploads directory. + $uploads = wp_get_upload_dir(); + + // Check for the "uploads/woocommerce_uploads" directory. + $response = wp_remote_get( $uploads['baseurl'] . '/woocommerce_uploads' ); + $response_code = intval( wp_remote_retrieve_response_code( $response ) ); + $response_content = wp_remote_retrieve_body( $response ); + + // Check if returns 200 with empty content in case can open an index.html file, + // and check for non-200 codes in case the directory is protected. + $is_protected = ( 200 === $response_code && empty( $response_content ) ) || ( 200 !== $response_code ); + set_transient( $cache_key, $is_protected ? 'protected' : 'unprotected', 1 * DAY_IN_SECONDS ); return $is_protected; } From 8fecbcf9bff20b19cc3c887f8e6ce2e79fa7df0c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 6 May 2020 21:49:20 -0300 Subject: [PATCH 068/115] Make safe --- includes/admin/class-wc-admin-notices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index e966ee6b9f585..fd61bf6c388f9 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -568,7 +568,7 @@ protected static function is_uploads_directory_protected() { $uploads = wp_get_upload_dir(); // Check for the "uploads/woocommerce_uploads" directory. - $response = wp_remote_get( $uploads['baseurl'] . '/woocommerce_uploads' ); + $response = wp_safe_remote_get( esc_url_raw( $uploads['baseurl'] . '/woocommerce_uploads' ) ); $response_code = intval( wp_remote_retrieve_response_code( $response ) ); $response_content = wp_remote_retrieve_body( $response ); From 16027eb33e26fd0fd92e97d14c7c2bc00b8202d5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 6 May 2020 21:50:01 -0300 Subject: [PATCH 069/115] Updated the notice --- .../html-notice-uploads-directory-is-unprotected.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php index 6cbafb9e9769b..74e43043f4077 100644 --- a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php +++ b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php @@ -10,10 +10,6 @@ $uploads = wp_get_upload_dir(); -if ( $uploads['error'] ) { - return; -} - ?>
    @@ -22,9 +18,9 @@ %1$s) is unprotected. We highly recommend securing your uploads directory against indexing. Learn more here.', 'woocommerce' ), - $uploads['basedir'], + /* translators: 1: uploads directory URL 2: documentation URL */ + __( 'Your store\'s uploads directory is browsable via the web. We strongly recommend configuring your web server to prevent directory indexing.', 'woocommerce' ), + esc_url( $uploads['baseurl'] . '/woocommerce_uploads' ), 'https://docs.woocommerce.com/document/ssl-and-https/' ) ); From 32d2b79e7831e11abda9e63476bd983d2cd1dd08 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 7 May 2020 13:11:20 -0300 Subject: [PATCH 070/115] Introduced script to generate a zip package --- bin/build-zip.sh | 32 ++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 33 insertions(+) create mode 100755 bin/build-zip.sh diff --git a/bin/build-zip.sh b/bin/build-zip.sh new file mode 100755 index 0000000000000..a80eaa9c928ed --- /dev/null +++ b/bin/build-zip.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +PLUGIN_SLUG="woocommerce" +PROJECT_PATH=$(pwd) +BUILD_PATH="${PROJECT_PATH}/build" +DEST_PATH="$BUILD_PATH/$PLUGIN_SLUG" + +echo "Generating build directory..." +rm -rf "$BUILD_PATH" +mkdir -p "$DEST_PATH" + +echo "Installing PHP and JS dependencies..." +npm install +composer install || exit "$?" +echo "Running JS Build..." +npm run build || exit "$?" +echo "Cleaning up PHP dependencies..." +composer install --no-dev || exit "$?" + +echo "Syncing files..." +rsync -rc --exclude-from="$PROJECT_PATH/.distignore" "$PROJECT_PATH/" "$DEST_PATH/" --delete --delete-excluded + +echo "Restoring PHP dependencies..." +composer install || exit "$?" +npm run build || exit "$?" + +echo "Generating zip file..." +cd "$BUILD_PATH" || exit +zip -q -r "${PLUGIN_SLUG}.zip" "$PLUGIN_SLUG/" +echo "$BUILD_PATH/${PLUGIN_SLUG}.zip file generated!" + +echo "Build done!" diff --git a/package.json b/package.json index d39aab8703b8d..c0fd2c79db853 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "scripts": { "build": "grunt && npm run makepot", "build-watch": "grunt watch", + "build:zip": "./bin/build-zip.sh", "lint:js": "eslint assets/js --ext=js", "test:e2e": "./tests/bin/e2e-test-integration.js", "test:e2e-dev": "./tests/bin/e2e-test-integration.js --dev", From 2420b8013d8a0866867ae721237b8a9543761684 Mon Sep 17 00:00:00 2001 From: Timmy Crawford Date: Thu, 7 May 2020 12:05:11 -0700 Subject: [PATCH 071/115] Add tracking event on order search. --- .../events/class-wc-orders-tracking.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/tracks/events/class-wc-orders-tracking.php b/includes/tracks/events/class-wc-orders-tracking.php index 464f90ac25771..aa950136e1685 100644 --- a/includes/tracks/events/class-wc-orders-tracking.php +++ b/includes/tracks/events/class-wc-orders-tracking.php @@ -21,6 +21,26 @@ public function init() { // WC_Meta_Box_Order_Actions::save() hooks in at priority 50. add_action( 'woocommerce_process_shop_order_meta', array( $this, 'track_order_action' ), 51 ); add_action( 'load-post-new.php', array( $this, 'track_add_order_from_edit' ), 10 ); + add_filter( 'woocommerce_shop_order_search_results', array( $this, 'track_order_search' ), 10, 3 ); + } + + /** + * Send a track event when on the Order Listing page, and search results are being displayed. + * + * @param array $order_ids Array of order_ids that are matches for the search. + * @param string $term The string that was used in the search. + * @param array $search_fields Fields that were used in the original search. + */ + public function track_order_search( $order_ids, $term, $search_fields ) { + $screen = get_current_screen(); + + // We only want to record this track when the filter is executed on the order listing page. + if ( 'edit-shop_order' === $screen->id ) { + // we are on the order listing page, and query results are being shown. + WC_Tracks::record_event( 'orders_view_search' ); + } + + return $order_ids; } /** From 7ee559004b6239d7269f783f1b2542645ba69862 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 7 May 2020 16:05:45 -0300 Subject: [PATCH 072/115] Change notice class to error --- .../views/html-notice-uploads-directory-is-unprotected.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php index 74e43043f4077..d621c0c497af0 100644 --- a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php +++ b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php @@ -11,7 +11,7 @@ $uploads = wp_get_upload_dir(); ?> -
    +

    From f5e67af29a054d8ab7b8450db1b96a1f417aa5b4 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 7 May 2020 16:12:48 -0300 Subject: [PATCH 073/115] Allow use .error and .success classes with .woocommerce-message --- assets/css/activation.scss | 5 ++++- assets/css/admin.scss | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/css/activation.scss b/assets/css/activation.scss index 1823bd69dce7d..30ad30bc07a08 100644 --- a/assets/css/activation.scss +++ b/assets/css/activation.scss @@ -9,7 +9,10 @@ div.woocommerce-message { overflow: hidden; position: relative; - border-left-color: #cc99c2 !important; + + &.updated { + border-left-color: #cc99c2 !important; + } } p.woocommerce-actions, diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 67ae21ee00f78..d4e4d05c6558f 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -541,9 +541,12 @@ .woocommerce-message { position: relative; - border-left-color: #cc99c2 !important; overflow: hidden; + &.updated { + border-left-color: #cc99c2 !important; + } + a.skip, a.docs { text-decoration: none !important; From 2fdf4b6a0c24672111d1d3afa085eb9120266592 Mon Sep 17 00:00:00 2001 From: Barry Hughes Date: Thu, 7 May 2020 13:32:05 -0700 Subject: [PATCH 074/115] Pass the result of _n() through sprintf() to ensure placeholders are replaced with values --- includes/class-wc-form-handler.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index 3565b642a6bf0..1cc6bb806e560 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -466,12 +466,15 @@ public static function add_payment_method_action() { if ( WC_Rate_Limiter::retried_too_soon( $rate_limit_id ) ) { wc_add_notice( - /* translators: %d number of seconds */ - _n( - 'You cannot add a new payment method so soon after the previous one. Please wait for %d second.', - 'You cannot add a new payment method so soon after the previous one. Please wait for %d seconds.', - $delay, - 'woocommerce' + sprintf( + /* translators: %d number of seconds */ + _n( + 'You cannot add a new payment method so soon after the previous one. Please wait for %d second.', + 'You cannot add a new payment method so soon after the previous one. Please wait for %d seconds.', + $delay, + 'woocommerce' + ), + $delay ), 'error' ); From 94bf2eb518b2888e154fd0c46150b6ed2d2ff7da Mon Sep 17 00:00:00 2001 From: Timmy Crawford Date: Thu, 7 May 2020 13:32:45 -0700 Subject: [PATCH 075/115] Updates per feedback. --- includes/tracks/events/class-wc-orders-tracking.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/tracks/events/class-wc-orders-tracking.php b/includes/tracks/events/class-wc-orders-tracking.php index aa950136e1685..7ef2db2a4e80e 100644 --- a/includes/tracks/events/class-wc-orders-tracking.php +++ b/includes/tracks/events/class-wc-orders-tracking.php @@ -32,6 +32,11 @@ public function init() { * @param array $search_fields Fields that were used in the original search. */ public function track_order_search( $order_ids, $term, $search_fields ) { + // Since `woocommerce_shop_order_search_results` can run in the front-end context, exit if get_current_screen isn't defined. + if ( ! function_exists( 'get_current_screen' ) ) { + return $order_ids; + } + $screen = get_current_screen(); // We only want to record this track when the filter is executed on the order listing page. From 224559e73fab6a19410c557ead221528732e8bc8 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 7 May 2020 18:57:53 -0300 Subject: [PATCH 076/115] Updated since tag and removed global variable --- includes/admin/class-wc-admin.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index af6f46edcb03d..6932f817ca5e5 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -313,24 +313,21 @@ public function disable_webhook_post_export( $args ) { /** * Include admin classes. * - * @since 4.1.1 - * - * @param String $classes Body classes string. - * - * @return String + * @since 4.2.0 + * @param string $classes Body classes string. + * @return string */ public function include_admin_body_class( $classes ) { - if ( false !== strpos( $classes, 'wc-wp-version-gte-53' ) ) { return $classes; } - global $wp_version; - $version_parts = explode( '-', $wp_version ); - $version = count( $version_parts ) > 1 ? $version_parts[0] : $wp_version; + $raw_version = get_bloginfo( 'version' ); + $version_parts = explode( '-', $raw_version ); + $version = count( $version_parts ) > 1 ? $version_parts[0] : $raw_version; // Add WP 5.3+ compatibility class. - if ( $wp_version && version_compare( $version, '5.3', '>=' ) ) { + if ( $raw_version && version_compare( $version, '5.3', '>=' ) ) { $classes .= ' wc-wp-version-gte-53'; } From df97b1f74e6086f5fae2d0639d4e386febc42b1f Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Thu, 7 May 2020 18:39:19 -0400 Subject: [PATCH 077/115] Add `wcadmin_products_view` Tracks event --- includes/tracks/events/class-wc-products-tracking.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/tracks/events/class-wc-products-tracking.php b/includes/tracks/events/class-wc-products-tracking.php index 3fd0bc6c2a52b..c1bc1cee05246 100644 --- a/includes/tracks/events/class-wc-products-tracking.php +++ b/includes/tracks/events/class-wc-products-tracking.php @@ -17,12 +17,23 @@ class WC_Products_Tracking { * Init tracking. */ public function init() { + add_action( 'load-edit.php', array( $this, 'track_products_view' ), 10 ); add_action( 'edit_post', array( $this, 'track_product_updated' ), 10, 2 ); add_action( 'transition_post_status', array( $this, 'track_product_published' ), 10, 3 ); add_action( 'created_product_cat', array( $this, 'track_product_category_created' ) ); add_action( 'add_meta_boxes_product', array( $this, 'track_product_updated_client_side' ), 10 ); } + /** + * Send a Tracks event when the Products page is viewed. + */ + public function track_products_view() { + if ( isset( $_GET['post_type'] ) && 'product' === wp_unslash( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + WC_Tracks::record_event( 'products_view' ); + } + } + + /** * Send a Tracks event when a product is updated. * From 8ae5b4d5a6bc0057f89c5729479adbe5c15df6e8 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 7 May 2020 16:19:31 -0700 Subject: [PATCH 078/115] Update class-wc-admin-addons.php Fix variable name typo. `$parameters` --- includes/admin/class-wc-admin-addons.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-wc-admin-addons.php b/includes/admin/class-wc-admin-addons.php index 31e9adac3a3d4..42faab0fb1940 100644 --- a/includes/admin/class-wc-admin-addons.php +++ b/includes/admin/class-wc-admin-addons.php @@ -51,13 +51,13 @@ public static function get_featured() { */ public static function build_parameter_string( $category, $term, $country ) { - $paramters = array( + $parameters = array( 'category' => $category, 'term' => $term, 'country' => $country, ); - return '?' . http_build_query( $paramters ); + return '?' . http_build_query( $parameters ); } /** From b1a32f4144ad84a1980b4dd3d63f89132865431a Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Thu, 7 May 2020 21:24:17 -0400 Subject: [PATCH 079/115] Add `wcadmin_products_search` Tracks event. --- .../events/class-wc-products-tracking.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/tracks/events/class-wc-products-tracking.php b/includes/tracks/events/class-wc-products-tracking.php index c1bc1cee05246..b583dea13de94 100644 --- a/includes/tracks/events/class-wc-products-tracking.php +++ b/includes/tracks/events/class-wc-products-tracking.php @@ -28,8 +28,23 @@ public function init() { * Send a Tracks event when the Products page is viewed. */ public function track_products_view() { - if ( isset( $_GET['post_type'] ) && 'product' === wp_unslash( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + // We only record Tracks event when no `_wp_http_referer` query arg is set, since + // when searching, the request gets sent from the browser twice, + // once with the `_wp_http_referer` and once without it. + // + // Otherwise, we would double-record the view and search events. + + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification + if ( isset( $_GET['post_type'] ) + && 'product' === wp_unslash( $_GET['post_type'] ) + && ! isset( $_GET['_wp_http_referer'] ) ) { + // phpcs:enable + WC_Tracks::record_event( 'products_view' ); + + if ( isset( $_GET['s'] ) ) { + WC_Tracks::record_event( 'products_search' ); + } } } From 14122aae5cf24b3b91eab741838d0339b56a63c1 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Fri, 8 May 2020 09:51:12 -0400 Subject: [PATCH 080/115] Ignore *.swp files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 98eda2aff7cf6..9bf4a8ba4cd94 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ project.properties *.sublime-project *.sublime-workspace .sublimelinterrc +*.swp # Grunt /node_modules/ From 4f908c452db0eb36cde4fff308dfaf5d39854e20 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 8 May 2020 11:24:43 -0300 Subject: [PATCH 081/115] update tests and e2e readme instructions, file locations --- tests/README.md | 2 +- tests/e2e/README.md | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/README.md b/tests/README.md index e352b11933f53..9a75383a9843c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -76,4 +76,4 @@ Code coverage is available on [Codecov](https://codecov.io/gh/woocommerce/woocom ## WooCommerce E2E Tests -See [e2e-tests README](https://github.com/woocommerce/woocommerce/tree/master/tests/e2e-tests) to learn how to setup testing environment for running e2e tests and run them. +See [e2e README](https://github.com/woocommerce/woocommerce/tree/master/tests/e2e) to learn how to setup testing environment for running e2e tests and run them. diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 755647a1ae57b..898b5b89d2f97 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -54,7 +54,7 @@ We recommend using Docker for running tests locally in order for the test enviro ### Environment Variables -During the process of Docker building a container with test site for running tests, site URL is being set. Admin and customer users are also being created in advance with details specified in the `docker-compose.yaml` file. As a result, there is `./tests/e2e-tests/config/default.json` file that contains pre-set variables needed to run the test: +During the process of Docker building a container with test site for running tests, site URL is being set. Admin and customer users are also being created in advance with details specified in the `docker-compose.yaml` file. As a result, there is `./tests/e2e/config/default.json` file that contains pre-set variables needed to run the test: ``` { @@ -90,6 +90,8 @@ Setup Wizard e2e test (located in `activate-and-setup` directory) will run befor - Run `npm install` +- Run `npm install jest --global` + - Run `composer install --no-dev` - Run `npm run build` @@ -132,14 +134,14 @@ Tests are being run headless by default. However, sometimes it's useful to obser npm run test:e2e-dev ``` -The dev mode also enables SlowMo mode. SlowMo slows down Puppeteer’s operations so we can better see what is happening in the browser. You can adjust the SlowMo value by editing `PUPPETEER_SLOWMO` variable in `./tests/bin/e2e-test-integration.js` file. The default `PUPPETEER_SLOWMO=50` means test actions will be slowed down by 50 milliseconds. +The dev mode also enables SlowMo mode. SlowMo slows down Puppeteer’s operations so we can better see what is happening in the browser. You can adjust the SlowMo value by copying `/tests/e2e/env/config/jest.puppetee.config.js` to `/tests/e2e/config` and editing the value in that file. The default `PUPPETEER_SLOWMO=50` means test actions will be slowed down by 50 milliseconds. ### How to run an individual test To run an individual test, use the direct path to the spec. For example: ```bash -npm run test:e2e ./tests/e2e-tests/specs/wp-admin/wp-admin-product-new.test.js +npm run test:e2e ./tests/e2e/specs/wp-admin/wp-admin-product-new.test.js ``` ### How to skip tests @@ -159,7 +161,7 @@ it.only( 'Can make sure WooCommerce is activated. If not, activate it', async () As a result, when you run `setup-wizard.test.js`, only the login and activate tests will run. The rest will be skipped. You should see the following in the terminal: ``` - PASS tests/e2e-tests/specs/activate-and-setup/setup-wizard.test.js (11.927s) + PASS tests/e2e/specs/activate-and-setup/setup-wizard.test.js (11.927s) Store owner can login and make sure WooCommerce is activated ✓ Can login (7189ms) ✓ Can make sure WooCommerce is activated. If not, activate it (1187ms) @@ -196,7 +198,7 @@ We use the following tools to write e2e tests: - [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer) – provides all required configuration to run tests using Puppeteer - [expect-puppeteer](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer) – assertion library for Puppeteer -Tests are kept in `tests/e2e-tests/specs` folder. +Tests are kept in `tests/e2e/specs` folder. The following packages are being used to write tests: From da1dd76a68e43652836fdb5a43f99d863e112a90 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Fri, 8 May 2020 11:20:28 -0400 Subject: [PATCH 082/115] Only log `products_search` event if search query is non-empty --- .../tracks/events/class-wc-products-tracking.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/tracks/events/class-wc-products-tracking.php b/includes/tracks/events/class-wc-products-tracking.php index b583dea13de94..3a993b9406322 100644 --- a/includes/tracks/events/class-wc-products-tracking.php +++ b/includes/tracks/events/class-wc-products-tracking.php @@ -35,14 +35,22 @@ public function track_products_view() { // Otherwise, we would double-record the view and search events. // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification - if ( isset( $_GET['post_type'] ) + if ( + isset( $_GET['post_type'] ) && 'product' === wp_unslash( $_GET['post_type'] ) - && ! isset( $_GET['_wp_http_referer'] ) ) { + && ! isset( $_GET['_wp_http_referer'] ) + ) { // phpcs:enable WC_Tracks::record_event( 'products_view' ); - if ( isset( $_GET['s'] ) ) { + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification + if ( + isset( $_GET['s'] ) + && 0 < strlen( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) + ) { + // phpcs:enable + WC_Tracks::record_event( 'products_search' ); } } From 9c5e07e5ba4d7aee90e4e79580d146296c98e9c2 Mon Sep 17 00:00:00 2001 From: Kathy Darling Date: Fri, 8 May 2020 10:07:41 -0600 Subject: [PATCH 083/115] clear floats for upsells and related products. Closes #26334. --- assets/css/twenty-twenty.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/css/twenty-twenty.scss b/assets/css/twenty-twenty.scss index b7dce2f6d798f..526a72206f655 100644 --- a/assets/css/twenty-twenty.scss +++ b/assets/css/twenty-twenty.scss @@ -924,6 +924,8 @@ a.reset_variations { .related.products, .up-sells { + clear: both; + ul.products { display: flex; justify-content: space-evenly; From 72ff998033142bf44280aa78aab749d15e4878bb Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 8 May 2020 14:29:02 -0300 Subject: [PATCH 084/115] remove npm e2e-CI script command --- tests/e2e/env/README.md | 7 ++++++- tests/e2e/env/package.json | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/e2e/env/README.md b/tests/e2e/env/README.md index 7669bde479f24..6ce824a29dd4e 100644 --- a/tests/e2e/env/README.md +++ b/tests/e2e/env/README.md @@ -154,8 +154,13 @@ version: ~> 1.0 .... script: - - npm explore @woocommerce/e2e-environment -- npm run test:e2e-CI + - npm install jest --global + - npm explore @woocommerce/e2e-environment -- npm run test:e2e +.... + +after_script: + - npm explore @woocommerce/e2e-environment -- npm run docker:down ``` Use `[[ ${RUN_E2E} == 1 ]]` in your bash scripts to test for the core e2e test run. diff --git a/tests/e2e/env/package.json b/tests/e2e/env/package.json index 5385654442a73..f8176b93e09b2 100644 --- a/tests/e2e/env/package.json +++ b/tests/e2e/env/package.json @@ -44,7 +44,6 @@ "docker:ssh": "docker exec -it woocommerce_wordpress-www /bin/bash", "install-wp-tests": "./bin/install-wp-tests.sh", "test:e2e": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js", - "test:e2e-CI": "bash ./bin/e2e-CI.sh", "test:e2e-dev": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js --dev" } } From ad3a9e8bf373a7a65a1a59ee50f18b484f26daa9 Mon Sep 17 00:00:00 2001 From: yasiendwieb Date: Mon, 2 Mar 2020 10:38:53 +0200 Subject: [PATCH 085/115] fix issue in tax calculation at cart test case --- tests/legacy/unit-tests/cart/cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/legacy/unit-tests/cart/cart.php b/tests/legacy/unit-tests/cart/cart.php index 7c0fe0cb9722b..0d16f561a55f0 100644 --- a/tests/legacy/unit-tests/cart/cart.php +++ b/tests/legacy/unit-tests/cart/cart.php @@ -218,7 +218,7 @@ public function test_cart_get_total_issue_21021() { $product2 = WC_Helper_Product::create_simple_product(); $product2->set_price( 59 ); $product2->set_regular_price( 59 ); - $product->set_tax_class( '5percent' ); + $product2->set_tax_class( '23percent' ); $product2->save(); // Create a flat rate method. From 73b71023ca4b31be2dfa97cbb27aca73af1786ee Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 1 Apr 2020 17:51:43 -0300 Subject: [PATCH 086/115] Fixed cart get total unit test --- tests/legacy/unit-tests/cart/cart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/legacy/unit-tests/cart/cart.php b/tests/legacy/unit-tests/cart/cart.php index 0d16f561a55f0..52b1df97195e6 100644 --- a/tests/legacy/unit-tests/cart/cart.php +++ b/tests/legacy/unit-tests/cart/cart.php @@ -181,6 +181,10 @@ public function test_cart_get_total_issue_21021() { add_filter( 'woocommerce_customer_get_shipping_state', array( $this, 'force_customer_us_state' ) ); add_filter( 'woocommerce_customer_get_shipping_postcode', array( $this, 'force_customer_us_postcode' ) ); + // Create tax classes first. + WC_Tax::create_tax_class( '23percent' ); + WC_Tax::create_tax_class( '5percent' ); + $tax_rate = array( 'tax_rate_country' => '', 'tax_rate_state' => '', @@ -244,7 +248,7 @@ public function test_cart_get_total_issue_21021() { WC()->cart->add_to_cart( $product->get_id(), 1 ); WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) ); WC()->cart->calculate_totals(); - $this->assertEquals( 28.9, WC()->cart->total ); + $this->assertEquals( 27.05, WC()->cart->total ); // Add product2 to cart. WC()->cart->add_to_cart( $product2->get_id(), 1 ); From c6fb4aefbc6c08105f753b00a9df347fe050423b Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Fri, 8 May 2020 11:49:45 -0400 Subject: [PATCH 087/115] Add `wcadmin_categories_view`, `wcadmin_categories_seach`, `wcadmin_tags_view`, and `wcadmin_tags_search` Tracks events. --- .../events/class-wc-products-tracking.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/includes/tracks/events/class-wc-products-tracking.php b/includes/tracks/events/class-wc-products-tracking.php index 3a993b9406322..577e1d534a27d 100644 --- a/includes/tracks/events/class-wc-products-tracking.php +++ b/includes/tracks/events/class-wc-products-tracking.php @@ -18,6 +18,7 @@ class WC_Products_Tracking { */ public function init() { add_action( 'load-edit.php', array( $this, 'track_products_view' ), 10 ); + add_action( 'load-edit-tags.php', array( $this, 'track_categories_and_tags_view' ), 10, 2 ); add_action( 'edit_post', array( $this, 'track_product_updated' ), 10, 2 ); add_action( 'transition_post_status', array( $this, 'track_product_published' ), 10, 3 ); add_action( 'created_product_cat', array( $this, 'track_product_category_created' ) ); @@ -56,6 +57,47 @@ public function track_products_view() { } } + /** + * Send a Tracks event when the Products Categories and Tags page is viewed. + */ + public function track_categories_and_tags_view() { + // We only record Tracks event when no `_wp_http_referer` query arg is set, since + // when searching, the request gets sent from the browser twice, + // once with the `_wp_http_referer` and once without it. + // + // Otherwise, we would double-record the view and search events. + + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification + if ( + isset( $_GET['post_type'] ) + && 'product' === wp_unslash( $_GET['post_type'] ) + && isset( $_GET['taxonomy'] ) + && ! isset( $_GET['_wp_http_referer'] ) + ) { + $taxonomy = wp_unslash( $_GET['taxonomy'] ); + // phpcs:enable + + if ( 'product_cat' === $taxonomy ) { + WC_Tracks::record_event( 'categories_view' ); + } elseif ( 'product_tag' === $taxonomy ) { + WC_Tracks::record_event( 'tags_view' ); + } + + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification + if ( + isset( $_GET['s'] ) + && 0 < strlen( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) + ) { + // phpcs:enable + + if ( 'product_cat' === $taxonomy ) { + WC_Tracks::record_event( 'categories_search' ); + } elseif ( 'product_tag' === $taxonomy ) { + WC_Tracks::record_event( 'tags_search' ); + } + } + } + } /** * Send a Tracks event when a product is updated. From e10702625c63c51f0995a74fb0aef1a9657208ea Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Mon, 11 May 2020 13:08:45 +1200 Subject: [PATCH 088/115] Add filter to validate add payment method action --- includes/class-wc-form-handler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index 3565b642a6bf0..deb325163e995 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -459,6 +459,10 @@ public static function add_payment_method_action() { return; } + if ( ! apply_filters( 'woocommerce_add_payment_method_validation', true) ) { + return; + } + // Test rate limit. $current_user_id = get_current_user_id(); $rate_limit_id = 'add_payment_method_' . $current_user_id; From 19b074f46b3c4623f5836f9ad6c0a6d5fa254fc2 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Mon, 11 May 2020 13:09:39 +1200 Subject: [PATCH 089/115] Trigger action to add additional fields before the add payment method save button --- templates/myaccount/form-add-payment-method.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/myaccount/form-add-payment-method.php b/templates/myaccount/form-add-payment-method.php index 20a4de2ffdbf7..d71221a8eb12b 100644 --- a/templates/myaccount/form-add-payment-method.php +++ b/templates/myaccount/form-add-payment-method.php @@ -47,6 +47,8 @@ ?> + +

    From 492e862db85cb44d6fc3873da1eff45f1301e23b Mon Sep 17 00:00:00 2001 From: Dan Q Date: Mon, 11 May 2020 07:13:46 +0100 Subject: [PATCH 090/115] Proposed updated link to WooCommerce documentation Re #26447. Changes link to "WooCommerce Documentation" in README.md from https://docs.woocommerce.com/documentation/plugins/woocommerce/ to https://docs.woocommerce.com/, which is a more-helpful place for beginners (who've come across the GitHub repo in the first instance) to get started. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae91337621f1f..91334b368fa65 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Welcome to the WooCommerce repository on GitHub. Here you can browse the source, If you are not a developer, please use the [WooCommerce plugin page](https://wordpress.org/plugins/woocommerce/) on WordPress.org. ## Documentation -* [WooCommerce Documentation](https://docs.woocommerce.com/documentation/plugins/woocommerce/) +* [WooCommerce Documentation](https://docs.woocommerce.com/) * [WooCommerce Developer Documentation](https://github.com/woocommerce/woocommerce/wiki) * [WooCommerce Code Reference](https://docs.woocommerce.com/wc-apidocs/) * [WooCommerce REST API Docs](https://woocommerce.github.io/woocommerce-rest-api-docs/) From 253cf5b5d9b28818ca023b7c66ef0d3bd411de96 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Mon, 11 May 2020 23:54:19 +0530 Subject: [PATCH 091/115] Update WC-REST API version to 1.0.8 --- composer.json | 2 +- composer.lock | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 302aa695b70d0..9f497ca6c1044 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "woocommerce/action-scheduler": "3.1.5", "woocommerce/woocommerce-admin": "1.1.1", "woocommerce/woocommerce-blocks": "2.5.16", - "woocommerce/woocommerce-rest-api": "1.0.7" + "woocommerce/woocommerce-rest-api": "1.0.8" }, "require-dev": { "phpunit/phpunit": "7.5.20", diff --git a/composer.lock b/composer.lock index c3c2a976a2dd6..df59505ee82b2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "265265cc587459cc670e28108c87c9aa", + "content-hash": "7eeb045064d70f87a84b44d48ff56b3b", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -388,12 +388,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/action-scheduler.git", - "reference": "84e8ecba7d4f542f85fae7663e90eede1858b41b" + "reference": "93451c8b1061010f0dcf1ac50da7e4b44d119fb1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/84e8ecba7d4f542f85fae7663e90eede1858b41b", - "reference": "84e8ecba7d4f542f85fae7663e90eede1858b41b", + "url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/93451c8b1061010f0dcf1ac50da7e4b44d119fb1", + "reference": "93451c8b1061010f0dcf1ac50da7e4b44d119fb1", "shasum": "" }, "require-dev": { @@ -423,12 +423,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-admin.git", - "reference": "79e78bb8b71fa0c0b0a77efee5474b46d62c1a76" + "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/79e78bb8b71fa0c0b0a77efee5474b46d62c1a76", - "reference": "79e78bb8b71fa0c0b0a77efee5474b46d62c1a76", + "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/ac862f831eced0e6a3692539a24c738d5aafc4ee", + "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee", "shasum": "" }, "require": { @@ -513,16 +513,16 @@ }, { "name": "woocommerce/woocommerce-rest-api", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-rest-api.git", - "reference": "49162ec26a25bd0c6efc0f3452b113cdfff0a823" + "reference": "0756027c669bb5749554ee58b9416cbdcceaa752" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-rest-api/zipball/49162ec26a25bd0c6efc0f3452b113cdfff0a823", - "reference": "49162ec26a25bd0c6efc0f3452b113cdfff0a823", + "url": "https://api.github.com/repos/woocommerce/woocommerce-rest-api/zipball/0756027c669bb5749554ee58b9416cbdcceaa752", + "reference": "0756027c669bb5749554ee58b9416cbdcceaa752", "shasum": "" }, "require": { @@ -549,7 +549,7 @@ ], "description": "The WooCommerce core REST API.", "homepage": "https://github.com/woocommerce/woocommerce-rest-api", - "time": "2020-01-28T21:04:51+00:00" + "time": "2020-05-11T14:54:30+00:00" } ], "packages-dev": [ @@ -2463,16 +2463,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.15.0", + "version": "v1.16.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14" + "reference": "1aab00e39cebaef4d8652497f46c15c1b7e45294" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/4719fa9c18b0464d399f1a63bf624b42b6fa8d14", - "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1aab00e39cebaef4d8652497f46c15c1b7e45294", + "reference": "1aab00e39cebaef4d8652497f46c15c1b7e45294", "shasum": "" }, "require": { @@ -2484,7 +2484,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.15-dev" + "dev-master": "1.16-dev" } }, "autoload": { @@ -2517,7 +2517,7 @@ "polyfill", "portable" ], - "time": "2020-02-27T09:26:54+00:00" + "time": "2020-05-08T16:50:20+00:00" }, { "name": "theseer/tokenizer", From 3ce6d4f04a5a1ec86c025d81796b2af9eda0e04e Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 11 May 2020 20:00:23 -0300 Subject: [PATCH 092/115] Fixed coding standards --- assets/js/frontend/add-to-cart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/frontend/add-to-cart.js b/assets/js/frontend/add-to-cart.js index cc2c9ba68a614..446e5dc1e9a43 100644 --- a/assets/js/frontend/add-to-cart.js +++ b/assets/js/frontend/add-to-cart.js @@ -71,7 +71,7 @@ jQuery( function( $ ) { $thisbutton.addClass( 'loading' ); // Allow 3rd parties to validate and quit early. - if( false === $( document.body ).triggerHandler( 'should_send_ajax_request.adding_to_cart', [ $thisbutton ] ) ) { + if ( false === $( document.body ).triggerHandler( 'should_send_ajax_request.adding_to_cart', [ $thisbutton ] ) ) { $( document.body ).trigger( 'ajax_request_not_sent.adding_to_cart', [ false, false, $thisbutton ] ); return true; } @@ -160,7 +160,7 @@ jQuery( function( $ ) { if ( $button ) { $button.removeClass( 'loading' ); - if( fragments ) { + if ( fragments ) { $button.addClass( 'added' ); } From 8fb72c8a1d8beb7dc2f22e7f44e82706e2ce6508 Mon Sep 17 00:00:00 2001 From: Job Date: Thu, 23 Apr 2020 16:05:22 +0200 Subject: [PATCH 093/115] Decapitalise "Better" in "Build a Better WooCommerce" All titles and questions in the new onboarding wizards only capitalise names and the first letter of the sentence. This seemed a tiny bit off. (Literally tiny.) Changed "Build a Better WooCommerce" to "Build a better WooCommerce" --- tests/e2e/utils/components.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/components.js b/tests/e2e/utils/components.js index d4cd5ea07a4fc..06a7d4a87f28f 100644 --- a/tests/e2e/utils/components.js +++ b/tests/e2e/utils/components.js @@ -69,7 +69,7 @@ const completeOnboardingWizard = async () => { // Wait for usage tracking pop-up window to appear await page.waitForSelector( '.components-modal__header-heading' ); await expect( page ).toMatchElement( - '.components-modal__header-heading', { text: 'Build a Better WooCommerce' } + '.components-modal__header-heading', { text: 'Build a better WooCommerce' } ); // Query for "Continue" buttons From c4bb82eafcb0cc57e1426343af827f4081345f81 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 12 May 2020 16:24:15 +0000 Subject: [PATCH 094/115] Update dependency woocommerce/woocommerce-admin to v1.2.0 --- composer.json | 2 +- composer.lock | 47 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 9f497ca6c1044..e412ad4831758 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "maxmind-db/reader": "1.6.0", "pelago/emogrifier": "^3.1", "woocommerce/action-scheduler": "3.1.5", - "woocommerce/woocommerce-admin": "1.1.1", + "woocommerce/woocommerce-admin": "1.2.0", "woocommerce/woocommerce-blocks": "2.5.16", "woocommerce/woocommerce-rest-api": "1.0.8" }, diff --git a/composer.lock b/composer.lock index df59505ee82b2..2ad89de96695a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7eeb045064d70f87a84b44d48ff56b3b", + "content-hash": "234a8d9c407edce45f8392358f1da8f1", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -380,11 +380,25 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-03-16T08:31:04+00:00" }, { "name": "woocommerce/action-scheduler", - "version": "3.1.5", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/woocommerce/action-scheduler.git", @@ -415,20 +429,20 @@ ], "description": "Action Scheduler for WordPress and WooCommerce", "homepage": "https://actionscheduler.org/", - "time": "2020-04-29T16:19:22+00:00" + "time": "2020-05-05T13:26:04+00:00" }, { "name": "woocommerce/woocommerce-admin", - "version": "v1.1.1", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-admin.git", - "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee" + "reference": "aa5062218a399843e68160e1b4b884320a7530ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/ac862f831eced0e6a3692539a24c738d5aafc4ee", - "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee", + "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/aa5062218a399843e68160e1b4b884320a7530ae", + "reference": "aa5062218a399843e68160e1b4b884320a7530ae", "shasum": "" }, "require": { @@ -462,7 +476,7 @@ ], "description": "A modern, javascript-driven WooCommerce Admin experience.", "homepage": "https://github.com/woocommerce/woocommerce-admin", - "time": "2020-04-28T22:16:15+00:00" + "time": "2020-05-08T22:39:16+00:00" }, { "name": "woocommerce/woocommerce-blocks", @@ -2517,6 +2531,20 @@ "polyfill", "portable" ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-05-08T16:50:20+00:00" }, { @@ -2921,5 +2949,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.1" - } + }, + "plugin-api-version": "1.1.0" } From f5a7f727f32b8e1cae191a686bb756ea70f5c6a9 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 7 May 2020 14:21:45 -0300 Subject: [PATCH 095/115] update Action Scheduler to 3.1.6 --- composer.json | 2 +- composer.lock | 113 +++++++++++++++----------------------------------- 2 files changed, 35 insertions(+), 80 deletions(-) diff --git a/composer.json b/composer.json index 5d49f490c1ee8..1ccb3807fb0dc 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "composer/installers": "1.7.0", "maxmind-db/reader": "1.6.0", "pelago/emogrifier": "^3.1", - "woocommerce/action-scheduler": "3.1.5", + "woocommerce/action-scheduler": "3.1.6", "woocommerce/woocommerce-blocks": "2.5.16", "woocommerce/woocommerce-rest-api": "1.0.7", "woocommerce/woocommerce-admin": "1.1.1" diff --git a/composer.lock b/composer.lock index 8d09e37139461..a1ece4ee65cc6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f587bb7d4020e7b4987cd1dde300e48", + "content-hash": "28b654c7e0c127f818a5e5edeb0cfd47", "packages": [ { "name": "automattic/jetpack-autoloader", - "version": "v1.6.0", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-autoloader.git", - "reference": "3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7" + "reference": "7c6736eeee0f9fc49fa691fe3e958725efb27ca0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7", - "reference": "3bcbe1ae19febd6beeb181cf11af0bf0b7abe7e7", + "url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/7c6736eeee0f9fc49fa691fe3e958725efb27ca0", + "reference": "7c6736eeee0f9fc49fa691fe3e958725efb27ca0", "shasum": "" }, "require": { @@ -40,23 +40,24 @@ "GPL-2.0-or-later" ], "description": "Creates a custom autoloader for a plugin or theme.", - "time": "2020-03-26T07:57:53+00:00" + "time": "2020-04-23T02:28:37+00:00" }, { "name": "automattic/jetpack-constants", - "version": "v1.1.3", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-constants.git", - "reference": "5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a" + "reference": "881618defb04134ddba120e7835af1a474a11edc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a", - "reference": "5fdd94dec1151e7defd684a97e0b64fe6ff1bd3a", + "url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/881618defb04134ddba120e7835af1a474a11edc", + "reference": "881618defb04134ddba120e7835af1a474a11edc", "shasum": "" }, "require-dev": { + "php-mock/php-mock": "^2.1", "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5" }, "type": "library", @@ -70,7 +71,7 @@ "GPL-2.0-or-later" ], "description": "A wrapper for defining constants in a more testable way.", - "time": "2019-11-08T21:16:05+00:00" + "time": "2020-04-15T18:58:53+00:00" }, { "name": "composer/installers", @@ -330,7 +331,7 @@ }, { "name": "symfony/css-selector", - "version": "v3.4.39", + "version": "v3.4.40", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -379,34 +380,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-03-16T08:31:04+00:00" }, { "name": "woocommerce/action-scheduler", - "version": "3.1.5", + "version": "3.1.6", "source": { "type": "git", "url": "https://github.com/woocommerce/action-scheduler.git", - "reference": "84e8ecba7d4f542f85fae7663e90eede1858b41b" + "reference": "275d0ba54b1c263dfc62688de2fa9a25a373edf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/84e8ecba7d4f542f85fae7663e90eede1858b41b", - "reference": "84e8ecba7d4f542f85fae7663e90eede1858b41b", + "url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/275d0ba54b1c263dfc62688de2fa9a25a373edf8", + "reference": "275d0ba54b1c263dfc62688de2fa9a25a373edf8", "shasum": "" }, "require-dev": { @@ -428,7 +415,7 @@ ], "description": "Action Scheduler for WordPress and WooCommerce", "homepage": "https://actionscheduler.org/", - "time": "2020-04-29T16:19:22+00:00" + "time": "2020-05-12T16:22:33+00:00" }, { "name": "woocommerce/woocommerce-admin", @@ -436,12 +423,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-admin.git", - "reference": "79e78bb8b71fa0c0b0a77efee5474b46d62c1a76" + "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/79e78bb8b71fa0c0b0a77efee5474b46d62c1a76", - "reference": "79e78bb8b71fa0c0b0a77efee5474b46d62c1a76", + "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/ac862f831eced0e6a3692539a24c738d5aafc4ee", + "reference": "ac862f831eced0e6a3692539a24c738d5aafc4ee", "shasum": "" }, "require": { @@ -1214,24 +1201,21 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/6568f4687e5b41b054365f9ae03fcb1ed5f2069b", + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b", "shasum": "" }, "require": { "php": ">=7.1" }, - "require-dev": { - "phpunit/phpunit": "~6" - }, "type": "library", "extra": { "branch-alias": { @@ -1262,7 +1246,7 @@ "reflection", "static analysis" ], - "time": "2018-08-07T13:53:10+00:00" + "time": "2020-04-27T09:25:28+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -2430,7 +2414,7 @@ }, { "name": "symfony/finder", - "version": "v3.4.39", + "version": "v3.4.40", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -2475,34 +2459,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-02-14T07:34:21+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.15.0", + "version": "v1.16.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14" + "reference": "1aab00e39cebaef4d8652497f46c15c1b7e45294" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/4719fa9c18b0464d399f1a63bf624b42b6fa8d14", - "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1aab00e39cebaef4d8652497f46c15c1b7e45294", + "reference": "1aab00e39cebaef4d8652497f46c15c1b7e45294", "shasum": "" }, "require": { @@ -2514,7 +2484,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.15-dev" + "dev-master": "1.16-dev" } }, "autoload": { @@ -2547,21 +2517,7 @@ "polyfill", "portable" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-02-27T09:26:54+00:00" + "time": "2020-05-08T16:50:20+00:00" }, { "name": "theseer/tokenizer", @@ -2965,6 +2921,5 @@ "platform-dev": [], "platform-overrides": { "php": "7.1" - }, - "plugin-api-version": "1.1.0" + } } From f4a7838ca3b27f2c17c47a4b0acacecd2e46dd0d Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Tue, 12 May 2020 09:48:07 -0700 Subject: [PATCH 096/115] Style fix --- i18n/states.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/i18n/states.php b/i18n/states.php index e5c1f95ea0e79..6361184ccc2f7 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -852,15 +852,15 @@ 'MZP' => __( 'Cabo Delgado', 'woocommerce' ), 'MZG' => __( 'Gaza', 'woocommerce' ), 'MZI' => __( 'Inhambane', 'woocommerce' ), - 'MZB' => __( 'Manica', 'woocommerce' ), + 'MZB' => __( 'Manica', 'woocommerce' ), 'MZL' => __( 'Maputo Province', 'woocommerce' ), - 'MZMPM' => __( 'Maputo', 'woocommerce' ), + 'MZMPM' => __( 'Maputo', 'woocommerce' ), 'MZN' => __( 'Nampula', 'woocommerce' ), 'MZA' => __( 'Niassa', 'woocommerce' ), 'MZS' => __( 'Sofala', 'woocommerce' ), 'MZT' => __( 'Tete', 'woocommerce' ), 'MZQ' => __( 'Zambézia', 'woocommerce' ), - ), + ), 'NG' => array( // Nigerian provinces. 'AB' => __( 'Abia', 'woocommerce' ), 'FC' => __( 'Abuja', 'woocommerce' ), From 8d6e13952a670208131af14f03c69b85846ab078 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 12 May 2020 15:16:11 -0300 Subject: [PATCH 097/115] New docs URL --- .../views/html-notice-uploads-directory-is-unprotected.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php index d621c0c497af0..d222d5d518440 100644 --- a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php +++ b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php @@ -21,7 +21,7 @@ /* translators: 1: uploads directory URL 2: documentation URL */ __( 'Your store\'s uploads directory is browsable via the web. We strongly recommend configuring your web server to prevent directory indexing.', 'woocommerce' ), esc_url( $uploads['baseurl'] . '/woocommerce_uploads' ), - 'https://docs.woocommerce.com/document/ssl-and-https/' + 'https://docs.woocommerce.com/document/digital-downloadable-product-handling/#protecting-your-uploads-directory ' ) ); ?> From 281459914bddd98043b07b96b1eb28a27028e392 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 12 May 2020 15:16:36 -0300 Subject: [PATCH 098/115] Fixed space in URL --- .../views/html-notice-uploads-directory-is-unprotected.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php index d222d5d518440..a4fd291f7ca11 100644 --- a/includes/admin/views/html-notice-uploads-directory-is-unprotected.php +++ b/includes/admin/views/html-notice-uploads-directory-is-unprotected.php @@ -21,7 +21,7 @@ /* translators: 1: uploads directory URL 2: documentation URL */ __( 'Your store\'s uploads directory is browsable via the web. We strongly recommend configuring your web server to prevent directory indexing.', 'woocommerce' ), esc_url( $uploads['baseurl'] . '/woocommerce_uploads' ), - 'https://docs.woocommerce.com/document/digital-downloadable-product-handling/#protecting-your-uploads-directory ' + 'https://docs.woocommerce.com/document/digital-downloadable-product-handling/#protecting-your-uploads-directory' ) ); ?> From f01c5a3b79ddf25abf357a127e1a1f8905fa14c1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 12 May 2020 17:49:20 -0300 Subject: [PATCH 099/115] Start 4.3.0 development --- includes/class-woocommerce.php | 2 +- woocommerce.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-woocommerce.php b/includes/class-woocommerce.php index f5acc2122c21f..6b1b3334185a0 100644 --- a/includes/class-woocommerce.php +++ b/includes/class-woocommerce.php @@ -20,7 +20,7 @@ final class WooCommerce { * * @var string */ - public $version = '4.1.0'; + public $version = '4.3.0'; /** * The single instance of the class. diff --git a/woocommerce.php b/woocommerce.php index 7f394d7e63778..45142ab1df250 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce * Plugin URI: https://woocommerce.com/ * Description: An eCommerce toolkit that helps you sell anything. Beautifully. - * Version: 4.1.0 + * Version: 4.3.0-dev * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woocommerce From a7a1ffaaef8d300ba58205307c770980bf45f839 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 12 May 2020 17:50:33 -0300 Subject: [PATCH 100/115] Updated package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5493bdc08c77d..0d024b7299ad1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce", "title": "WooCommerce", - "version": "4.1.0", + "version": "4.3.0", "homepage": "https://woocommerce.com/", "repository": { "type": "git", From ac1c6533eb4d5cc9e27c5649976417366f5c2b60 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 12 May 2020 18:03:53 -0300 Subject: [PATCH 101/115] Added 4.1.0 entry in CHANGELOG.txt --- CHANGELOG.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a6b1ec8d47973..39309fc7ac92c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,48 @@ == Changelog == += 4.1.0 - 2020-05-05 = + +**WooCommerce** +* Enhancement - Update dependency woocommerce/woocommerce-admin to v1.1.0 #26057 +* Enhancement - Updated jetpack-autoloader to 1.6 and woocommerce-blocks to 2.5.16. #26099 +* Enhancement - Added option to ignore discounts from cart's total amount to enable free shipping. #24776 +* Enhancement - Changed show password icon color to a darker grey hue. #25625 +* Enhancement - Use new Setup Wizard for all users. #26016 +* Tweak - Show notice for WP min version to WP 5.2. #26094 +* Tweak - Improve the string for untested WooCommerce extensions in the system status page to avoid confusion. #25904 +* Tweak - Updated KZT (₸) symbol. #25609 +* Tweak - Trim whitespaces and strip slashes from MaxMind License Key. #25466 +* Tweak - Updated "Help" tabs documentation. #25826 +* Tweak - Update serbian currency symbol to рсд from дин. #25885 +* Fix - Password visibility toggle to hide password again from text. #25627 +* Fix - Undefined property error when attempting to modify the coupon post meta. #25755 +* Fix - Remove some of the individual rounding logic to make sure we round at certain places only. #25800 +* Fix - Order totals calculation if the order contains taxable and non-taxable products and percentage coupons. #25092 +* Fix - Wording for cancelled order email. #25316 +* Fix - Removed guided tour videos link on setup wizard (since current link only redirects to the docs). #25823 +* Fix - Add RTL style to the onboarding wizard. #25835 +* Fix - Trigger change and set val to qty on the frontend so that it properly updates event handlers. #25903 +* Fix - Corrected the way percent coupons apply remainders across the order. #25943 +* Fix - Clarified the error messaging for WooCommerce.com package update failures. #26034 +* Fix - Enforce per user usage limit check for a coupon on guest users based on email. #26066 +* Fix - Remove elements with style=display:none explicitly to address a regression causing broken email html. #26075 +* Dev - Added woocommerce_can_restock_refunded_items filter. #25728 +* Dev - Added woocommerce_order_get_tax_location filter. #25727 +* Dev - Updated stock handling to prevent race conditions when orders come in at the same time. #25708 +* Dev - Updated /myaccount/form-login.php to use consistent kebab-case class names for woocommerce-form-row. #25668 +* Dev - Add filter woocommerce_product_upsells_products_heading to allow heading modification without having to override the template file. #25628 +* Dev - Added woocommerce_order_get_tax_location filter. #25727 +* Dev - Added the get_woocommerce_currency_symbols function to allow develops to get an array of all the currency symbol registered with WooCommerce. #25733 +* Dev - Changed string typed label_class to array in checkout fields. +* Dev - Added "woocommerce_emogrifier" action before the content of the emails is "emogrified". #25801 +* Dev - Add Ability to Filter Event Props. #25851 +* Dev - Updated the unit test install script to support paths to MySQL sockets that contain spaces. #25923 +* Dev - Made the default test source folders support the system tmp folder. #25923 +* Dev - Add cart & checkout block/shortcode info to tracker data. #25932 +* Dev - Make WC_Product_Data_Store_CPT::update_product_stock operations atomic. #26039 +* Dev - Adds usage data for the of cart & checkout blocks (currently in development in WooCommmerce Blocks plugin) to the WC Tracker snapshot. #26084 +* Dev - Implement some additional tracks for coupons, orders, and products. #26085 + = 4.0.1 - 2020-03-18 = **WooCommerce** From a7203ec4d02711f6f77045cc46c936199ea36f19 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 13 May 2020 15:00:04 +0200 Subject: [PATCH 102/115] Added clean up of duplicate notes, if there are any. There has been some reports about duplicate notes in the db, so this should remove the duplicates and keep the first one. --- includes/admin/notes/class-wc-notes-run-db-update.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index d3bb683559c81..79cd1c774ad1c 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -54,6 +54,16 @@ private static function get_current_notice() { return; } + if ( count( $note_ids ) > 1 ) { + // Remove weird duplicates. Leave the first one. + $current_notice = array_shift( $note_ids ); + foreach ( $note_ids as $note_id ) { + $note = new WC_Admin_Note( $note_id ); + $data_store->delete( $note ); + } + return $current_notice; + } + return current( $note_ids ); } From eb0879cd1a238111b91e7db6d57d9c07977860de Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 13 May 2020 16:32:42 +0200 Subject: [PATCH 103/115] Extracted actions to the beginning of the function to allow usage in note_up_to_date check. --- .../notes/class-wc-notes-run-db-update.php | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 79cd1c774ad1c..a36a7dc23df97 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -91,11 +91,12 @@ public static function set_notice_actioned() { * * @param WC_Admin_Note $note Note to check. * @param string $update_url URL to check the note against. + * @param array(string) $current_actions List of actions to check for. * @return bool */ - private static function note_up_to_date( $note, $update_url ) { + private static function note_up_to_date( $note, $update_url, $current_actions ) { $actions = $note->get_actions(); - if ( 2 === count( array_intersect( wp_list_pluck( $actions, 'name' ), array( 'update-db_run', 'update-db_learn-more' ) ) ) + if ( count( $current_actions ) === count( array_intersect( wp_list_pluck( $actions, 'name' ), $current_actions ) ) && in_array( $update_url, wp_list_pluck( $actions, 'query' ) ) ) { return true; } @@ -120,6 +121,23 @@ private static function update_needed_notice( $note_id = null ) { ) ); + $note_actions = array( + array( + 'name' => 'update-db_run', + 'label' => __( 'Update WooCommerce Database', 'woocommerce' ), + 'url' => $update_url, + 'status' => 'unactioned', + 'primary' => true, + ), + array( + 'name' => 'update-db_learn-more', + 'label' => __( 'Learn more about updates', 'woocommerce' ), + 'url' => 'https://docs.woocommerce.com/document/how-to-update-woocommerce/', + 'status' => 'unactioned', + 'primary' => false, + ), + ); + if ( $note_id ) { $note = new WC_Admin_Note( $note_id ); } else { @@ -127,7 +145,7 @@ private static function update_needed_notice( $note_id = null ) { } // Check if the note needs to be updated (e.g. expired nonce or different note type stored in the previous run). - if ( self::note_up_to_date( $note, $update_url ) ) { + if ( self::note_up_to_date( $note, $update_url, wp_list_pluck( $note_actions, 'name' ) ) ) { return $note_id; } @@ -148,20 +166,9 @@ private static function update_needed_notice( $note_id = null ) { // Set new actions. $note->clear_actions(); - $note->add_action( - 'update-db_run', - __( 'Update WooCommerce Database', 'woocommerce' ), - $update_url, - 'unactioned', - true - ); - $note->add_action( - 'update-db_learn-more', - __( 'Learn more about updates', 'woocommerce' ), - 'https://docs.woocommerce.com/document/how-to-update-woocommerce/', - 'unactioned', - false - ); + foreach ( $note_actions as $note_action ) { + $note->add_action( ...array_values( $note_action ) ); + } return $note->save(); } From ed64c0c731e47c532b9fcb0e313e10f9edb96126 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 13 May 2020 16:33:27 +0200 Subject: [PATCH 104/115] Y U no nonce here? --- includes/admin/notes/class-wc-notes-run-db-update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index a36a7dc23df97..7f5f96d8c730a 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -181,7 +181,7 @@ private static function update_needed_notice( $note_id = null ) { * @param int $note_id Note id to update. */ private static function update_in_progress_notice( $note_id ) { - // Same actions as in includes/admin/views/html-notice-updating.php. + // Same actions as in includes/admin/views/html-notice-updating.php. This just redirects, performs no action, so without nonce. $pending_actions_url = admin_url( 'admin.php?page=wc-status&tab=action-scheduler&s=woocommerce_run_update&status=pending' ); $cron_disabled = Constants::is_true( 'DISABLE_WP_CRON' ); $cron_cta = $cron_disabled ? __( 'You can manually run queued updates here.', 'woocommerce' ) : __( 'View progress →', 'woocommerce' ); From a2f985414e6cc3a49d8f0a910e8a551186b21448 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 13 May 2020 16:34:23 +0200 Subject: [PATCH 105/115] Added freshness check also for 'done' notice. --- .../notes/class-wc-notes-run-db-update.php | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 7f5f96d8c730a..391a35c6e3e60 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -222,23 +222,32 @@ private static function update_done_notice( $note_id ) { ) ); + $note_actions = array( + array( + 'name' => 'update-db_done', + 'label' => __( 'Thanks!', 'woocommerce' ), + 'url' => $hide_notices_url, + 'status' => 'actioned', + 'primary' => true, + ), + ); + $note = new WC_Admin_Note( $note_id ); + + // Check if the note needs to be updated (e.g. expired nonce or different note type stored in the previous run). + if ( self::note_up_to_date( $note, $hide_notices_url, wp_list_pluck( $note_actions, 'name' ) ) ) { + return $note_id; + } + $note->set_title( __( 'WooCommerce database update done', 'woocommerce' ) ); $note->set_content( __( 'WooCommerce database update complete. Thank you for updating to the latest version!', 'woocommerce' ) ); - $actions = $note->get_actions(); - if ( ! in_array( 'update-db_done', wp_list_pluck( $actions, 'name' ) ) ) { - $note->clear_actions(); - $note->add_action( - 'update-db_done', - __( 'Thanks!', 'woocommerce' ), - $hide_notices_url, - 'actioned', - true - ); - - $note->save(); + $note->clear_actions(); + foreach ( $note_actions as $note_action ) { + $note->add_action( ...array_values( $note_action ) ); } + + $note->save(); } /** From 6b11451b88644e1d476c92d2a0ac8abc754e0896 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 13 May 2020 16:36:09 +0200 Subject: [PATCH 106/115] Replaced repeated code from get_current_notice with the function call. --- .../notes/class-wc-notes-run-db-update.php | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 391a35c6e3e60..425435ccc928f 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -263,26 +263,22 @@ private static function update_done_notice( $note_id ) { */ private static function should_show_notice() { if ( ! \WC_Install::needs_db_update() ) { - try { - $data_store = \WC_Data_Store::load( 'admin-note' ); - } catch ( Exception $e ) { - // Bail out in case of incorrect use. + + $note_id = self::get_current_notice(); + + // Db update not needed && note does not exist -> don't show it. + if ( ! $note_id ) { return false; } - $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); - - if ( ! empty( $note_ids ) ) { - // Db update not needed && note actioned -> don't show it. - $note = new WC_Admin_Note( $note_ids[0] ); - if ( $note::E_WC_ADMIN_NOTE_ACTIONED === $note->get_status() ) { - return false; - } - } else { - // Db update not needed && note does not exist -> don't show it. + + // Db update not needed && note actioned -> don't show it. + $note = new WC_Admin_Note( $note_id ); + if ( $note::E_WC_ADMIN_NOTE_ACTIONED === $note->get_status() ) { return false; } } + // Db update needed -> show notice. return true; } From 2c1625d3f919bab76cd7cfcb87cee1eea6cb663d Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 14 May 2020 13:31:43 +0200 Subject: [PATCH 107/115] Added a couple of tests for WC_Notes_Run_Db_Update, a poorly testable class. --- .../class-wc-tests-notes-run-db-update.php | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php diff --git a/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php new file mode 100644 index 0000000000000..fe9ba9e72f4d0 --- /dev/null +++ b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php @@ -0,0 +1,191 @@ +plugin_dir . '/includes/admin/notes/class-wc-notes-run-db-update.php'; + + } + + /** + * Clean up before each test. + */ + public function setUp() { + self::remove_db_update_notes(); + } + + /** + * Returns a list of note ids with name 'wc-update-db-reminder' from the database. + * + * @return array(int) List of note ids with name 'wc-update-db-reminder'. + */ + private static function get_db_update_notes() { + $data_store = \WC_Data_Store::load( 'admin-note' ); + $note_ids = $data_store->get_notes_with_name( WC_Notes_Run_Db_Update::NOTE_NAME ); + return $note_ids; + } + + /** + * Removes all the notes with name 'wc-update-db-reminder' from the database. + */ + private static function remove_db_update_notes() { + $data_store = \WC_Data_Store::load( 'admin-note' ); + $note_ids = $data_store->get_notes_with_name( WC_Notes_Run_Db_Update::NOTE_NAME ); + foreach ( $note_ids as $note_id ) { + $note = new WC_Admin_Note( $note_id ); + $data_store->delete( $note ); + } + } + + /** + * Creates a sample note with name 'wc-update-db-reminder'. + * + * @return int Newly create note's id. + */ + private static function create_db_update_note() { + $update_url = html_entity_decode( + wp_nonce_url( + add_query_arg( 'do_update_woocommerce', 'true', admin_url( 'admin.php?page=wc-settings' ) ), + 'wc_db_update', + 'wc_db_update_nonce' + ) + ); + + $note_actions = array( + array( + 'name' => 'update-db_run', + 'label' => __( 'Update WooCommerce Database', 'woocommerce' ), + 'url' => $update_url, + 'status' => 'unactioned', + 'primary' => true, + ), + array( + 'name' => 'update-db_learn-more', + 'label' => __( 'Learn more about updates', 'woocommerce' ), + 'url' => 'https://docs.woocommerce.com/document/how-to-update-woocommerce/', + 'status' => 'unactioned', + 'primary' => false, + ), + ); + + $note = new WC_Admin_Note(); + + $note->set_title( 'WooCommerce database update required' ); + $note->set_content( 'To keep things running smoothly, we have to update your database to the newest version.' ); + $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_UPDATE ); + $note->set_icon( 'info' ); + $note->set_name( WC_Notes_Run_Db_Update::NOTE_NAME ); + $note->set_content_data( (object) array() ); + $note->set_source( 'woocommerce-core' ); + $note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED ); + + // Set new actions. + $note->clear_actions(); + foreach ( $note_actions as $note_action ) { + $note->add_action( ...array_values( $note_action ) ); + } + + return $note->save(); + } + + /** + * No note should be created/exist if db version is equal to WC code version. + */ + public function test_noop_db_update_note() { + update_option( 'woocommerce_db_version', WC()->version ); + + // No notes initially. + $this->assertEquals( 0, count( self::get_db_update_notes() ), 'There should be no db update notes initially.' ); + + WC_Notes_Run_Db_Update::show_reminder(); + + // No notice should be created. + $this->assertEquals( 0, count( self::get_db_update_notes() ), 'There should be no db update notes created if db is up to date.' ); + } + + + /** + * Note should be created if there is none and WC is updated. + */ + public function test_create_db_update_note() { + // No notes initially. + $this->assertEquals( 0, count( self::get_db_update_notes() ), 'There should be no db update notes initially.' ); + + // Make it appear as if db version is lower than WC version, i.e. db update is required. + update_option( 'woocommerce_db_version', '3.9.0' ); + + WC_Notes_Run_Db_Update::show_reminder(); + + // A notice should be created. + $this->assertEquals( 1, count( self::get_db_update_notes() ), 'A db update note should be created if db is NOT up to date.' ); + + // Update the db option back. + update_option( 'woocommerce_db_version', WC()->version ); + } + + /** + * Note should be created if there is none and WC is updated. + */ + public function test_clean_up_multiple_db_update_notes() { + // No notes initially. + $this->assertEquals( 0, count( self::get_db_update_notes() ), 'There should be no db update notes initially.' ); + + $note_1 = self::create_db_update_note(); + $note_2 = self::create_db_update_note(); + + $this->assertEquals( 2, count( self::get_db_update_notes() ), 'There should be 2 db update notes after I created 2.' ); + + WC_Notes_Run_Db_Update::show_reminder(); + + // Only one notice should remain, in case 2 were created under some weird circumstances. + $this->assertEquals( 1, count( self::get_db_update_notes() ), 'A db update note should be created if db is NOT up to date.' ); + + } + + /** + * Test switch from db update needed to thanks note. + */ + public function test_db_update_note_to_thanks_note() { + // No notes initially. + $this->assertEquals( 0, count( self::get_db_update_notes() ), 'There should be no db update notes initially.' ); + + // Make it appear as if db version is lower than WC version, i.e. db update is required. + update_option( 'woocommerce_db_version', '3.9.0' ); + + // Magic 1: nothing to update-db note. + WC_Notes_Run_Db_Update::show_reminder(); + + $note_ids = self::get_db_update_notes(); + // An 'update required' notice should be created. + $this->assertEquals( 1, count( $note_ids ), 'A db update note should be created if db is NOT up to date.' ); + + $note = new WC_Admin_Note( $note_ids[0] ); + $actions = $note->get_actions(); + $this->assertEquals( 'update-db_run', $actions[0]->name, 'A db update note to update the database should be displayed now.' ); + + // Simulate database update has been performed. + update_option( 'woocommerce_db_version', WC()->version ); + + // Magic 2: update-db note to thank you note. + WC_Notes_Run_Db_Update::show_reminder(); + + $note = new WC_Admin_Note( $note_ids[0] ); + $actions = $note->get_actions(); + $this->assertEquals( 'update-db_done', $actions[0]->name, 'A db update note--Thanks for the update--should be displayed now.' ); + } + +} From 777c140611e76af03e436c8dc8b97d296d1f365e Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 14 May 2020 14:35:09 +0200 Subject: [PATCH 108/115] Skip tests when WC Admin is not active. Since those Notes were created because of WC Admin and the display is handled by WC Admin, it does not make sense to test them without WC Admin. In addition, the data store that handles these Notices is not loaded without WC Admin. --- .../admin/notes/class-wc-tests-notes-run-db-update.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php index fe9ba9e72f4d0..c4ff724eb4981 100644 --- a/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php +++ b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php @@ -25,6 +25,10 @@ public static function setUpBeforeClass() { * Clean up before each test. */ public function setUp() { + if ( ! WC()->is_wc_admin_active() ) { + $this->markTestSkipped( 'WC Admin is not active on WP versions < 5.3' ); + return; + } self::remove_db_update_notes(); } From c09a2695891ce0d235508d25611a36fef294b6a0 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 14 May 2020 14:06:01 -0300 Subject: [PATCH 109/115] Revert "Fix duplicated custom fields after import products from .csv file" --- .../admin/importers/class-wc-product-csv-importer-controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 2e1a6d4143dc6..22b7055591704 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -577,6 +577,7 @@ protected function auto_map_columns( $raw_headers, $num_indexes = true ) { $headers = array(); foreach ( $raw_headers as $key => $field ) { + $field = strtolower( $field ); $index = $num_indexes ? $key : $field; $headers[ $index ] = $field; From 630b7f436d85b8ee21464f0e0e0fdc3ef41759a8 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Fri, 15 May 2020 09:08:35 +1200 Subject: [PATCH 110/115] apply review feedback: better naming and coding style fix --- includes/class-wc-form-handler.php | 2 +- templates/myaccount/form-add-payment-method.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index deb325163e995..d4adc3f0208d3 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -459,7 +459,7 @@ public static function add_payment_method_action() { return; } - if ( ! apply_filters( 'woocommerce_add_payment_method_validation', true) ) { + if ( ! apply_filters( 'woocommerce_add_payment_method_form_is_valid', true ) ) { return; } diff --git a/templates/myaccount/form-add-payment-method.php b/templates/myaccount/form-add-payment-method.php index d71221a8eb12b..2e2b8ca637c1e 100644 --- a/templates/myaccount/form-add-payment-method.php +++ b/templates/myaccount/form-add-payment-method.php @@ -47,7 +47,7 @@ ?> - +
    From 63ba6f7ee07f26b48c215ffe6205317a94a4a5cd Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Thu, 14 May 2020 21:04:11 -0700 Subject: [PATCH 111/115] Moved the PSR-4 namespaced test directory to the correct folder I know this probably doesn't belong in this PR, but it has been thoroughly discussed and I don't think anyone will mind :) --- composer.json | 2 +- .../helper/{WCHelperTest.php => class-wc-helper-test.php} | 4 +--- tests/php/{ => src}/.gitkeep | 0 3 files changed, 2 insertions(+), 4 deletions(-) rename tests/php/includes/admin/helper/{WCHelperTest.php => class-wc-helper-test.php} (92%) rename tests/php/{ => src}/.gitkeep (100%) diff --git a/composer.json b/composer.json index 983bab8297210..3380a30123f83 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ }, "autoload-dev": { "psr-4": { - "Automattic\\WooCommerce\\Tests\\": "tests/php/" + "Automattic\\WooCommerce\\Tests\\": "tests/php/src" } }, "scripts": { diff --git a/tests/php/includes/admin/helper/WCHelperTest.php b/tests/php/includes/admin/helper/class-wc-helper-test.php similarity index 92% rename from tests/php/includes/admin/helper/WCHelperTest.php rename to tests/php/includes/admin/helper/class-wc-helper-test.php index 2580610b15fa8..e181f1e365e81 100644 --- a/tests/php/includes/admin/helper/WCHelperTest.php +++ b/tests/php/includes/admin/helper/class-wc-helper-test.php @@ -5,12 +5,10 @@ * @package WooCommerce|Tests|WC_Helper. */ -namespace Automattic\WooCommerce; - /** * Class WC_Tests_WC_Helper. */ -class WCHelperTest extends \WC_Unit_Test_Case { +class WC_Helper_Test extends \WC_Unit_Test_Case { /** * Test that woo plugins are loaded correctly even if incorrect cache is intially set. diff --git a/tests/php/.gitkeep b/tests/php/src/.gitkeep similarity index 100% rename from tests/php/.gitkeep rename to tests/php/src/.gitkeep From 7bf9c31f6446fe5ae48736009eb05b17e5d4f4f3 Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Thu, 14 May 2020 21:20:55 -0700 Subject: [PATCH 112/115] Adjusted the column name normalization to avoid squashing meta key case sensitivity Since we were converting the field to lowercase we ended up inserting meta in all lowercase, regardless of what it was in the CSV file. We should only be using the normalized field name when looking at the default columns, and should instead rely on a case-insensitive regex for the special columns. One thing to note is that we're still defaulting the $headers array to the normalized field, as we don't want to change what is being passed to the filter for unmapped columns. --- ...ass-wc-product-csv-importer-controller.php | 14 ++-- ...c-product-csv-importer-controller-test.php | 64 +++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 22b7055591704..5a87ec9ae506e 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -319,6 +319,7 @@ public function handle_upload() { return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) ); } + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated if ( ! self::is_file_valid_csv( wc_clean( wp_unslash( $_FILES['import']['name'] ) ), false ) ) { return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) ); } @@ -327,7 +328,7 @@ public function handle_upload() { 'test_form' => false, 'mimes' => self::get_valid_csv_filetypes(), ); - $import = $_FILES['import']; // WPCS: sanitization ok, input var ok. + $import = $_FILES['import']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash $upload = wp_handle_upload( $import, $overrides ); if ( isset( $upload['error'] ) ) { @@ -577,14 +578,15 @@ protected function auto_map_columns( $raw_headers, $num_indexes = true ) { $headers = array(); foreach ( $raw_headers as $key => $field ) { - $field = strtolower( $field ); + $normalized_field = strtolower( $field ); $index = $num_indexes ? $key : $field; - $headers[ $index ] = $field; + $headers[ $index ] = $normalized_field; - if ( isset( $default_columns[ $field ] ) ) { - $headers[ $index ] = $default_columns[ $field ]; + if ( isset( $default_columns[ $normalized_field ] ) ) { + $headers[ $index ] = $default_columns[ $normalized_field ]; } else { foreach ( $special_columns as $regex => $special_key ) { + // Don't use the normalized field in the regex since meta might be case-sensitive. if ( preg_match( $regex, $field, $matches ) ) { $headers[ $index ] = $special_key . $matches[1]; break; @@ -619,7 +621,7 @@ public function auto_map_user_preferences( $headers ) { * @return string */ protected function sanitize_special_column_name_regex( $value ) { - return '/' . str_replace( array( '%d', '%s' ), '(.*)', trim( quotemeta( $value ) ) ) . '/'; + return '/' . str_replace( array( '%d', '%s' ), '(.*)', trim( quotemeta( $value ) ) ) . '/i'; } /** diff --git a/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php b/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php new file mode 100644 index 0000000000000..af046f3893190 --- /dev/null +++ b/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php @@ -0,0 +1,64 @@ +plugin_dir . '/includes/import/class-wc-product-csv-importer.php'; + require_once $bootstrap->plugin_dir . '/includes/admin/importers/class-wc-product-csv-importer-controller.php'; + } + + /** + * Tests that the automatic mapping is case insensitive so that columns can be matched more easily. + */ + public function test_that_auto_mapping_is_case_insensitive() { + // Allow us to call the protected method. + $class = new ReflectionClass( WC_Product_CSV_Importer_Controller::class ); + $method = $class->getMethod( 'auto_map_columns' ); + $method->setAccessible( true ); + + $controller = new WC_Product_CSV_Importer_Controller(); + + // Test a few different casing formats first. + $columns = $method->invoke( $controller, array( 'Name', 'Type' ) ); + $this->assertEquals( + array( + 0 => 'name', + 1 => 'type', + ), + $columns + ); + $columns = $method->invoke( $controller, array( 'NAME', 'tYpE' ) ); + $this->assertEquals( + array( + 0 => 'name', + 1 => 'type', + ), + $columns + ); + + // Make sure that the case sensitivity doesn't squash the meta keys. + $columns = $method->invoke( $controller, array( 'Meta: _TESTING', 'Meta: _testing' ) ); + $this->assertEquals( + array( + 0 => 'meta:_TESTING', + 1 => 'meta:_testing', + ), + $columns + ); + } +} From 50e386cbe8c81a6643d98f87f57ae591ccb3e1c6 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 15 May 2020 09:26:17 +0200 Subject: [PATCH 113/115] Corrected the comment. --- includes/admin/notes/class-wc-notes-run-db-update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 425435ccc928f..aa0bd6b0a03e9 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -278,7 +278,7 @@ private static function should_show_notice() { } } - // Db update needed -> show notice. + // Db update needed or notice not actioned -> show notice. return true; } From 2f141eca771fc910d8b59607ad5f7687142b4975 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 15 May 2020 09:40:23 +0200 Subject: [PATCH 114/115] PHPCS --- .../admin/notes/class-wc-notes-run-db-update.php | 12 ++++++------ .../notes/class-wc-tests-notes-run-db-update.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index aa0bd6b0a03e9..2215f5caac7c6 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -48,7 +48,7 @@ private static function get_current_notice() { } catch ( Exception $e ) { return; } - $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); + $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); if ( empty( $note_ids ) ) { return; @@ -89,15 +89,15 @@ public static function set_notice_actioned() { * - actions are set up for the first 'Update database' notice, and * - URL for note's action is equal to the given URL (to check for potential nonce update). * - * @param WC_Admin_Note $note Note to check. - * @param string $update_url URL to check the note against. - * @param array(string) $current_actions List of actions to check for. + * @param WC_Admin_Note $note Note to check. + * @param string $update_url URL to check the note against. + * @param array( string ) $current_actions List of actions to check for. * @return bool */ private static function note_up_to_date( $note, $update_url, $current_actions ) { $actions = $note->get_actions(); if ( count( $current_actions ) === count( array_intersect( wp_list_pluck( $actions, 'name' ), $current_actions ) ) - && in_array( $update_url, wp_list_pluck( $actions, 'query' ) ) ) { + && in_array( $update_url, wp_list_pluck( $actions, 'query' ), true ) ) { return true; } @@ -302,7 +302,7 @@ public static function show_reminder() { if ( \WC_Install::needs_db_update() ) { $next_scheduled_date = WC()->queue()->get_next( 'woocommerce_run_update_callback', null, 'woocommerce-db-updates' ); - if ( $next_scheduled_date || ! empty( $_GET['do_update_woocommerce'] ) ) { // WPCS: input var ok, CSRF ok. + if ( $next_scheduled_date || ! empty( $_GET['do_update_woocommerce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended self::update_in_progress_notice( $note_id ); } else { self::update_needed_notice( $note_id ); diff --git a/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php index c4ff724eb4981..90cef085ffc29 100644 --- a/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php +++ b/tests/legacy/unit-tests/admin/notes/class-wc-tests-notes-run-db-update.php @@ -35,7 +35,7 @@ public function setUp() { /** * Returns a list of note ids with name 'wc-update-db-reminder' from the database. * - * @return array(int) List of note ids with name 'wc-update-db-reminder'. + * @return array( int ) List of note ids with name 'wc-update-db-reminder'. */ private static function get_db_update_notes() { $data_store = \WC_Data_Store::load( 'admin-note' ); From 0934f4a1470b07651cfd1fc5e3418e1901428ddf Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 15 May 2020 10:24:30 +0200 Subject: [PATCH 115/115] Merged should_show_notice and show_reminder and simplified logic. Removed redundant calls to the same functions as this code runs on each admin pageload. --- .../notes/class-wc-notes-run-db-update.php | 63 ++++++++----------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 2215f5caac7c6..9d8253640ef4b 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -251,65 +251,52 @@ private static function update_done_notice( $note_id ) { } /** - * Return true if db update notice should be shown, false otherwise. + * Prepare the correct content of the db update note to be displayed by WC Admin. + * + * This one gets called on each page load, so try to bail quickly. * * If the db needs an update, the notice should be always shown. * If the db does not need an update, but the notice has *not* been actioned (i.e. after the db update, when - * store owner hasn't acknowledged the successful db update), still show the notice. + * store owner hasn't acknowledged the successful db update), still show the Thanks notice. * If the db does not need an update, and the notice has been actioned, then notice should *not* be shown. - * The same is true if the db does not need an update and the notice does not exist. - * - * @return bool + * The notice should also be hidden if the db does not need an update and the notice does not exist. */ - private static function should_show_notice() { - if ( ! \WC_Install::needs_db_update() ) { - - $note_id = self::get_current_notice(); + public static function show_reminder() { + $needs_db_update = \WC_Install::needs_db_update(); + $note_id = self::get_current_notice(); + if ( ! $needs_db_update ) { // Db update not needed && note does not exist -> don't show it. if ( ! $note_id ) { - return false; + return; } - // Db update not needed && note actioned -> don't show it. $note = new WC_Admin_Note( $note_id ); if ( $note::E_WC_ADMIN_NOTE_ACTIONED === $note->get_status() ) { - return false; + // Db update not needed && note actioned -> don't show it. + return; + } else { + // Db update not needed && notice is unactioned -> Thank you note. + \WC_Install::update_db_version(); + self::update_done_notice( $note_id ); + return; + } + } else { + // Db needs update &&. + if ( ! $note_id ) { + // Db needs update && no notice exists -> create one that shows Nudge to update. + $note_id = self::update_needed_notice(); } - } - - // Db update needed or notice not actioned -> show notice. - return true; - } - - /** - * Prepare the correct content of the db update note to be displayed by WC Admin. - * - * This one gets called on each page load, so try to bail quickly. - */ - public static function show_reminder() { - if ( ! self::should_show_notice() ) { - return; - } - - $note_id = self::get_current_notice(); - - if ( \WC_Install::needs_db_update() && empty( $note_id ) ) { - // Db needs update && no notice exists -> create one. - $note_id = self::update_needed_notice(); - } - if ( \WC_Install::needs_db_update() ) { $next_scheduled_date = WC()->queue()->get_next( 'woocommerce_run_update_callback', null, 'woocommerce-db-updates' ); if ( $next_scheduled_date || ! empty( $_GET['do_update_woocommerce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // Db needs update && db update is scheduled -> update note to In progress. self::update_in_progress_notice( $note_id ); } else { + // Db needs update && db update is not scheduled -> Nudge to run the db update. self::update_needed_notice( $note_id ); } - } else { - \WC_Install::update_db_version(); - self::update_done_notice( $note_id ); } }