WordPress at a glance

plugins_url() WP 1.0

Retrieves a URL within the plugins or mu-plugins directory.

Defaults to the plugins directory URL if no arguments are supplied.

Is the basis for: plugin_dir_url()
✈ 1 time = 0.000034s = very fast | 50000 times = 0.71s = very fast

No Hooks.

Return

String. Plugins URL link with optional paths appended.

Usage

plugins_url( $path, $plugin );
$path(string)
Extra path appended to the end of the URL, including the relative directory if $plugin is supplied.
Default: ''
$plugin(string)
A full path to a file inside a plugin or mu-plugin. The URL will be relative to its directory. Typically this is done by passing __FILE__ as the argument.
Default: ''

Code of plugins_url: wp-includes/link-template.php VER 5.0.1

<?php
function plugins_url( $path = '', $plugin = '' ) {

	$path = wp_normalize_path( $path );
	$plugin = wp_normalize_path( $plugin );
	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
		$url = WPMU_PLUGIN_URL;
	else
		$url = WP_PLUGIN_URL;


	$url = set_url_scheme( $url );

	if ( !empty($plugin) && is_string($plugin) ) {
		$folder = dirname(plugin_basename($plugin));
		if ( '.' != $folder )
			$url .= '/' . ltrim($folder, '/');
	}

	if ( $path && is_string( $path ) )
		$url .= '/' . ltrim($path, '/');

	/**
	 * Filters the URL to the plugins directory.
	 *
	 * @since 2.8.0
	 *
	 * @param string $url    The complete URL to the plugins directory including scheme and path.
	 * @param string $path   Path relative to the URL to the plugins directory. Blank string
	 *                       if no path is specified.
	 * @param string $plugin The plugin file path to be relative to. Blank string if no plugin
	 *                       is specified.
	 */
	return apply_filters( 'plugins_url', $url, $path, $plugin );
}

Related Functions

From tag: Link (URL)

More from category: Plugins, Hooks

No comments
    Hello, !     Log In . Register