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
檢視更多 >