Agentic
4 months ago
BlockTemplates
1 month ago
EmailImprovements
1 year ago
EmailPreview
1 month ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
1 month ago
Onboarding
5 months ago
Orders
1 month ago
ProductForm
2 years ago
ProductReviews
1 month ago
RemoteFreeExtensions
1 month ago
Schedulers
1 month ago
Settings
6 days ago
Suggestions
1 month ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
1 month ago
CategoryLookup.php
4 years ago
Coupons.php
1 year ago
CouponsMovedTrait.php
5 months ago
CustomerEffortScoreTracks.php
7 months ago
Events.php
2 months ago
FeaturePlugin.php
4 months ago
Homescreen.php
1 month ago
Loader.php
1 month ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
1 month ago
RemoteInboxNotifications.php
3 years ago
Settings.php
6 days ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
6 days ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
FeaturePlugin.php
250 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Admin: Feature plugin main class. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\API; |
| 11 | use Automattic\WooCommerce\Admin\Notes\Notes; |
| 12 | use Automattic\WooCommerce\Internal\Admin\Notes\OrderMilestones; |
| 13 | use Automattic\WooCommerce\Internal\Admin\Notes\WooSubscriptionsNotes; |
| 14 | use Automattic\WooCommerce\Internal\Admin\Notes\TrackingOptIn; |
| 15 | use Automattic\WooCommerce\Internal\Admin\Notes\WooCommercePayments; |
| 16 | use Automattic\WooCommerce\Internal\Admin\Notes\InstallJPAndWCSPlugins; |
| 17 | use Automattic\WooCommerce\Internal\Admin\Notes\SellingOnlineCourses; |
| 18 | use Automattic\WooCommerce\Internal\Admin\Notes\MagentoMigration; |
| 19 | use Automattic\WooCommerce\Internal\Admin\Notes\ScheduledUpdatesPromotion; |
| 20 | use Automattic\WooCommerce\Admin\Features\Features; |
| 21 | use Automattic\WooCommerce\Admin\PluginsHelper; |
| 22 | use Automattic\WooCommerce\Admin\PluginsInstaller; |
| 23 | use Automattic\WooCommerce\Admin\ReportExporter; |
| 24 | use Automattic\WooCommerce\Admin\ReportsSync; |
| 25 | use Automattic\WooCommerce\Internal\Admin\CategoryLookup; |
| 26 | use Automattic\WooCommerce\Internal\Admin\Events; |
| 27 | use Automattic\WooCommerce\Internal\Admin\Onboarding\Onboarding; |
| 28 | |
| 29 | /** |
| 30 | * Feature plugin main class. |
| 31 | * |
| 32 | * @internal This file will not be bundled with woo core, only the feature plugin. |
| 33 | * @internal Note this is not called WC_Admin due to a class already existing in core with that name. |
| 34 | */ |
| 35 | class FeaturePlugin { |
| 36 | /** |
| 37 | * The single instance of the class. |
| 38 | * |
| 39 | * @var object |
| 40 | */ |
| 41 | protected static $instance = null; |
| 42 | |
| 43 | /** |
| 44 | * Indicates if init has been invoked already. |
| 45 | * |
| 46 | * @var bool |
| 47 | */ |
| 48 | private bool $initialized = false; |
| 49 | |
| 50 | /** |
| 51 | * Constructor |
| 52 | * |
| 53 | * @return void |
| 54 | */ |
| 55 | protected function __construct() {} |
| 56 | |
| 57 | /** |
| 58 | * Get class instance. |
| 59 | * |
| 60 | * @return object Instance. |
| 61 | */ |
| 62 | final public static function instance() { |
| 63 | if ( null === static::$instance ) { |
| 64 | static::$instance = new static(); |
| 65 | } |
| 66 | return static::$instance; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Init the feature plugin, only if we can detect both Gutenberg and WooCommerce. |
| 71 | */ |
| 72 | public function init() { |
| 73 | // Bail if WC isn't initialized (This can be called from WCAdmin's entrypoint). |
| 74 | if ( ! defined( 'WC_ABSPATH' ) ) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if ( $this->initialized ) { |
| 79 | return; |
| 80 | } |
| 81 | $this->initialized = true; |
| 82 | |
| 83 | // Load the page controller functions file first to prevent fatal errors when disabling WooCommerce Admin. |
| 84 | $this->define_constants(); |
| 85 | require_once WC_ADMIN_ABSPATH . '/includes/react-admin/page-controller-functions.php'; |
| 86 | require_once WC_ADMIN_ABSPATH . '/src/Admin/Notes/DeprecatedNotes.php'; |
| 87 | require_once WC_ADMIN_ABSPATH . '/includes/react-admin/core-functions.php'; |
| 88 | require_once WC_ADMIN_ABSPATH . '/includes/react-admin/feature-config.php'; |
| 89 | require_once WC_ADMIN_ABSPATH . '/includes/react-admin/wc-admin-update-functions.php'; |
| 90 | require_once WC_ADMIN_ABSPATH . '/includes/react-admin/class-experimental-abtest.php'; |
| 91 | |
| 92 | if ( did_action( 'plugins_loaded' ) ) { |
| 93 | self::on_plugins_loaded(); |
| 94 | } else { |
| 95 | // Make sure we hook into `plugins_loaded` before core's Automattic\WooCommerce\Package::init(). |
| 96 | // If core is network activated but we aren't, the packaged version of WooCommerce Admin will |
| 97 | // attempt to use a data store that hasn't been loaded yet - because we've defined our constants here. |
| 98 | // See: https://github.com/woocommerce/woocommerce-admin/issues/3869. |
| 99 | add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), 9 ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Setup plugin once all other plugins are loaded. |
| 105 | * |
| 106 | * @return void |
| 107 | */ |
| 108 | public function on_plugins_loaded() { |
| 109 | $this->hooks(); |
| 110 | $this->includes(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Define Constants. |
| 115 | * |
| 116 | * IMPORTANT: When adding new constants here, also add them to |
| 117 | * php-stubs/wc-constants.php for PHPStan static analysis. |
| 118 | */ |
| 119 | protected function define_constants() { |
| 120 | $this->define( 'WC_ADMIN_APP', 'wc-admin-app' ); |
| 121 | $this->define( 'WC_ADMIN_ABSPATH', WC_ABSPATH ); |
| 122 | $this->define( 'WC_ADMIN_DIST_JS_FOLDER', 'assets/client/admin/' ); |
| 123 | $this->define( 'WC_ADMIN_DIST_CSS_FOLDER', 'assets/client/admin/' ); |
| 124 | $this->define( 'WC_ADMIN_PLUGIN_FILE', WC_PLUGIN_FILE ); |
| 125 | |
| 126 | /** |
| 127 | * Define the WC Admin Images Folder URL. |
| 128 | * |
| 129 | * @deprecated 6.7.0 |
| 130 | * @var string |
| 131 | */ |
| 132 | if ( ! defined( 'WC_ADMIN_IMAGES_FOLDER_URL' ) ) { |
| 133 | /** |
| 134 | * Define the WC Admin Images Folder URL. |
| 135 | * |
| 136 | * @deprecated 6.7.0 |
| 137 | * @var string |
| 138 | */ |
| 139 | define( 'WC_ADMIN_IMAGES_FOLDER_URL', plugins_url( 'assets/images', WC_PLUGIN_FILE ) ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Define the current WC Admin version. |
| 144 | * |
| 145 | * @deprecated 6.4.0 |
| 146 | * @var string |
| 147 | */ |
| 148 | if ( ! defined( 'WC_ADMIN_VERSION_NUMBER' ) ) { |
| 149 | /** |
| 150 | * Define the current WC Admin version. |
| 151 | * |
| 152 | * @deprecated 6.4.0 |
| 153 | * @var string |
| 154 | */ |
| 155 | define( 'WC_ADMIN_VERSION_NUMBER', '3.3.0' ); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Include WC Admin classes. |
| 161 | */ |
| 162 | public function includes() { |
| 163 | // Initialize Database updates, option migrations, and Notes. |
| 164 | Events::instance()->init(); |
| 165 | Notes::init(); |
| 166 | |
| 167 | // Initialize Plugins Installer. |
| 168 | PluginsInstaller::init(); |
| 169 | PluginsHelper::init(); |
| 170 | |
| 171 | // Initialize API. |
| 172 | API\Init::instance(); |
| 173 | |
| 174 | if ( Features::is_enabled( 'onboarding' ) ) { |
| 175 | Onboarding::init(); |
| 176 | } |
| 177 | |
| 178 | if ( Features::is_enabled( 'analytics' ) ) { |
| 179 | // Initialize Reports syncing. |
| 180 | ReportsSync::init(); |
| 181 | CategoryLookup::instance()->init(); |
| 182 | |
| 183 | // Initialize Reports exporter. |
| 184 | ReportExporter::init(); |
| 185 | } |
| 186 | |
| 187 | // Admin note providers. |
| 188 | // @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue. |
| 189 | new WooSubscriptionsNotes(); |
| 190 | new OrderMilestones(); |
| 191 | new TrackingOptIn(); |
| 192 | new WooCommercePayments(); |
| 193 | new InstallJPAndWCSPlugins(); |
| 194 | new SellingOnlineCourses(); |
| 195 | new MagentoMigration(); |
| 196 | new ScheduledUpdatesPromotion(); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Set up our admin hooks and plugin loader. |
| 201 | */ |
| 202 | protected function hooks() { |
| 203 | add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ), 0 ); |
| 204 | |
| 205 | Loader::get_instance(); |
| 206 | WCAdminAssets::get_instance(); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /** |
| 211 | * Overwrites the allowed features array using a local `feature-config.php` file. |
| 212 | * |
| 213 | * @param array $features Array of feature slugs. |
| 214 | */ |
| 215 | public function replace_supported_features( $features ) { |
| 216 | /** |
| 217 | * Get additional feature config |
| 218 | * |
| 219 | * @since 6.5.0 |
| 220 | */ |
| 221 | $feature_config = apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() ); |
| 222 | $features = array_keys( array_filter( $feature_config ) ); |
| 223 | return $features; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Define constant if not already set. |
| 228 | * |
| 229 | * @param string $name Constant name. |
| 230 | * @param string|bool $value Constant value. |
| 231 | */ |
| 232 | protected function define( $name, $value ) { |
| 233 | if ( ! defined( $name ) ) { |
| 234 | define( $name, $value ); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Prevent cloning. |
| 240 | */ |
| 241 | private function __clone() {} |
| 242 | |
| 243 | /** |
| 244 | * Prevent unserializing. |
| 245 | */ |
| 246 | public function __wakeup() { |
| 247 | die(); |
| 248 | } |
| 249 | } |
| 250 |