2021-05-05 23:49:47 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Evaluates the spec and returns a status.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 12:50:33 +00:00
|
|
|
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
|
2021-05-05 23:49:47 +00:00
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
2021-08-19 14:39:02 +00:00
|
|
|
use Automattic\WooCommerce\Admin\PluginsHelper;
|
2021-05-05 23:49:47 +00:00
|
|
|
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator;
|
|
|
|
|
|
|
|
/**
|
2021-08-04 15:57:09 +00:00
|
|
|
* Evaluates the extension and returns it.
|
2021-05-05 23:49:47 +00:00
|
|
|
*/
|
|
|
|
class EvaluateExtension {
|
|
|
|
/**
|
2021-08-04 15:57:09 +00:00
|
|
|
* Evaluates the extension and returns it.
|
2021-05-05 23:49:47 +00:00
|
|
|
*
|
2021-08-04 15:57:09 +00:00
|
|
|
* @param object $extension The extension to evaluate.
|
|
|
|
* @return object The evaluated extension.
|
2021-05-05 23:49:47 +00:00
|
|
|
*/
|
2021-08-04 15:57:09 +00:00
|
|
|
public static function evaluate( $extension ) {
|
2021-05-05 23:49:47 +00:00
|
|
|
$rule_evaluator = new RuleEvaluator();
|
|
|
|
|
2021-08-04 15:57:09 +00:00
|
|
|
if ( isset( $extension->is_visible ) ) {
|
|
|
|
$is_visible = $rule_evaluator->evaluate( $extension->is_visible );
|
|
|
|
$extension->is_visible = $is_visible;
|
|
|
|
} else {
|
|
|
|
$extension->is_visible = true;
|
2021-05-05 23:49:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 14:39:02 +00:00
|
|
|
$installed_plugins = PluginsHelper::get_installed_plugin_slugs();
|
2021-10-05 12:27:30 +00:00
|
|
|
$activated_plugins = PluginsHelper::get_active_plugin_slugs();
|
2021-08-19 14:39:02 +00:00
|
|
|
$extension->is_installed = in_array( explode( ':', $extension->key )[0], $installed_plugins, true );
|
2021-10-05 12:27:30 +00:00
|
|
|
$extension->is_activated = in_array( explode( ':', $extension->key )[0], $activated_plugins, true );
|
2021-08-19 14:39:02 +00:00
|
|
|
|
2021-08-04 15:57:09 +00:00
|
|
|
return $extension;
|
2021-05-05 23:49:47 +00:00
|
|
|
}
|
|
|
|
}
|