Skip to content

Commit 0d76fbb

Browse files
authored
packaged version 4.26 (#341)
1 parent 8789723 commit 0d76fbb

27 files changed

+491
-37
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## [4.26.0]
4+
5+
### Added
6+
- Added automatic API scope check during plugin installation. If provided API credentials do not meet the required [criteria](https://developer.bigcommerce.com/bigcommerce-for-wordpress/ZG9jOjIyMDYzNQ-multisite), the plugin installation will be aborted and an error message will be shown
7+
- Added ability to control customer's group's cache expiration time as well as ability to purge customer and products cache. In order to control or purge the cache go to Bigcommerce -> Settings -> Diagnostics.
8+
- Use the 'Flush Users Cache' button will purge customers' group cache and retrieve fresh data from Bigcommerce API.
9+
- Use the 'User Cache Expiration' option field to set the time for how long the group cache should be stored.
10+
- Use the 'Flush Products Cache' button in order to invalidate products cache
11+
- Please note: if webhooks are enabled the cache will be invalidated automatically
12+
13+
### Changed
14+
- Update plugin readme 'Tested up to' version
15+
- Update styles for 'Choose Options' on Twenty Twenty-Two theme
16+
17+
### Fixed
18+
- Correct label spelling from 'Production Condition Color' to 'Product Condition Color' in Customizer Colors section.
19+
- Fix image zoom styling on product page for Twenty Twenty-One theme
20+
321
## [4.25.0]
422

523
### Added
@@ -1704,6 +1722,7 @@
17041722
in fact, reset postdata, so far as Gutenberg 3.2.0 is concerned.
17051723

17061724

1725+
[4.26.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.25.0...4.26.0
17071726
[4.25.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.24.0...4.25.0
17081727
[4.24.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.23.0...4.24.0
17091728
[4.23.0]: https://github.com/bigcommerce/bigcommerce-for-wordpress/compare/4.22.0...4.23.0

assets/css/master.css

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/master.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/pcss/wp-themes/_all.pcss

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@import "twenty-nineteen-theme";
1515
@import "twenty-twenty-theme";
1616
@import "twenty-twenty-one-theme";
17+
@import "twenty-twenty-two-theme";
1718
@import "genesis-themes";
1819
@import "shoptimizer";
1920
@import "veganos";

assets/pcss/wp-themes/_twenty-twenty-one-theme.pcss

+6
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,10 @@
408408
--global--color-background: var(--color-bc-black);
409409
--global--color-primary: transparent;
410410
}
411+
412+
/* CASE: image zoom doesn't work properly do to max-width property */
413+
.bc-product-gallery__image-slide img {
414+
max-width: none;
415+
width: 100%;
416+
}
411417
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.bc-wp-twenty-twenty-two-theme {
2+
3+
.bc-btn--view-product {
4+
box-sizing: border-box;
5+
}
6+
}

bigcommerce.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: BigCommerce for WordPress
44
Description: Scale your ecommerce business with WordPress on the front-end and BigCommerce on the back end. Free up server resources from things like catalog management, processing payments, and managing fulfillment logistics.
55
Author: BigCommerce
6-
Version: 4.25.0
6+
Version: 4.26
77
Author URI: https://www.bigcommerce.com/wordpress
88
Requires PHP: 7.4.0
99
Text Domain: bigcommerce

build-timestamp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '5.01.03.07.2022');
2+
define('BIGCOMMERCE_ASSETS_BUILD_TIMESTAMP', '5.44.03.28.2022');

readme.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: bigcommerce, moderntribe, jbrinley, becomevocal, vincentlistrani, jbirthler, kdiplas, iliabaum, joshliston, nickioa, fernando22, mr_speer, geoffgraham, yuenvision, xwp, karenpwhite
33
Tags: ecommerce, online store, sell online, storefront, retail, online shop, bigcommerce, big commerce, e-commerce, physical products, buy buttons, commerce, shopping cart, checkout, cart, shop, headless commerce, shipping, payments, fulfillment
44
Requires at least: 5.2
5-
Tested up to: 5.8.1
6-
Stable tag: 4.25.0
5+
Tested up to: 5.9.2
6+
Stable tag: 4.26
77
Requires PHP: 7.4.0
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html

src/BigCommerce/Accounts/Customer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Bigcommerce\Api\Resources\Address;
1010
use Bigcommerce\Api\Resources\Order;
1111
use Bigcommerce\Api\Resources\OrderProduct;
12+
use BigCommerce\Settings\Sections\Troubleshooting_Diagnostics;
1213

1314
/**
1415
* Class Customer
@@ -346,7 +347,7 @@ public function get_group_id() {
346347
// Couldn't find in cache, retrieve from the API
347348
$profile = $this->get_profile();
348349
$group_id = isset( $profile['customer_group_id'] ) ? absint( $profile['customer_group_id'] ) : 0;
349-
$expiration = HOUR_IN_SECONDS; // TODO: a future webhook to flush this cache when the customer's group changes
350+
$expiration = get_option( Troubleshooting_Diagnostics::USERS_TRANSIENT, 12 * HOUR_IN_SECONDS ); // TODO: a future webhook to flush this cache when the customer's group changes
350351
if ( $group_id === 0 ) {
351352
set_transient( $transient_key, 'zero', $expiration ); // workaround for storing empty values in cache
352353
} else {
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace BigCommerce\Api;
4+
5+
use BigCommerce\Container\Api;
6+
use BigCommerce\Container\Settings;
7+
use BigCommerce\Settings\Sections\Api_Credentials;
8+
9+
class Api_Config_Renewal {
10+
11+
private $config;
12+
13+
public function __construct(Configuration $config ) {
14+
$this->config = $config;
15+
}
16+
17+
public function renewal_config( $option, $value ) {
18+
switch ( $option ) {
19+
case Api_Credentials::OPTION_STORE_URL:
20+
$this->config->setHost( $value );
21+
break;
22+
case Api_Credentials::OPTION_CLIENT_ID:
23+
$this->config->setClientId( $value );
24+
break;
25+
case Api_Credentials::OPTION_CLIENT_SECRET:
26+
$this->config->setClientSecret( $value );
27+
break;
28+
case Api_Credentials::OPTION_ACCESS_TOKEN:
29+
$this->config->setAccessToken( $value );
30+
break;
31+
}
32+
33+
$hash = bigcommerce()->container()[ Settings::CREDENTIALS_SCREEN ]->get_store_hash( $this->config->getHost() );
34+
35+
\Bigcommerce\Api\Client::configure( [
36+
'client_id' => $this->config->getClientId(),
37+
'auth_token' => $this->config->getAccessToken(),
38+
'client_secret' => $this->config->getClientSecret(),
39+
'store_hash' => $hash,
40+
] );
41+
42+
return $this->config;
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace BigCommerce\Api;
4+
5+
use BigCommerce\Logging\Error_Log;
6+
7+
class Api_Scopes_Validator extends v2ApiAdapter {
8+
9+
const CUSTOMERS_RESOURCE = '/customers';
10+
const MARKETING_RESOURCE = '/gift_certificates';
11+
const ORDERS_RESOURCE = '/orders';
12+
const PAYMENT_METHODS_RESOURCE = '/payments/methods';
13+
14+
/**
15+
* Validate scopes for several API items in order to make pre check during onboarding process
16+
*
17+
* @return bool
18+
*
19+
* @throws \Exception
20+
*/
21+
public function validate() {
22+
$customer = $this->validate_customers_modify_scope();
23+
24+
if ( ! $customer ) {
25+
throw new \Exception( __( 'Customers API scopes are invalid', 'bigcommerce' ), 500 );
26+
}
27+
28+
$this->cleanup_scope_check_resource( self::CUSTOMERS_RESOURCE, $customer );
29+
30+
$resources = [
31+
self::MARKETING_RESOURCE,
32+
self::ORDERS_RESOURCE,
33+
self::PAYMENT_METHODS_RESOURCE,
34+
];
35+
36+
foreach ( $resources as $path ) {
37+
if ( ! $this->validate_scopes( $path ) ) {
38+
throw new \Exception( sprintf( __( 'API scopes are invalid. Requested resource: %s', 'bigcommerce' ), $path ), 500 );
39+
}
40+
}
41+
42+
return true;
43+
}
44+
45+
private function validate_customers_modify_scope() {
46+
try {
47+
$result = $this->createResource( self::CUSTOMERS_RESOURCE, [
48+
'company' => 'Bigcommerce',
49+
'email' => sprintf( 'api-scopecheck-%[email protected]', time() ),
50+
'first_name' => 'Api',
51+
'last_name' => 'Scope',
52+
'phone' => '1234567890',
53+
] );
54+
55+
if ( ! $result || ! isset( $result->id ) ) {
56+
return false;
57+
}
58+
59+
return $result->id;
60+
} catch ( \Exception $e ) {
61+
do_action( 'bigcommerce/log', Error_Log::ERROR, __( 'Could not proceed with current API scopes for customers', 'bigcommerce' ), [
62+
'trace' => $e->getTraceAsString(),
63+
] );
64+
65+
return false;
66+
}
67+
}
68+
69+
private function validate_scopes( $path = '' ) {
70+
try {
71+
$result = $this->getResource( $path );
72+
73+
if ( ! $result ) {
74+
return false;
75+
}
76+
77+
return true;
78+
} catch ( \Exception $e ) {
79+
do_action( 'bigcommerce/log', Error_Log::ERROR, __( 'Could not proceed with current API scopes for Marketing', 'bigcommerce' ), [
80+
'trace' => $e->getTraceAsString(),
81+
] );
82+
83+
return false;
84+
}
85+
}
86+
87+
private function cleanup_scope_check_resource( $path, $id ) {
88+
$deletePath = sprintf( $path . '/%d', $id );
89+
$this->deleteResource( $deletePath );
90+
}
91+
92+
}

src/BigCommerce/Container/Api.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace BigCommerce\Container;
55

66

7+
use BigCommerce\Api\Api_Config_Renewal;
8+
use BigCommerce\Api\Api_Scopes_Validator;
79
use BigCommerce\Api\Caching_Client;
810
use BigCommerce\Api\Null_Client;
911
use BigCommerce\Api\Configuration;
@@ -19,9 +21,11 @@
1921
* @package BigCommerce\Container
2022
*/
2123
class Api extends Provider {
22-
const CONFIG_COMPLETE = 'api.configuration.complete';
24+
const API_VALID = 'api.configuration.valid';
25+
const API_CONFIG_RENEWAL = 'api.configuration.config';
26+
const CONFIG_COMPLETE = 'api.configuration.complete';
2327

24-
const CACHE_HANDLER = 'api.cache_handler';
28+
const CACHE_HANDLER = 'api.cache_handler';
2529
const CLIENT = 'api.client';
2630
const CONFIG = 'api.configuration';
2731
const CLIENT_ID = 'api.client_id';
@@ -68,6 +72,10 @@ public function register( Container $container ) {
6872
return apply_filters( 'bigcommerce/api/config', $config );
6973
};
7074

75+
$container[ self::API_CONFIG_RENEWAL ] = function ( Container $container ) {
76+
return new Api_Config_Renewal( $container[ self::CONFIG ] );
77+
};
78+
7179
$container[ self::CLIENT_ID ] = function ( Container $container ) {
7280
$env = bigcommerce_get_env( 'BIGCOMMERCE_CLIENT_ID' );
7381

@@ -109,6 +117,10 @@ public function register( Container $container ) {
109117
return new Request_Headers();
110118
};
111119

120+
$container[ self::API_VALID ] = function ( Container $container ) {
121+
return new Api_Scopes_Validator( $container[ self::CLIENT ] );
122+
};
123+
112124
$container[ self::CONFIG_COMPLETE ] = function( Container $container ) {
113125
$credentials = [
114126
$container[ self::CLIENT_ID ],

src/BigCommerce/Container/Import.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ private function cron( Container $container ) {
121121
add_action( Processors\Cleanup::CLEAN_USERS_TRANSIENT, $this->create_callback( 'clean_users_group_transient', function () use ( $container ) {
122122
$container[ self::CLEANUP ]->clean_customer_group_transients();
123123
} ), 10, 0 );
124+
125+
add_action( Processors\Cleanup::CLEAN_PRODUCTS_TRANSIENT, $this->create_callback( 'clean_products_data_transient', function ( $offset ) use ( $container ) {
126+
$container[ self::CLEANUP ]->clean_products_transient( $offset );
127+
} ), 10, 1 );
124128
}
125129

126130
private function process( Container $container ) {
@@ -195,7 +199,7 @@ private function process( Container $container ) {
195199
};
196200

197201
$container[ self::CLEANUP ] = function ( Container $container ) {
198-
return new Processors\Cleanup( $container[ self::LARGE_BATCH_SIZE ] );
202+
return new Processors\Cleanup( $container[ Api::CACHE_HANDLER ], $container[ self::LARGE_BATCH_SIZE ] );
199203
};
200204

201205
$container[ self::ERROR ] = function ( Container $container ) {

src/BigCommerce/Container/Settings.php

+52
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33

44
namespace BigCommerce\Container;
55

6+
use BigCommerce\Api\Api_Scopes_Validator;
7+
use BigCommerce\Api\Base_Client;
8+
use BigCommerce\Api\v3\Api\CatalogApi;
9+
use BigCommerce\Api\v3\Api\ChannelsApi;
610
use BigCommerce\Import\Runner\Cron_Runner;
711
use BigCommerce\Import\Runner\Status;
812
use BigCommerce\Merchant\Onboarding_Api;
913
use BigCommerce\Nav_Menu\Nav_Items_Meta_Box;
1014
use BigCommerce\Post_Types\Product\Product;
1115
use BigCommerce\Settings\Abort_Import;
1216
use BigCommerce\Settings\Connection_Status;
17+
use BigCommerce\Settings\Flush_Cache;
1318
use BigCommerce\Settings\Import_Now;
1419
use BigCommerce\Settings\Import_Status;
1520
use BigCommerce\Settings\Onboarding_Progress;
@@ -80,6 +85,7 @@ class Settings extends Provider {
8085
const ONBOARDING_PROGRESS = 'settings.onboarding.progress_bar';
8186
const SITE_URL_SYNC = 'settings.site_url_sync';
8287
const ABORT_IMPORT = 'settings.abort_product_import';
88+
const FLUSH_CACHE = 'settings.flush_cache';
8389

8490
const CONFIG_STATUS = 'settings.configuration_status';
8591
const CONFIG_DISPLAY_MENUS = 'settings.configuration_display_menus';
@@ -203,6 +209,41 @@ private function api_credentials( Container $container ) {
203209
$container[ self::API_SECTION ]->do_api_settings_updated_action( $new_value, $old_value );
204210
}
205211
} );
212+
213+
$pre_update_options_action = $this->create_callback( 'api_credentials_pre_update_action', function ($new_value, $old_value, $option ) use ( $container ) {
214+
if ( $old_value === $new_value ) {
215+
return $old_value;
216+
}
217+
218+
if ( $old_value === false ) {
219+
return $new_value;
220+
}
221+
222+
$config = $container[ Api::API_CONFIG_RENEWAL ]->renewal_config( $option, $new_value );
223+
$client = new Base_Client( $config );
224+
$channels_api = new ChannelsApi( $client );
225+
$api_validator = new Api_Scopes_Validator( $client );
226+
$catalog_api = new CatalogApi( $client );
227+
228+
try {
229+
$api_validator->validate();
230+
$channels_api->listChannels()->getData();
231+
$catalog_api->catalogSummaryGet();
232+
return $new_value;
233+
} catch ( \Exception $e ) {
234+
add_settings_error( Api_Credentials_Screen::NAME, 'submitted', __( 'Unable to connect to the BigCommerce API. Please re-enter your credentials.', 'bigcommerce' ), 'error' );
235+
add_settings_error( Api_Credentials_Screen::NAME, 'submitted', $e->getMessage(), 'error' );
236+
$container[ Api::API_CONFIG_RENEWAL ]->renewal_config( $option, $old_value );
237+
set_transient( 'settings_errors', get_settings_errors(), 30 );
238+
return $old_value;
239+
}
240+
} );
241+
242+
add_filter( 'pre_update_option_' . Api_Credentials::OPTION_STORE_URL, $pre_update_options_action, 10, 3 );
243+
add_filter( 'pre_update_option_' . Api_Credentials::OPTION_CLIENT_ID, $pre_update_options_action, 10, 3 );
244+
add_filter( 'pre_update_option_' . Api_Credentials::OPTION_CLIENT_SECRET, $pre_update_options_action, 10, 3 );
245+
add_filter( 'pre_update_option_' . Api_Credentials::OPTION_ACCESS_TOKEN, $pre_update_options_action, 10, 3 );
246+
206247
add_action( 'update_option_' . Api_Credentials::OPTION_STORE_URL, $update_options_action, 10, 2 );
207248
add_action( 'update_option_' . Api_Credentials::OPTION_CLIENT_ID, $update_options_action, 10, 2 );
208249
add_action( 'update_option_' . Api_Credentials::OPTION_CLIENT_SECRET, $update_options_action, 10, 2 );
@@ -654,6 +695,10 @@ private function diagnostics( Container $container ) {
654695
return new Abort_Import( $container[ self::SETTINGS_SCREEN ] );
655696
};
656697

698+
$container[ self::FLUSH_CACHE ] = function ( Container $container ) {
699+
return new Flush_Cache( $container[ self::SETTINGS_SCREEN ] );
700+
};
701+
657702
add_action( 'bigcommerce/settings/register/screen=' . Settings_Screen::NAME, $this->create_callback( 'diagnostics_settings_register', function () use ( $container ) {
658703
$container[ self::DIAGNOSTICS_SECTION ]->register_settings_section();
659704
} ), 90, 0 );
@@ -673,6 +718,13 @@ private function diagnostics( Container $container ) {
673718
add_action( 'admin_post_' . Troubleshooting_Diagnostics::ABORT_NAME, $this->create_callback( 'diagnostics_settings_abort_import_action', function () use ( $container ) {
674719
$container[ self::ABORT_IMPORT ]->abort( $container['import.cleanup'] );
675720
} ), 10, 0 );
721+
722+
$flush_cache = $this->create_callback( 'diagnostics_settings_handle_cache_flush', function () use ( $container ) {
723+
$container[ self::FLUSH_CACHE ]->handle_request();
724+
} );
725+
726+
add_action( 'admin_post_' . Troubleshooting_Diagnostics::FLUSH_USER, $flush_cache, 10, 0 );
727+
add_action( 'admin_post_' . Troubleshooting_Diagnostics::FLUSH_PRODUCTS, $flush_cache, 10, 0 );
676728
}
677729

678730
private function resources( Container $container ) {

0 commit comments

Comments
 (0)