-
-
Save wordpressvn/2aa5beb676e7f1e32222b30c3926829e to your computer and use it in GitHub Desktop.
Utility to get plugin info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // no need to use this line. | |
/** | |
* Utility to get information on installed plugins. | |
* | |
* Returns an array of all installed plugins and indicates which are | |
* plugin are active and which are not. Array is keyed by the plugin's | |
* folder/slug.php (which is how WP looks at them) and includes the | |
* name, version, and true/false whether it is active or not. | |
* | |
* @see: https://codex.wordpress.org/Function_Reference/get_plugins | |
* @see: https://developer.wordpress.org/reference/functions/get_plugins/ | |
* @see: https://developer.wordpress.org/reference/functions/get_option/ | |
* | |
* @return $plugins array { | |
* An array of all installed plugins. | |
* | |
* @type array $plugin { | |
* The plugin information (note: array key is folder/slug.php) | |
* | |
* @type string $name | |
* @type string $version | |
* @type boolean $active | |
* } | |
* } | |
*/ | |
function my_get_plugin_info() { | |
// Get all plugins | |
include_once( 'wp-admin/includes/plugin.php' ); | |
$all_plugins = get_plugins(); | |
// Get active plugins | |
$active_plugins = get_option( 'active_plugins' ); | |
// Assemble array of name, version, and whether plugin is active (boolean) | |
foreach ( $all_plugins as $key => $value ) { | |
$is_active = ( in_array( $key, $active_plugins ) ) ? true : false; | |
$plugins[ $key ] = array( | |
'name' => $value['Name'], | |
'version' => $value['Version'], | |
'active' => $is_active, | |
); | |
} | |
return $plugins; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // No need to use this line. | |
/** | |
* Utility to get information on installed plugins. | |
* | |
* This utility gets the full installed plugin list (get_plugins()) and the | |
* active plugin list (get_option( 'active_plugins' )) and adds the data | |
* from the active plugin list to the full list as a boolean (key: 'Active'). | |
* | |
* @see: https://codex.wordpress.org/Function_Reference/get_plugins | |
* @see: https://developer.wordpress.org/reference/functions/get_plugins/ | |
* @see: https://developer.wordpress.org/reference/functions/get_option/ | |
* | |
* @return $plugins array { | |
* An array of all installed plugins. | |
* | |
* @type array $plugin { | |
* The plugin information (note: array key is folder/slug.php) | |
* | |
* @type string $Name | |
* @type string $PluginURI | |
* @type string $Version | |
* @type string $Description | |
* @type string $Author | |
* @type string $AuthorURI | |
* @type string $TextDomain | |
* @type string $DomainPath | |
* @type boolean $Network | |
* @type string $Title | |
* @type string $AuthorName | |
* @type boolean $Active | |
* } | |
* } | |
*/ | |
function my_get_plugins() { | |
// Get all plugins | |
include_once( 'wp-admin/includes/plugin.php' ); | |
$all_plugins = get_plugins(); | |
// Get active plugins | |
$active_plugins = get_option( 'active_plugins' ); | |
// Add 'Active' boolean to $all_plugins array. | |
foreach ( $all_plugins as $key => $value ) { | |
$is_active = ( in_array( $key, $active_plugins ) ) ? true : false; | |
$all_plugins[ $key ]['Active'] = $is_active; | |
} | |
return $all_plugins; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment