get_mu_plugins

函数
get_mu_plugins ( No parameters )
返回值
  • (array[]) Array of arrays of mu-plugin data, keyed by plugin file name. See get_plugin_data().
定义位置
相关方法
wp_get_mu_pluginsget_pluginsget_plugin_filesdelete_pluginsget_links
引入
3.0.0
弃用
-

get_mu_plugins函数用于检索WordPress安装中的活动必须使用(mu)插件数组: 此函数可用于检索有关当前正在使用的MU插件的信息。

检查mu-plugins目录,检索所有带有任何插件数据的mu-plugin文件。

WordPress只包括基础mu-plugins目录(wp-content/mu-plugins)中的mu-plugins文件。

function get_mu_plugins() {
	$wp_plugins   = array();
	$plugin_files = array();

	if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
		return $wp_plugins;
	}

	// Files in wp-content/mu-plugins directory.
	$plugins_dir = @opendir( WPMU_PLUGIN_DIR );
	if ( $plugins_dir ) {
		while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
			if ( '.php' === substr( $file, -4 ) ) {
				$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;
		}

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

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

常见问题

FAQs
查看更多 >