Added bail codes for WCA execution paths

This commit is contained in:
Ilyas Foo 2022-04-28 12:19:17 +08:00
parent 0389bc7cc3
commit bb05a6fc85
3 changed files with 62 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace Automattic\WooCommerce\Admin;
use Automattic\WooCommerce\Admin\DeprecatedClassFacade;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
/**
* Loader Class.
@ -12,6 +13,20 @@ use Automattic\WooCommerce\Admin\Features\Features;
*/
class Loader extends DeprecatedClassFacade {
/**
* The name of the non-deprecated class that this facade covers.
*
* @var string
*/
protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Loader';
/**
* The version that this class was deprecated in.
*
* @var string
*/
protected static $deprecated_in_version = '6.3.0';
/**
* Returns if a specific wc-admin feature is enabled.
*
@ -55,4 +70,21 @@ class Loader extends DeprecatedClassFacade {
wc_deprecated_function( 'is_embed_page', '6.3', '\Automattic\WooCommerce\Admin\PageController::is_embed_page()' );
return PageController::is_embed_page();
}
/**
* Determines if a minified JS file should be served.
*
* @param boolean $script_debug Only serve unminified files if script debug is on.
* @return boolean If js asset should use minified version.
*
* @deprecated since 6.3.0, use WCAdminAssets::should_use_minified_js_file( $script_debug )
*/
public static function should_use_minified_js_file( $script_debug ) {
// Bail if WC isn't initialized (This can be called from WCAdmin's entrypoint).
if ( ! defined( 'WC_ABSPATH' ) ) {
return;
}
wc_deprecated_function( 'should_use_minified_js_file', '6.3', '\Automattic\WooCommerce\Internal\Admin\WCAdminAssets::should_use_minified_js_file()' );
return WCAdminAssets::should_use_minified_js_file( $script_debug );
}
}

View File

@ -68,6 +68,11 @@ class FeaturePlugin {
* Init the feature plugin, only if we can detect both Gutenberg and WooCommerce.
*/
public function init() {
// Bail if WC isn't initialized (This can be called from WCAdmin's entrypoint).
if ( ! defined( 'WC_ABSPATH' ) ) {
return;
}
// Load the page controller functions file first to prevent fatal errors when disabling WooCommerce Admin.
$this->define_constants();
require_once WC_ADMIN_ABSPATH . '/includes/react-admin/page-controller-functions.php';

View File

@ -84,7 +84,7 @@ class Loader {
*/
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
add_action( 'admin_init', array( __CLASS__, 'is_using_installed_wc_admin_plugin' ) );
add_action( 'admin_init', array( __CLASS__, 'deactivate_wc_admin_plugin' ) );
}
/**
@ -111,6 +111,30 @@ class Loader {
}
}
/**
* Verifies which plugin version is being used. If WooCommerce Admin is installed and activated but not in use
* it will show a warning.
*/
public static function deactivate_wc_admin_plugin() {
if ( PluginsHelper::is_plugin_active( 'woocommerce-admin' ) ) {
$path = PluginsHelper::get_plugin_path_from_slug( 'woocommerce-admin' );
deactivate_plugins( $path );
add_action(
'admin_notices',
function() {
echo '<div class="error"><p>';
printf(
/* translators: %s: is referring to the plugin's name. */
esc_html__( '%1$s plugin has been deactivated to avoid conflicts with %2$s plugin.', 'woocommerce' ),
'<code>WooCommerce Admin</code>',
'<code>WooCommerce</code>'
);
echo '</p></div>';
}
);
}
}
/**
* Returns breadcrumbs for the current page.
*/