检查mu-plugins目录并使用任何插件数据检索所有mu-plugin文件。

原型

get_mu_plugins()

描述

WordPress只包含基本mu-plugins目录中的mu-plugin文件(wp-content / mu-plugins)。

返回值

(array)  Key是mu-plugin文件路径,值是mu-plugin数据的数组。

源文件

路径:wp-admin/includes/plugin.php

<?php
...
function get_mu_plugins() {
	$wp_plugins = array();
	// Files in wp-content/mu-plugins directory
	$plugin_files = array();
	if ( ! is_dir( WPMU_PLUGIN_DIR ) )
		return $wp_plugins;
	if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) {
		while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
			if ( substr( $file, -4 ) == '.php' )
				$plugin_files[] = $file;
		}
	} else {
		return $wp_plugins;
	}
	@closedir( $plugins_dir );
	if ( empty($plugin_files) )
		return $wp_plugins;
	foreach ( $plugin_files as $plugin_file ) {
		if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )
			continue;
		$plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
		if ( empty ( $plugin_data['Name'] ) )
			$plugin_data['Name'] = $plugin_file;
		$wp_plugins[ $plugin_file ] = $plugin_data;
	}
	if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
		unset( $wp_plugins['index.php'] );
	uasort( $wp_plugins, '_sort_uname_callback' );
	return $wp_plugins;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_mu_plugins/