* WooCommerce Admin: Feature plugin main class.
namespace Automattic\WooCommerce\Internal\Admin;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\API;
use Automattic\WooCommerce\Admin\Notes\Notes;
use Automattic\WooCommerce\Internal\Admin\Notes\OrderMilestones;
use Automattic\WooCommerce\Internal\Admin\Notes\WooSubscriptionsNotes;
use Automattic\WooCommerce\Internal\Admin\Notes\TrackingOptIn;
use Automattic\WooCommerce\Internal\Admin\Notes\WooCommercePayments;
use Automattic\WooCommerce\Internal\Admin\Notes\InstallJPAndWCSPlugins;
use Automattic\WooCommerce\Internal\Admin\Notes\SellingOnlineCourses;
use Automattic\WooCommerce\Internal\Admin\Notes\MagentoMigration;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\PluginsHelper;
use Automattic\WooCommerce\Admin\PluginsInstaller;
use Automattic\WooCommerce\Admin\ReportExporter;
use Automattic\WooCommerce\Admin\ReportsSync;
use Automattic\WooCommerce\Internal\Admin\CategoryLookup;
use Automattic\WooCommerce\Internal\Admin\Events;
use Automattic\WooCommerce\Internal\Admin\Onboarding\Onboarding;
* Feature plugin main class.
* @internal This file will not be bundled with woo core, only the feature plugin.
* @internal Note this is not called WC_Admin due to a class already existing in core with that name.
* The single instance of the class.
protected static $instance = null;
* Indicates if init has been invoked already.
private bool $initialized = false;
protected function __construct() {}
* @return object Instance.
final public static function instance() {
if ( null === static::$instance ) {
static::$instance = new static();
return static::$instance;
* Init the feature plugin, only if we can detect both Gutenberg and WooCommerce.
// Bail if WC isn't initialized (This can be called from WCAdmin's entrypoint).
if ( ! defined( 'WC_ABSPATH' ) ) {
if ( $this->initialized ) {
$this->initialized = true;
// 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';
require_once WC_ADMIN_ABSPATH . '/src/Admin/Notes/DeprecatedNotes.php';
require_once WC_ADMIN_ABSPATH . '/includes/react-admin/core-functions.php';
require_once WC_ADMIN_ABSPATH . '/includes/react-admin/feature-config.php';
require_once WC_ADMIN_ABSPATH . '/includes/react-admin/wc-admin-update-functions.php';
require_once WC_ADMIN_ABSPATH . '/includes/react-admin/class-experimental-abtest.php';
if ( did_action( 'plugins_loaded' ) ) {
self::on_plugins_loaded();
// Make sure we hook into `plugins_loaded` before core's Automattic\WooCommerce\Package::init().
// If core is network activated but we aren't, the packaged version of WooCommerce Admin will
// attempt to use a data store that hasn't been loaded yet - because we've defined our constants here.
// See: https://github.com/woocommerce/woocommerce-admin/issues/3869.
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), 9 );
* Setup plugin once all other plugins are loaded.
public function on_plugins_loaded() {
protected function define_constants() {
$this->define( 'WC_ADMIN_APP', 'wc-admin-app' );
$this->define( 'WC_ADMIN_ABSPATH', WC_ABSPATH );
$this->define( 'WC_ADMIN_DIST_JS_FOLDER', 'assets/client/admin/' );
$this->define( 'WC_ADMIN_DIST_CSS_FOLDER', 'assets/client/admin/' );
$this->define( 'WC_ADMIN_PLUGIN_FILE', WC_PLUGIN_FILE );
* Define the WC Admin Images Folder URL.
if ( ! defined( 'WC_ADMIN_IMAGES_FOLDER_URL' ) ) {
* Define the WC Admin Images Folder URL.
define( 'WC_ADMIN_IMAGES_FOLDER_URL', plugins_url( 'assets/images', WC_PLUGIN_FILE ) );
* Define the current WC Admin version.
if ( ! defined( 'WC_ADMIN_VERSION_NUMBER' ) ) {
* Define the current WC Admin version.
define( 'WC_ADMIN_VERSION_NUMBER', '3.3.0' );
* Include WC Admin classes.
public function includes() {
// Initialize Database updates, option migrations, and Notes.
Events::instance()->init();
// Initialize Plugins Installer.
PluginsInstaller::init();
if ( Features::is_enabled( 'onboarding' ) ) {
if ( Features::is_enabled( 'analytics' ) ) {
// Initialize Reports syncing.
CategoryLookup::instance()->init();
// Initialize Reports exporter.
// @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue.
new WooSubscriptionsNotes();
new WooCommercePayments();
new InstallJPAndWCSPlugins();
new SellingOnlineCourses();
* Set up our admin hooks and plugin loader.
protected function hooks() {
add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ), 0 );
WCAdminAssets::get_instance();
* Overwrites the allowed features array using a local `feature-config.php` file.
* @param array $features Array of feature slugs.
public function replace_supported_features( $features ) {
* Get additional feature config
$feature_config = apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
$features = array_keys( array_filter( $feature_config ) );
* Define constant if not already set.
* @param string $name Constant name.
* @param string|bool $value Constant value.
protected function define( $name, $value ) {
if ( ! defined( $name ) ) {
private function __clone() {}
public function __wakeup() {