Skip to content

Commit b2cc828

Browse files
authored
Merge pull request #4860 from Automattic/develop
Staging release: v20230912.1
2 parents adeb000 + 41d9212 commit b2cc828

19 files changed

+1670
-721
lines changed

__tests__/e2e/package-lock.json

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

__tests__/e2e/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"author": "Automattic",
1313
"devDependencies": {
14-
"@automattic/eslint-plugin-wpvip": "^0.5.2",
14+
"@automattic/eslint-plugin-wpvip": "^0.6.0",
1515
"@babel/plugin-syntax-decorators": "^7.18.6",
1616
"@playwright/test": "^1.27.1",
1717
"asana-phrase": "^0.0.8",

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require-dev": {
3-
"phpunit/phpunit": "9.6.11",
3+
"phpunit/phpunit": "9.6.12",
44
"automattic/vipwpcs": "2.3.4",
55
"phpcompatibility/phpcompatibility-wp": "2.1.4",
66
"erusev/parsedown": "1.7.4",

composer.lock

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

integrations/block-data-api.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class BlockDataApiIntegration extends Integration {
2222
*/
2323
protected string $version = '1.0';
2424

25+
/**
26+
* Returns `true` if `Block Data API` is already available e.g. via customer code. We will use
27+
* this function to prevent activating of integration from platform side.
28+
*/
29+
public function is_loaded(): bool {
30+
return defined( 'VIP_BLOCK_DATA_API_LOADED' );
31+
}
32+
2533
/**
2634
* Applies hooks to load Block Data API plugin.
2735
*
@@ -30,8 +38,11 @@ class BlockDataApiIntegration extends Integration {
3038
public function load(): void {
3139
// Wait until plugins_loaded to give precedence to the plugin in the customer repo.
3240
add_action( 'plugins_loaded', function() {
33-
// Do not load plugin if already loaded by customer code.
34-
if ( defined( 'VIP_BLOCK_DATA_API_LOADED' ) ) {
41+
// Return if the integration is already loaded.
42+
//
43+
// In activate() method we do make sure to not activate the integration if its already loaded
44+
// but still adding it here as a safety measure i.e. if load() is called directly.
45+
if ( $this->is_loaded() ) {
3546
return;
3647
}
3748

@@ -44,4 +55,9 @@ public function load(): void {
4455
}
4556
} );
4657
}
58+
59+
/**
60+
* Configure `Block Data API` for VIP Platform.
61+
*/
62+
public function configure(): void {}
4763
}

integrations/integration.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ public function __construct( string $slug ) {
6363
* @private
6464
*/
6565
public function activate( array $options = [] ): void {
66+
// If integration is already available in customer code then don't activate it from platform side.
67+
if ( $this->is_loaded() ) {
68+
trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
69+
sprintf( 'Prevented activating of integration with slug "%s" because it is already loaded.', esc_html( $this->slug ) ),
70+
E_USER_WARNING
71+
);
72+
}
73+
6674
// Don't do anything if integration is already activated.
6775
if ( $this->is_active() ) {
6876
trigger_error( sprintf( 'VIP Integration with slug "%s" is already activated.', esc_html( $this->get_slug() ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
69-
return;
7077
}
7178

7279
$this->is_active = true;
@@ -102,6 +109,14 @@ public function get_slug(): string {
102109
return $this->slug;
103110
}
104111

112+
/**
113+
* Returns `true` if the integration is already available e.g. via customer code. We will use
114+
* this function to prevent activating of integration again.
115+
*
116+
* @private
117+
*/
118+
abstract public function is_loaded(): bool;
119+
105120
/**
106121
* Implement custom action and filter calls to load integration here.
107122
*
@@ -112,4 +127,14 @@ public function get_slug(): string {
112127
* @private
113128
*/
114129
abstract public function load(): void;
130+
131+
/**
132+
* Configure the integration for VIP platform.
133+
*
134+
* If we want to implement functionality only if the integration is enabled via VIP
135+
* then we will use this function.
136+
*
137+
* @private
138+
*/
139+
abstract public function configure(): void;
115140
}

integrations/integrations.php

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public function activate_platform_integrations() {
6969
$this->activate( $slug, [
7070
'config' => $vip_config->get_site_config(),
7171
] );
72+
73+
// If integration is activated successfully without any error then configure.
74+
if ( $integration->is_active() ) {
75+
$integration->configure();
76+
}
7277
}
7378
}
7479
}

integrations/parsely.php

+44-3
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,45 @@
1313
* @private
1414
*/
1515
class ParselyIntegration extends Integration {
16+
/**
17+
* Returns `true` if `Parse.ly` is already available e.g. customer code. We will use
18+
* this function to prevent loading of integration again from platform side.
19+
*/
20+
public function is_loaded(): bool {
21+
return class_exists( 'Parsely' ) || class_exists( 'Parsely\Parsely' );
22+
}
23+
1624
/**
1725
* Loads the plugin.
1826
*
1927
* @private
2028
*/
2129
public function load(): void {
22-
// Do not load plugin if already loaded by customer code.
23-
if ( class_exists( 'Parsely\Parsely' ) ) {
30+
// Return if the integration is already loaded.
31+
//
32+
// In activate() method we do make sure to not activate the integration if its already loaded
33+
// but still adding it here as a safety measure i.e. if load() is called directly.
34+
if ( $this->is_loaded() ) {
2435
return;
2536
}
2637

2738
// Activating the integration via setting constant whose implementation is already
2839
// handled via Automattic\VIP\WP_Parsely_Integration (ideally we should move
2940
// all the implementation here such that there will be only one way of managing
3041
// the plugin).
31-
define( 'VIP_PARSELY_ENABLED', true );
42+
if ( ! defined( 'VIP_PARSELY_ENABLED' ) ) {
43+
define( 'VIP_PARSELY_ENABLED', true );
44+
}
45+
}
3246

47+
/**
48+
* Configure `Parse.ly` for VIP Platform.
49+
*
50+
* @private
51+
*/
52+
public function configure(): void {
3353
add_filter( 'wp_parsely_credentials', array( $this, 'wp_parsely_credentials_callback' ) );
54+
add_filter( 'wp_parsely_managed_options', array( $this, 'wp_parsely_managed_options_callback' ) );
3455
}
3556

3657
/**
@@ -55,4 +76,24 @@ public function wp_parsely_credentials_callback( $original_credentials ) {
5576
// and we have to hide the credential banner warning or more.
5677
return array_merge( array( 'is_managed' => true ), $credentials );
5778
}
79+
80+
/**
81+
* Callback for `wp_parsely_managed_options` filter.
82+
*
83+
* @param array $value Value passed to filter.
84+
*
85+
* @return array
86+
*/
87+
public function wp_parsely_managed_options_callback( $value ) {
88+
return array(
89+
'force_https_canonicals' => true,
90+
'meta_type' => 'repeated_metas',
91+
// Managed options that will obey the values on database.
92+
'cats_as_tags' => null,
93+
'content_id_prefix' => null,
94+
'logo' => null,
95+
'lowercase_tags' => null,
96+
'use_top_level_cats' => null,
97+
);
98+
}
5899
}

package-lock.json

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

search/search-dev-tools/.babelrc.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
],
1515
"plugins": [
1616
[ "@babel/plugin-transform-react-jsx", { "pragma": "h", "pragmaFrag": "Fragment" } ],
17-
[ "@babel/plugin-proposal-class-properties" ],
18-
[ "@babel/plugin-proposal-object-rest-spread", { "loose": true } ],
17+
[ "@babel/plugin-transform-class-properties" ],
18+
[ "@babel/plugin-transform-object-rest-spread", { "loose": true } ],
1919
[ "@babel/plugin-transform-object-assign" ],
20-
[ "@babel/plugin-proposal-private-property-in-object" ]
20+
[ "@babel/plugin-transform-private-property-in-object" ]
2121
]
2222
}

search/search-dev-tools/.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"root": true,
3-
"plugins": ["@babel"],
43
"extends": [
5-
"plugin:@automattic/wpvip/base",
4+
"plugin:@automattic/wpvip/javascript",
65
"plugin:@automattic/wpvip/react",
76
"preact"
87
],

search/search-dev-tools/build/bundle.js

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

0 commit comments

Comments
 (0)