Skip to content

Commit 8e55097

Browse files
committed
Replace plugin slug with file
Follow-up to https://core.trac.wordpress.org/changeset/62192
1 parent a658b51 commit 8e55097

1 file changed

Lines changed: 8 additions & 49 deletions

File tree

‎src/Connectors_Command.php‎

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function build_connector_item( string $connector_id, array $connector ):
220220
private function get_connector_status( string $connector_id, array $connector ): string {
221221
$auth = is_array( $connector['authentication'] ) ? $connector['authentication'] : array();
222222
$plugin = isset( $connector['plugin'] ) && is_array( $connector['plugin'] ) ? $connector['plugin'] : array();
223-
$plugin_slug = isset( $plugin['slug'] ) && is_string( $plugin['slug'] ) ? $plugin['slug'] : '';
223+
$plugin_file = isset( $plugin['file'] ) && is_string( $plugin['file'] ) ? $plugin['file'] : '';
224224
$method = isset( $auth['method'] ) && is_string( $auth['method'] ) ? $auth['method'] : '';
225225
$setting = isset( $auth['setting_name'] ) && is_string( $auth['setting_name'] ) ? $auth['setting_name'] : '';
226226

@@ -232,15 +232,18 @@ private function get_connector_status( string $connector_id, array $connector ):
232232
}
233233
}
234234

235-
if ( ! $plugin_slug ) {
236-
return 'active';
235+
if ( ! $plugin_file ) {
236+
return 'not installed';
237237
}
238238

239-
if ( $this->is_plugin_active( $plugin_slug ) ) {
239+
240+
if ( is_plugin_active( $plugin_file ) ) {
240241
return 'active';
241242
}
243+
244+
$is_installed = file_exists( wp_normalize_path( WP_PLUGIN_DIR . '/' . $file ) );
242245

243-
if ( $this->is_plugin_installed( $plugin_slug ) ) {
246+
if ( $is_installed) {
244247
return 'installed';
245248
}
246249

@@ -256,48 +259,4 @@ private function get_connector_status( string $connector_id, array $connector ):
256259
private function scalar_to_string( $value ): string {
257260
return is_scalar( $value ) ? (string) $value : '';
258261
}
259-
260-
/**
261-
* Checks whether a plugin is installed, given its slug.
262-
*
263-
* @param string $slug The WordPress.org plugin slug.
264-
* @return bool
265-
*/
266-
private function is_plugin_installed( string $slug ): bool {
267-
if ( ! function_exists( 'get_plugins' ) ) {
268-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
269-
}
270-
271-
foreach ( array_keys( get_plugins() ) as $plugin_file ) {
272-
if ( strpos( $plugin_file, $slug . '/' ) === 0 || $plugin_file === $slug . '.php' ) {
273-
return true;
274-
}
275-
}
276-
277-
return false;
278-
}
279-
280-
/**
281-
* Checks whether a plugin is active, given its slug.
282-
*
283-
* @param string $slug The WordPress.org plugin slug.
284-
* @return bool
285-
*/
286-
private function is_plugin_active( string $slug ): bool {
287-
if ( ! function_exists( 'is_plugin_active' ) ) {
288-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
289-
}
290-
291-
$active_plugins = (array) get_option( 'active_plugins', array() );
292-
foreach ( $active_plugins as $plugin_file ) {
293-
if ( ! is_string( $plugin_file ) ) {
294-
continue;
295-
}
296-
if ( strpos( $plugin_file, $slug . '/' ) === 0 || $plugin_file === $slug . '.php' ) {
297-
return true;
298-
}
299-
}
300-
301-
return false;
302-
}
303262
}

0 commit comments

Comments
 (0)