Load all classes with Composer's autoloader.

This commit is contained in:
Jeff Stieler 2019-07-29 14:04:17 -04:00
parent 73967f7251
commit 2752356c4d
19 changed files with 79 additions and 195 deletions

View File

@ -30,5 +30,15 @@
"phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer",
"phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier"
}
},
"autoload": {
"classmap": [
"includes/"
],
"files": [
"includes/core-functions.php",
"includes/feature-config.php",
"includes/page-controller/page-controller-functions.php"
]
}
}

View File

@ -1,7 +1,7 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "c4e5044bed13f99e535b3d692d12005c",
@ -1163,7 +1163,6 @@
"mock",
"xunit"
],
"abandoned": true,
"time": "2018-08-09T05:50:03+00:00"
},
{
@ -1970,12 +1969,12 @@
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
"url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git",
"reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"shasum": ""
},

View File

@ -16,8 +16,6 @@ class WC_Admin_Api_Init {
* Boostrap REST API.
*/
public function __construct() {
// Initialize classes.
add_action( 'plugins_loaded', array( $this, 'init_classes' ), 19 );
// Hook in data stores.
add_filter( 'woocommerce_data_stores', array( 'WC_Admin_Api_Init', 'add_data_stores' ) );
// REST API extensions init.
@ -28,113 +26,10 @@ class WC_Admin_Api_Init {
add_filter( 'woocommerce_rest_prepare_shop_order_object', array( __CLASS__, 'add_currency_symbol_to_order_response' ) );
}
/**
* Init classes.
*/
public function init_classes() {
// Interfaces.
require_once WC_ADMIN_ABSPATH . 'includes/interfaces/class-wc-admin-reports-data-store-interface.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-query.php';
// Common date time code.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-interval.php';
// Exceptions.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-parameter-exception.php';
// WC Class extensions.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order-trait.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order-refund.php';
// Segmentation.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-segmenting.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-stats-segmenting.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-stats-segmenting.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-stats-segmenting.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-stats-segmenting.php';
// Query classes for reports.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-revenue-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-variations-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-categories-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-downloads-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-downloads-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-customers-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-customers-stats-query.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-stock-stats-query.php';
// Data stores.
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-orders-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-products-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-variations-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-products-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-categories-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-taxes-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-coupons-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-downloads-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-customers-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php';
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php';
}
/**
* Init REST API.
*/
public function rest_api_init() {
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-admin-notes-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-admin-note-action-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-coupons-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-countries-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-download-ips-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-leaderboards-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-orders-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-products-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-categories-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-variations-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-reviews-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-variations-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-setting-options-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-categories-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-coupons-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-customers-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-customers-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-files-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-import-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-orders-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-orders-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-products-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-variations-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-products-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-taxes-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-stock-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-stock-stats-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-taxes-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-themes-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-customers-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-export-controller.php';
$controllers = array(
'WC_Admin_REST_Admin_Notes_Controller',
'WC_Admin_REST_Admin_Note_Action_Controller',
@ -176,10 +71,6 @@ class WC_Admin_Api_Init {
);
if ( WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) {
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-levels-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-profile-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-plugins-controller.php';
$controllers = array_merge(
$controllers,
array(
@ -425,5 +316,3 @@ class WC_Admin_Api_Init {
return $response;
}
}
new WC_Admin_Api_Init();

View File

@ -56,5 +56,3 @@ class WC_Admin_Events {
WC_Admin_Notes_Mobile_App::possibly_add_mobile_app_note();
}
}
WC_Admin_Events::instance()->init();

View File

@ -288,5 +288,3 @@ class WC_Admin_Install {
}
}
}
WC_Admin_Install::init();

View File

@ -127,17 +127,13 @@ class WC_Admin_Loader {
* Class loader for enabled WooCommerce Admin features/sections.
*/
public static function load_features() {
require_once WC_ADMIN_ABSPATH . 'includes/page-controller/class-wc-admin-page-controller.php';
require_once WC_ADMIN_ABSPATH . 'includes/page-controller/page-controller-functions.php';
$features = self::get_features();
foreach ( $features as $feature ) {
$feature = strtolower( $feature );
$file = WC_ADMIN_FEATURES_PATH . $feature . '/class-wc-admin-' . $feature . '.php';
if ( file_exists( $file ) ) {
require_once $file;
$feature = ucfirst( $feature );
self::$classes[] = 'WC_Admin_' . $feature;
$feature = strtolower( str_replace( '-', '_', $feature ) );
$feature = 'WC_Admin_' . ucwords( $feature, '_' );
if ( class_exists( $feature ) ) {
new $feature;
}
}
}
@ -740,5 +736,3 @@ class WC_Admin_Loader {
return apply_filters( 'wc_admin_get_user_data_fields', array() );
}
}
new WC_Admin_Loader();

View File

@ -797,5 +797,3 @@ class WC_Admin_Reports_Sync {
wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'order' ) );
}
}
WC_Admin_Reports_Sync::init();

View File

@ -181,5 +181,3 @@ class WC_Admin_Report_Exporter {
}
}
}
WC_Admin_Report_Exporter::init();

View File

@ -9,11 +9,11 @@
/**
* Contains backend logic for the activity panel feature.
*/
class WC_Admin_Activity_Panel {
class WC_Admin_Activity_Panels {
/**
* Class instance.
*
* @var WC_Admin_Activity_Panel instance
* @var WC_Admin_Activity_Panels instance
*/
protected static $instance = null;
@ -69,5 +69,3 @@ class WC_Admin_Activity_Panel {
WC_Admin_Notes_Settings_Notes::add_notes_for_settings_that_have_moved();
}
}
new WC_Admin_Activity_Panel();

View File

@ -117,5 +117,3 @@ class WC_Admin_Analytics_Dashboard {
array_unshift( $submenu['woocommerce'], $menu );
}
}
new WC_Admin_Analytics_Dashboard();

View File

@ -152,5 +152,3 @@ class WC_Admin_Analytics {
}
}
}
new WC_Admin_Analytics();

View File

@ -127,5 +127,3 @@ class WC_Admin_Onboarding_Tasks {
return false;
}
}
WC_Admin_Onboarding_Tasks::get_instance();

View File

@ -49,7 +49,9 @@ class WC_Admin_Onboarding {
return;
}
$this->includes();
// Include WC Admin Onboarding classes.
WC_Admin_Onboarding_Tasks::get_instance();
add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader.
add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) );
add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) );
@ -59,13 +61,6 @@ class WC_Admin_Onboarding {
add_filter( 'woocommerce_rest_prepare_themes', array( $this, 'add_uploaded_theme_data' ) );
}
/**
* Include WC Admin Onboarding classes.
*/
public function includes() {
require_once WC_ADMIN_FEATURES_PATH . 'onboarding/class-wc-admin-onboarding-tasks.php';
}
/**
* Returns true if the profiler should be displayed (not completed and not skipped).
*
@ -386,5 +381,3 @@ class WC_Admin_Onboarding {
$response = rest_do_request( $request );
}
}
WC_Admin_Onboarding::get_instance();

View File

@ -56,5 +56,3 @@ class WC_Admin_Notes_Historical_Data {
$note->save();
}
}
new WC_Admin_Notes_Historical_Data();

View File

@ -319,5 +319,3 @@ class WC_Admin_Notes_Order_Milestones {
$note->save();
}
}
new WC_Admin_Notes_Order_Milestones();

View File

@ -48,5 +48,3 @@ class WC_Admin_Notes_Welcome_Message {
$note->save();
}
}
new WC_Admin_Notes_Welcome_Message();

View File

@ -455,5 +455,3 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
}
}
}
new WC_Admin_Notes_Woo_Subscriptions_Notes();

View File

@ -181,5 +181,3 @@ class WC_Admin_Notes {
}
}
}
WC_Admin_Notes::init();

View File

@ -19,6 +19,51 @@
defined( 'ABSPATH' ) || exit;
/**
* Autoload packages.
*
* We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader.
* If the autoloader is not present, let's log the failure and display a nice admin notice.
*/
$autoloader = __DIR__ . '/vendor/autoload.php';
if ( is_readable( $autoloader ) ) {
require $autoloader;
} else {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( // phpcs:ignore
sprintf(
/* translators: 1: composer command. 2: plugin directory */
esc_html__( 'Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce-admin' ),
'`composer install`',
'`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`'
)
);
}
/**
* Outputs an admin notice if composer install has not been ran.
*/
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: 1: composer command. 2: plugin directory */
esc_html__( 'Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce-admin' ),
'<code>composer install</code>',
'<code>' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '</code>'
);
?>
</p>
</div>
<?php
}
);
return;
}
/**
* Feature plugin main class.
*
@ -69,7 +114,6 @@ class WC_Admin_Feature_Plugin {
* @return void
*/
public function on_activation() {
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-install.php';
WC_Admin_Install::create_tables();
WC_Admin_Install::create_events();
}
@ -140,33 +184,22 @@ class WC_Admin_Feature_Plugin {
* Include WC Admin classes.
*/
public function includes() {
require_once WC_ADMIN_ABSPATH . 'includes/core-functions.php';
// Initialize the WC API extensions.
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-sync.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-install.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-events.php';
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-api-init.php';
require_once WC_ADMIN_ABSPATH . 'includes/export/class-wc-admin-report-csv-exporter.php';
require_once WC_ADMIN_ABSPATH . 'includes/export/class-wc-admin-report-exporter.php';
// Data triggers.
require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-notes-data-store.php';
WC_Admin_Reports_Sync::init();
WC_Admin_Install::init();
WC_Admin_Events::instance()->init();
new WC_Admin_Api_Init();
WC_Admin_Report_Exporter::init();
// CRUD classes.
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-note.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes.php';
WC_Admin_Notes::init();
// Admin note providers.
// @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue.
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-new-sales-record.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-settings-notes.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-giving-feedback-notes.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-historical-data.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-order-milestones.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-mobile-app.php';
require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-welcome-message.php';
new WC_Admin_Notes_Woo_Subscriptions_Notes();
new WC_Admin_Notes_Historical_Data();
new WC_Admin_Notes_Order_Milestones();
new WC_Admin_Notes_Welcome_Message();
}
/**
@ -181,11 +214,6 @@ class WC_Admin_Feature_Plugin {
return $store_class;
}
// Include our store class here instead of wc_admin_plugins_loaded()
// because ActionScheduler is hooked into `plugins_loaded` at a
// much higher priority.
require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-actionscheduler-wppoststore.php';
return 'WC_Admin_ActionScheduler_WPPostStore';
}
@ -210,7 +238,7 @@ class WC_Admin_Feature_Plugin {
remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 );
require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-loader.php';
new WC_Admin_Loader();
add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) );
add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) );
@ -293,9 +321,6 @@ class WC_Admin_Feature_Plugin {
* @param array $features Array of feature slugs.
*/
public function replace_supported_features( $features ) {
if ( ! function_exists( 'wc_admin_get_feature_config' ) ) {
require_once WC_ADMIN_ABSPATH . '/includes/feature-config.php';
}
$feature_config = apply_filters( 'wc_admin_get_feature_config', wc_admin_get_feature_config() );
$features = array_keys( array_filter( $feature_config ) );
return $features;