Plugin Updates

This commit is contained in:
Tony Volpe
2024-04-02 20:23:21 +00:00
parent 96800520e8
commit 94170ec2c4
1514 changed files with 133309 additions and 105985 deletions

View File

@@ -20,7 +20,7 @@ class EvaluateExtension {
* @param object $extension The extension to evaluate.
* @return object The evaluated extension.
*/
public static function evaluate( $extension ) {
private static function evaluate( $extension ) {
global $wp_version;
$rule_evaluator = new RuleEvaluator();
@@ -49,4 +49,44 @@ class EvaluateExtension {
return $extension;
}
/**
* Evaluates the specs and returns the bundles with visible extensions.
*
* @param array $specs extensions spec array.
* @param array $allowed_bundles Optional array of allowed bundles to be returned.
* @return array The bundles and errors.
*/
public static function evaluate_bundles( $specs, $allowed_bundles = array() ) {
$bundles = array();
foreach ( $specs as $spec ) {
$spec = (object) $spec;
$bundle = (array) $spec;
$bundle['plugins'] = array();
if ( ! empty( $allowed_bundles ) && ! in_array( $spec->key, $allowed_bundles, true ) ) {
continue;
}
$errors = array();
foreach ( $spec->plugins as $plugin ) {
try {
$extension = self::evaluate( (object) $plugin );
if ( ! property_exists( $extension, 'is_visible' ) || $extension->is_visible ) {
$bundle['plugins'][] = $extension;
}
} catch ( \Throwable $e ) {
$errors[] = $e;
}
}
$bundles[] = $bundle;
}
return array(
'bundles' => $bundles,
'errors' => $errors,
);
}
}

View File

@@ -8,12 +8,13 @@ namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\DefaultFreeExtensions;
use Automattic\WooCommerce\Admin\RemoteSpecs\RemoteSpecsEngine;
/**
* Remote Payment Methods engine.
* This goes through the specs and gets eligible payment methods.
*/
class Init {
class Init extends RemoteSpecsEngine {
/**
* Constructor.
@@ -29,34 +30,39 @@ class Init {
* @return array
*/
public static function get_extensions( $allowed_bundles = array() ) {
$bundles = array();
$specs = self::get_specs();
$locale = get_user_locale();
foreach ( $specs as $spec ) {
$spec = (object) $spec;
$bundle = (array) $spec;
$bundle['plugins'] = array();
$specs = self::get_specs();
$results = EvaluateExtension::evaluate_bundles( $specs, $allowed_bundles );
$specs_to_return = $results['bundles'];
$specs_to_save = null;
if ( ! empty( $allowed_bundles ) && ! in_array( $spec->key, $allowed_bundles, true ) ) {
continue;
$plugins = array_filter(
$results['bundles'],
function( $bundle ) {
return count( $bundle['plugins'] ) > 0;
}
);
foreach ( $spec->plugins as $plugin ) {
try {
$extension = EvaluateExtension::evaluate( (object) $plugin );
if ( ! property_exists( $extension, 'is_visible' ) || $extension->is_visible ) {
$bundle['plugins'][] = $extension;
}
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
} catch ( \Throwable $e ) {
// Ignore errors.
}
}
$bundles[] = $bundle;
if ( empty( $plugins ) ) {
// When no plugins are visible, replace it with defaults and save for 3 hours.
$specs_to_save = DefaultFreeExtensions::get_all();
$specs_to_return = EvaluateExtension::evaluate_bundles( $specs_to_save, $allowed_bundles )['bundles'];
} elseif ( count( $results['errors'] ) > 0 ) {
// When suggestions is not empty but has errors, save it for 3 hours.
$specs_to_save = $specs;
}
return $bundles;
// When plugins is not empty but has errors, save it for 3 hours.
if ( count( $results['errors'] ) > 0 ) {
self::log_errors( $results['errors'] );
}
if ( $specs_to_save ) {
RemoteFreeExtensionsDataSourcePoller::get_instance()->set_specs_transient( array( $locale => $specs_to_save ), 3 * HOUR_IN_SECONDS );
}
return $specs_to_return;
}
/**