On this page
WP_REST_Plugins_Controller::get_plugin_data( string $plugin ): array|WP_Error
Gets the plugin header data for a plugin.
Parameters
$pluginstring Required-
The plugin file to get data for.
Return
array|WP_Error The plugin data, or a WP_Error if the plugin is not installed.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php. View all references
protected function get_plugin_data( $plugin ) {
$plugins = get_plugins();
if ( ! isset( $plugins[ $plugin ] ) ) {
return new WP_Error( 'rest_plugin_not_found', __( 'Plugin not found.' ), array( 'status' => 404 ) );
}
$data = $plugins[ $plugin ];
$data['_file'] = $plugin;
return $data;
}
Related
Uses
| Uses | Description |
|---|---|
| get_plugins() wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Plugins_Controller::get_item() wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php | Retrieves one plugin from the site. |
| WP_REST_Plugins_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php | Updates one plugin. |
| WP_REST_Plugins_Controller::delete_item() wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php | Deletes one plugin from the site. |
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/get_plugin_data