acf_plugin_dir_url()ACF 5.6.8

acf_plugin_dir_url

This function will calculate the url to a plugin folder. Different to the WP plugin_dir_url(), this function can calculate for urls outside of the plugins folder (theme include).

Хуков нет.

Возвращает

type. Description.

Использование

acf_plugin_dir_url( $file );
$file (обязательный)
-

Список изменений

С версии 5.6.8 Введена.

Код acf_plugin_dir_url() ACF 5.10.2

function acf_plugin_dir_url( $file ) {

	// vars
	$path = plugin_dir_path( $file );
	$path = wp_normalize_path( $path );

	// check plugins
	$check_path = wp_normalize_path( realpath( WP_PLUGIN_DIR ) );
	if ( strpos( $path, $check_path ) === 0 ) {
		return str_replace( $check_path, plugins_url(), $path );
	}

	// check wp-content
	$check_path = wp_normalize_path( realpath( WP_CONTENT_DIR ) );
	if ( strpos( $path, $check_path ) === 0 ) {
		return str_replace( $check_path, content_url(), $path );
	}

	// check root
	$check_path = wp_normalize_path( realpath( ABSPATH ) );
	if ( strpos( $path, $check_path ) === 0 ) {
		return str_replace( $check_path, site_url( '/' ), $path );
	}

	// return
	return plugin_dir_url( $file );

}