wp_register_plugin_realpath

函数
wp_register_plugin_realpath ( $file )
参数
  • (string) $file Known path to the file.
    Required:
返回值
  • (bool) Whether the path was able to be registered.
相关
  • wp_normalize_path()
定义位置
相关方法
wp_register_scriptwp_deregister_scriptwp_targeted_link_relwp_unregister_globalswp_register_tinymce_scripts
引入
3.9.0
弃用
-

wp_register_plugin_realpath: 这个函数是用来注册一个插件的目录作为该插件的真实路径。它接受两个参数:插件文件路径和目录路径。这在插件被符号链接或插件文件不在标准的WordPress插件目录中时很有用。

注册一个插件的真实路径。

这在plugin_basename()中被用来解决符号链接的路径。

function wp_register_plugin_realpath( $file ) {
	global $wp_plugin_paths;

	// Normalize, but store as static to avoid recalculation of a constant value.
	static $wp_plugin_path = null, $wpmu_plugin_path = null;

	if ( ! isset( $wp_plugin_path ) ) {
		$wp_plugin_path   = wp_normalize_path( WP_PLUGIN_DIR );
		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
	}

	$plugin_path     = wp_normalize_path( dirname( $file ) );
	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );

	if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
		return false;
	}

	if ( $plugin_path !== $plugin_realpath ) {
		$wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
	}

	return true;
}

常见问题

FAQs
查看更多 >