Skip to content

Commit 6a20a52

Browse files
committed
Cleanup how we autoload things. Rely on composer only instead of having a fallback to our own autoloader. Remove some code that we don't need
1 parent b2c71cb commit 6a20a52

File tree

2 files changed

+7
-187
lines changed

2 files changed

+7
-187
lines changed

autoload.php

-152
This file was deleted.

classifai.php

+7-35
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,14 @@ function classifai_define( $name, $value ) {
7777
require_once __DIR__ . '/config.php';
7878

7979
/**
80-
* Loads the CLASSIFAI PHP autoloader if possible.
80+
* Loads the autoloader if possible.
8181
*
8282
* @return bool True or false if autoloading was successful.
8383
*/
8484
function classifai_autoload() {
85-
if ( classifai_can_autoload() ) {
86-
require_once classifai_autoloader();
87-
88-
return true;
89-
} else {
90-
return false;
91-
}
92-
}
85+
if ( file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
86+
require_once CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php';
9387

94-
/**
95-
* In server mode we can autoload if autoloader file exists. For
96-
* test environments we prevent autoloading of the plugin to prevent
97-
* global pollution and for better performance.
98-
*/
99-
function classifai_can_autoload() {
100-
if ( file_exists( classifai_autoloader() ) ) {
10188
return true;
10289
} else {
10390
error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
@@ -108,32 +95,19 @@ function classifai_can_autoload() {
10895
}
10996
}
11097

111-
/**
112-
* Default is Composer's autoloader
113-
*/
114-
function classifai_autoloader() {
115-
if ( file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
116-
return CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php';
117-
} else {
118-
return CLASSIFAI_PLUGIN_DIR . '/autoload.php';
119-
}
120-
}
121-
12298
/**
12399
* Gets the installation message error.
124100
*
125-
* This was put in a function specifically because it's used both in WP-CLI and within an admin notice if not using
126-
* WP-CLI.
101+
* Used both in a WP-CLI context and within an admin notice.
127102
*
128103
* @return string
129104
*/
130105
function get_error_install_message() {
131-
return esc_html__( 'Error: Please run $ composer install in the classifai plugin directory.', 'classifai' );
106+
return esc_html__( 'Error: Please run $ composer install in the ClassifAI plugin directory.', 'classifai' );
132107
}
133108

134109
/**
135-
* Plugin code entry point. Singleton instance is used to maintain a common single
136-
* instance of the plugin throughout the current request's lifecycle.
110+
* Plugin code entry point.
137111
*
138112
* If autoloading failed an admin notice is shown and logged to
139113
* the PHP error_log.
@@ -159,7 +133,6 @@ function classifai_autorun() {
159133
}
160134
}
161135

162-
163136
/**
164137
* Generate a notice if autoload fails.
165138
*/
@@ -168,9 +141,8 @@ function classifai_autoload_notice() {
168141
error_log( get_error_install_message() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
169142
}
170143

171-
172144
/**
173-
* Register an activation hook that we can hook into.
145+
* Run functionality on plugin activation.
174146
*/
175147
function classifai_activation() {
176148
set_transient( 'classifai_activation_notice', 'classifai', HOUR_IN_SECONDS );

0 commit comments

Comments
 (0)