WP_REST_Plugins_Controller::get_plugin_data() WordPress Method

The WP_REST_Plugins_Controller::get_plugin_data() method is used to retrieve the data for a plugin. This data includes the plugin name, plugin slug, and plugin version.

WP_REST_Plugins_Controller::get_plugin_data( string $plugin ) #

Gets the plugin header data for a plugin.


Parameters

$plugin

(string)(Required)The plugin file to get data for.


Top ↑

Return

(array|WP_Error) The plugin data, or a WP_Error if the plugin is not installed.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.