Include inactive plugins in system status
This commit is contained in:
parent
6f983fb4eb
commit
56fbcfd8af
|
@ -23,6 +23,7 @@ $environment = $system_status->get_environment_info();
|
|||
$database = $system_status->get_database_info();
|
||||
$post_type_counts = $system_status->get_post_type_counts();
|
||||
$active_plugins = $system_status->get_active_plugins();
|
||||
$inactive_plugins = $system_status->get_inactive_plugins();
|
||||
$theme = $system_status->get_theme_info();
|
||||
$security = $system_status->get_security_info();
|
||||
$settings = $system_status->get_settings();
|
||||
|
@ -603,6 +604,58 @@ $untested_plugins = $plugin_updates->get_untested_plugins( WC()->version, 'minor
|
|||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="wc_status_table widefat" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3" data-export-label="Inactive Plugins (<?php echo count( $inactive_plugins ); ?>)"><h2><?php esc_html_e( 'Inactive plugins', 'woocommerce' ); ?> (<?php echo count( $inactive_plugins ); ?>)</h2></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $inactive_plugins as $plugin ) {
|
||||
if ( ! empty( $plugin['name'] ) ) {
|
||||
$dirname = dirname( $plugin['plugin'] );
|
||||
|
||||
// Link the plugin name to the plugin url if available.
|
||||
$plugin_name = esc_html( $plugin['name'] );
|
||||
if ( ! empty( $plugin['url'] ) ) {
|
||||
$plugin_name = '<a href="' . esc_url( $plugin['url'] ) . '" aria-label="' . esc_attr__( 'Visit plugin homepage', 'woocommerce' ) . '" target="_blank">' . $plugin_name . '</a>';
|
||||
}
|
||||
|
||||
$version_string = '';
|
||||
$network_string = '';
|
||||
if ( strstr( $plugin['url'], 'woothemes.com' ) || strstr( $plugin['url'], 'woocommerce.com' ) ) {
|
||||
if ( ! empty( $plugin['version_latest'] ) && version_compare( $plugin['version_latest'], $plugin['version'], '>' ) ) {
|
||||
/* translators: %s: plugin latest version */
|
||||
$version_string = ' – <strong style="color:red;">' . sprintf( esc_html__( '%s is available', 'woocommerce' ), $plugin['version_latest'] ) . '</strong>';
|
||||
}
|
||||
|
||||
if ( false !== $plugin['network_activated'] ) {
|
||||
$network_string = ' – <strong style="color:black;">' . esc_html__( 'Network enabled', 'woocommerce' ) . '</strong>';
|
||||
}
|
||||
}
|
||||
$untested_string = '';
|
||||
if ( array_key_exists( $plugin['plugin'], $untested_plugins ) ) {
|
||||
$untested_string = ' – <strong style="color:red;">' . esc_html__( 'Not tested with the active version of WooCommerce', 'woocommerce' ) . '</strong>';
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo wp_kses_post( $plugin_name ); ?></td>
|
||||
<td class="help"> </td>
|
||||
<td>
|
||||
<?php
|
||||
/* translators: %s: plugin author */
|
||||
printf( esc_html__( 'by %s', 'woocommerce' ), esc_html( $plugin['author_name'] ) );
|
||||
echo ' – ' . esc_html( $plugin['version'] ) . $version_string . $untested_string . $network_string; // WPCS: XSS ok.
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="wc_status_table widefat" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -341,6 +341,15 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'inactive_plugins' => array(
|
||||
'description' => __( 'Inactive plugins.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'theme' => array(
|
||||
'description' => __( 'Theme.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
|
@ -551,6 +560,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
'environment' => $this->get_environment_info(),
|
||||
'database' => $this->get_database_info(),
|
||||
'active_plugins' => $this->get_active_plugins(),
|
||||
'inactive_plugins' => $this->get_inactive_plugins(),
|
||||
'theme' => $this->get_theme_info(),
|
||||
'settings' => $this->get_settings(),
|
||||
'security' => $this->get_security_info(),
|
||||
|
@ -771,14 +781,6 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
* @return array
|
||||
*/
|
||||
public function get_active_plugins() {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/update.php';
|
||||
|
||||
if ( ! function_exists( 'get_plugin_updates' ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get both site plugins and network plugins.
|
||||
$active_plugins = (array) get_option( 'active_plugins', array() );
|
||||
if ( is_multisite() ) {
|
||||
$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
|
||||
|
@ -786,10 +788,66 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
}
|
||||
|
||||
$active_plugins_data = array();
|
||||
$available_updates = get_plugin_updates();
|
||||
|
||||
foreach ( $active_plugins as $plugin ) {
|
||||
$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
|
||||
$active_plugins_data[] = $this->format_plugin_data( $plugin, $data );
|
||||
}
|
||||
|
||||
return $active_plugins_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of inplugins active on the site.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_inactive_plugins() {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$plugins = get_plugins();
|
||||
$active_plugins = (array) get_option( 'active_plugins', array() );
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
|
||||
$active_plugins = array_merge( $active_plugins, $network_activated_plugins );
|
||||
}
|
||||
|
||||
$plugins_data = array();
|
||||
|
||||
foreach ( $plugins as $plugin => $data ) {
|
||||
if ( in_array( $plugin, $active_plugins, true ) ) {
|
||||
continue;
|
||||
}
|
||||
$plugins_data[] = $this->format_plugin_data( $plugin, $data );
|
||||
}
|
||||
|
||||
return $plugins_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format plugin data, including data on updates, into a standard format.
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @param string $plugin Plugin directory/file.
|
||||
* @param array $data Plugin data from WP.
|
||||
* @return array Formatted data.
|
||||
*/
|
||||
protected function format_plugin_data( $plugin, $data ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/update.php';
|
||||
|
||||
if ( ! function_exists( 'get_plugin_updates' ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( empty( $this->available_updates ) ) {
|
||||
$this->available_updates = get_plugin_updates();
|
||||
}
|
||||
|
||||
$dirname = dirname( $plugin );
|
||||
$version_latest = '';
|
||||
$slug = explode( '/', $plugin );
|
||||
|
@ -847,8 +905,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
$version_latest = $available_updates[ $plugin ]->update->new_version;
|
||||
}
|
||||
|
||||
// convert plugin data to json response format.
|
||||
$active_plugins_data[] = array(
|
||||
return array(
|
||||
'plugin' => $plugin,
|
||||
'name' => $data['Name'],
|
||||
'version' => $data['Version'],
|
||||
|
@ -860,9 +917,6 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return $active_plugins_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info on the current active theme, info on parent theme (if presnet)
|
||||
* and a list of template overrides.
|
||||
|
|
Loading…
Reference in New Issue