Skip to content

Commit

Permalink
Merge pull request #4860 from Automattic/develop
Browse files Browse the repository at this point in the history
Staging release: v20230912.1
  • Loading branch information
WPprodigy authored Sep 12, 2023
2 parents adeb000 + 41d9212 commit b2cc828
Show file tree
Hide file tree
Showing 19 changed files with 1,670 additions and 721 deletions.
423 changes: 375 additions & 48 deletions __tests__/e2e/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __tests__/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"author": "Automattic",
"devDependencies": {
"@automattic/eslint-plugin-wpvip": "^0.5.2",
"@automattic/eslint-plugin-wpvip": "^0.6.0",
"@babel/plugin-syntax-decorators": "^7.18.6",
"@playwright/test": "^1.27.1",
"asana-phrase": "^0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"phpunit/phpunit": "9.6.11",
"phpunit/phpunit": "9.6.12",
"automattic/vipwpcs": "2.3.4",
"phpcompatibility/phpcompatibility-wp": "2.1.4",
"erusev/parsedown": "1.7.4",
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions integrations/block-data-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class BlockDataApiIntegration extends Integration {
*/
protected string $version = '1.0';

/**
* Returns `true` if `Block Data API` is already available e.g. via customer code. We will use
* this function to prevent activating of integration from platform side.
*/
public function is_loaded(): bool {
return defined( 'VIP_BLOCK_DATA_API_LOADED' );
}

/**
* Applies hooks to load Block Data API plugin.
*
Expand All @@ -30,8 +38,11 @@ class BlockDataApiIntegration extends Integration {
public function load(): void {
// Wait until plugins_loaded to give precedence to the plugin in the customer repo.
add_action( 'plugins_loaded', function() {
// Do not load plugin if already loaded by customer code.
if ( defined( 'VIP_BLOCK_DATA_API_LOADED' ) ) {
// Return if the integration is already loaded.
//
// In activate() method we do make sure to not activate the integration if its already loaded
// but still adding it here as a safety measure i.e. if load() is called directly.
if ( $this->is_loaded() ) {
return;
}

Expand All @@ -44,4 +55,9 @@ public function load(): void {
}
} );
}

/**
* Configure `Block Data API` for VIP Platform.
*/
public function configure(): void {}
}
27 changes: 26 additions & 1 deletion integrations/integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ public function __construct( string $slug ) {
* @private
*/
public function activate( array $options = [] ): void {
// If integration is already available in customer code then don't activate it from platform side.
if ( $this->is_loaded() ) {
trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
sprintf( 'Prevented activating of integration with slug "%s" because it is already loaded.', esc_html( $this->slug ) ),
E_USER_WARNING
);
}

// Don't do anything if integration is already activated.
if ( $this->is_active() ) {
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
return;
}

$this->is_active = true;
Expand Down Expand Up @@ -102,6 +109,14 @@ public function get_slug(): string {
return $this->slug;
}

/**
* Returns `true` if the integration is already available e.g. via customer code. We will use
* this function to prevent activating of integration again.
*
* @private
*/
abstract public function is_loaded(): bool;

/**
* Implement custom action and filter calls to load integration here.
*
Expand All @@ -112,4 +127,14 @@ public function get_slug(): string {
* @private
*/
abstract public function load(): void;

/**
* Configure the integration for VIP platform.
*
* If we want to implement functionality only if the integration is enabled via VIP
* then we will use this function.
*
* @private
*/
abstract public function configure(): void;
}
5 changes: 5 additions & 0 deletions integrations/integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public function activate_platform_integrations() {
$this->activate( $slug, [
'config' => $vip_config->get_site_config(),
] );

// If integration is activated successfully without any error then configure.
if ( $integration->is_active() ) {
$integration->configure();
}
}
}
}
Expand Down
47 changes: 44 additions & 3 deletions integrations/parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,45 @@
* @private
*/
class ParselyIntegration extends Integration {
/**
* Returns `true` if `Parse.ly` is already available e.g. customer code. We will use
* this function to prevent loading of integration again from platform side.
*/
public function is_loaded(): bool {
return class_exists( 'Parsely' ) || class_exists( 'Parsely\Parsely' );
}

/**
* Loads the plugin.
*
* @private
*/
public function load(): void {
// Do not load plugin if already loaded by customer code.
if ( class_exists( 'Parsely\Parsely' ) ) {
// Return if the integration is already loaded.
//
// In activate() method we do make sure to not activate the integration if its already loaded
// but still adding it here as a safety measure i.e. if load() is called directly.
if ( $this->is_loaded() ) {
return;
}

// Activating the integration via setting constant whose implementation is already
// handled via Automattic\VIP\WP_Parsely_Integration (ideally we should move
// all the implementation here such that there will be only one way of managing
// the plugin).
define( 'VIP_PARSELY_ENABLED', true );
if ( ! defined( 'VIP_PARSELY_ENABLED' ) ) {
define( 'VIP_PARSELY_ENABLED', true );
}
}

/**
* Configure `Parse.ly` for VIP Platform.
*
* @private
*/
public function configure(): void {
add_filter( 'wp_parsely_credentials', array( $this, 'wp_parsely_credentials_callback' ) );
add_filter( 'wp_parsely_managed_options', array( $this, 'wp_parsely_managed_options_callback' ) );
}

/**
Expand All @@ -55,4 +76,24 @@ public function wp_parsely_credentials_callback( $original_credentials ) {
// and we have to hide the credential banner warning or more.
return array_merge( array( 'is_managed' => true ), $credentials );
}

/**
* Callback for `wp_parsely_managed_options` filter.
*
* @param array $value Value passed to filter.
*
* @return array
*/
public function wp_parsely_managed_options_callback( $value ) {
return array(
'force_https_canonicals' => true,
'meta_type' => 'repeated_metas',
// Managed options that will obey the values on database.
'cats_as_tags' => null,
'content_id_prefix' => null,
'logo' => null,
'lowercase_tags' => null,
'use_top_level_cats' => null,
);
}
}
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions search/search-dev-tools/.babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
],
"plugins": [
[ "@babel/plugin-transform-react-jsx", { "pragma": "h", "pragmaFrag": "Fragment" } ],
[ "@babel/plugin-proposal-class-properties" ],
[ "@babel/plugin-proposal-object-rest-spread", { "loose": true } ],
[ "@babel/plugin-transform-class-properties" ],
[ "@babel/plugin-transform-object-rest-spread", { "loose": true } ],
[ "@babel/plugin-transform-object-assign" ],
[ "@babel/plugin-proposal-private-property-in-object" ]
[ "@babel/plugin-transform-private-property-in-object" ]
]
}
3 changes: 1 addition & 2 deletions search/search-dev-tools/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"root": true,
"plugins": ["@babel"],
"extends": [
"plugin:@automattic/wpvip/base",
"plugin:@automattic/wpvip/javascript",
"plugin:@automattic/wpvip/react",
"preact"
],
Expand Down
2 changes: 1 addition & 1 deletion search/search-dev-tools/build/bundle.js

Large diffs are not rendered by default.

Loading

0 comments on commit b2cc828

Please sign in to comment.