WP_REST_Block_Directory_Controller::find_plugin_for_slug() WordPress Method

The WP_REST_Block_Directory_Controller::find_plugin_for_slug() method is used to find the WordPress plugin associated with a given slug. This is useful when you need to programmatically load a plugin or retrieve its information.

WP_REST_Block_Directory_Controller::find_plugin_for_slug( string $slug ) #

Finds an installed plugin for the given slug.


Parameters

$slug

(string)(Required)The WordPress.org directory slug for a plugin.


Top ↑

Return

(string) The plugin file found matching it.


Top ↑

Source

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

	protected function find_plugin_for_slug( $slug ) {
		require_once ABSPATH . 'wp-admin/includes/plugin.php';

		$plugin_files = get_plugins( '/' . $slug );

		if ( ! $plugin_files ) {
			return '';
		}

		$plugin_files = array_keys( $plugin_files );

		return $slug . '/' . reset( $plugin_files );
	}


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.