get_plugin_page_hookname

Definition:
function get_plugin_page_hookname( $plugin_page, $parent_page ) {}

Parameters

  • $plugin_page
  • $parent_page

Source code

function get_plugin_page_hookname( $plugin_page, $parent_page ) {

	global $admin_page_hooks;



	$parent = get_admin_page_parent( $parent_page );



	$page_type = 'admin';

	if ( empty ( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[$plugin_page] ) ) {

		if ( isset( $admin_page_hooks[$plugin_page] ) )

			$page_type = 'toplevel';

		else

			if ( isset( $admin_page_hooks[$parent] ))

				$page_type = $admin_page_hooks[$parent];

	} else if ( isset( $admin_page_hooks[$parent] ) ) {

		$page_type = $admin_page_hooks[$parent];

	}



	$plugin_name = preg_replace( '!\.php!', '', $plugin_page );



	return $page_type . '_page_' . $plugin_name;

}

1564

get_plugin_page_hook

Definition:
function get_plugin_page_hook( $plugin_page, $parent_page ) {}

Parameters

  • $plugin_page
  • $parent_page

Source code

function get_plugin_page_hook( $plugin_page, $parent_page ) {

	$hook = get_plugin_page_hookname( $plugin_page, $parent_page );

	if ( has_action($hook) )

		return $hook;

	else

		return null;

}

1562

get_plugin_files

Definition:
function get_plugin_files($plugin) {}

Get a list of a plugin’s files.

Parameters

  • string $plugin: Plugin ID

Return values

returns:List of files relative to the plugin root.

Source code

function get_plugin_files($plugin) {

	$plugin_file = WP_PLUGIN_DIR . '/' . $plugin;

	$dir = dirname($plugin_file);

	$plugin_files = array($plugin);

	if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) {

		$plugins_dir = @ opendir( $dir );

		if ( $plugins_dir ) {

			while (($file = readdir( $plugins_dir ) ) !== false ) {

				if ( substr($file, 0, 1) == '.' )

					continue;

				if ( is_dir( $dir . '/' . $file ) ) {

					$plugins_subdir = @ opendir( $dir . '/' . $file );

					if ( $plugins_subdir ) {

						while (($subfile = readdir( $plugins_subdir ) ) !== false ) {

							if ( substr($subfile, 0, 1) == '.' )

								continue;

							$plugin_files[] = plugin_basename("$dir/$file/$subfile");

						}

						@closedir( $plugins_subdir );

					}

				} else {

					if ( plugin_basename("$dir/$file") != $plugin )

						$plugin_files[] = plugin_basename("$dir/$file");

				}

			}

			@closedir( $plugins_dir );

		}

	}



	return $plugin_files;

}

1560

get_plugin_data

Definition:
function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {}

Parse the plugin contents to retrieve plugin’s metadata.
The metadata of the plugin’s data searches for the following in the plugin’s header. All plugin data must be on its own line. For plugin description, it must not have any newlines or only parts of the description will be displayed and the same goes for the plugin data. The below is formatted for printing.

Parameters

  • string $plugin_file: Path to the plugin file
  • bool $markup: If the returned data should have HTML markup applied
  • bool $translate: If the returned data should be translated

Return values

returns:See above for description.

Source code

function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {



	$default_headers = array(

		'Name' => 'Plugin Name',

		'PluginURI' => 'Plugin URI',

		'Version' => 'Version',

		'Description' => 'Description',

		'Author' => 'Author',

		'AuthorURI' => 'Author URI',

		'TextDomain' => 'Text Domain',

		'DomainPath' => 'Domain Path',

		'Network' => 'Network',

		// Site Wide Only is deprecated in favor of Network.

		'_sitewide' => 'Site Wide Only',

	);



	$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );



	// Site Wide Only is the old header for Network

	if ( empty( $plugin_data['Network'] ) && ! empty( $plugin_data['_sitewide'] ) ) {

		_deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The <code>%1$s</code> plugin header is deprecated. Use <code>%2$s</code> instead.' ), 'Site Wide Only: true', 'Network: true' ) );

		$plugin_data['Network'] = $plugin_data['_sitewide'];

	}

	$plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) );

	unset( $plugin_data['_sitewide'] );



	//For backward compatibility by default Title is the same as Name.

	$plugin_data['Title'] = $plugin_data['Name'];



	if ( $markup || $translate )

		$plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );

	else

		$plugin_data['AuthorName'] = $plugin_data['Author'];



	return $plugin_data;

}

1558

get_plugins

Definition:
function get_plugins($plugin_folder = '') {}

Check the plugins directory and retrieve all plugin files with plugin data.
WordPress only supports plugin files in the base plugins directory (wp-content/plugins) and in one directory above the plugins directory (wp-content/plugins/my-plugin). The file it looks for has the plugin data and must be found in those two locations. It is recommended that do keep your plugin files in directories.

Parameters

  • string $plugin_folder: Optional. Relative path to single plugin folder.

Return values

returns:Key is the plugin file path and the value is an array of the plugin data.

Source code

function get_plugins($plugin_folder = '') {



	if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') )

		$cache_plugins = array();



	if ( isset($cache_plugins[ $plugin_folder ]) )

		return $cache_plugins[ $plugin_folder ];



	$wp_plugins = array ();

	$plugin_root = WP_PLUGIN_DIR;

	if ( !empty($plugin_folder) )

		$plugin_root .= $plugin_folder;



	// Files in wp-content/plugins directory

	$plugins_dir = @ opendir( $plugin_root);

	$plugin_files = array();

	if ( $plugins_dir ) {

		while (($file = readdir( $plugins_dir ) ) !== false ) {

			if ( substr($file, 0, 1) == '.' )

				continue;

			if ( is_dir( $plugin_root.'/'.$file ) ) {

				$plugins_subdir = @ opendir( $plugin_root.'/'.$file );

				if ( $plugins_subdir ) {

					while (($subfile = readdir( $plugins_subdir ) ) !== false ) {

						if ( substr($subfile, 0, 1) == '.' )

							continue;

						if ( substr($subfile, -4) == '.php' )

							$plugin_files[] = "$file/$subfile";

					}

					closedir( $plugins_subdir );

				}

			} else {

				if ( substr($file, -4) == '.php' )

					$plugin_files[] = $file;

			}

		}

		closedir( $plugins_dir );

	}



	if ( empty($plugin_files) )

		return $wp_plugins;



	foreach ( $plugin_files as $plugin_file ) {

		if ( !is_readable( "$plugin_root/$plugin_file" ) )

			continue;



		$plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.



		if ( empty ( $plugin_data['Name'] ) )

			continue;



		$wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;

	}



	uasort( $wp_plugins, '_sort_uname_callback' );



	$cache_plugins[ $plugin_folder ] = $wp_plugins;

	wp_cache_set('plugins', $cache_plugins, 'plugins');



	return $wp_plugins;

}

1556