Advertisements

plugins_url

Definition:
function plugins_url($path = '', $plugin = '') {}

Retrieve the url to the plugins directory or to a specific file within that directory.
You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.

Parameters

  • string $path: Optional. Path relative to the plugins url.
  • string $plugin: Optional. The plugin file that you want to be relative to – i.e. pass in __FILE__

Return values

returns:Plugins url link with optional path appended.

Defined filters

  • plugins_url
    apply_filters('plugins_url', $url, $path, $plugin)

Source code

function plugins_url($path = '', $plugin = '') {



	$mu_plugin_dir = WPMU_PLUGIN_DIR;

	foreach ( array('path', 'plugin', 'mu_plugin_dir') as $var ) {

		$$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs

		$$var = preg_replace('|/+|', '/', $$var);

	}



	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )

		$url = WPMU_PLUGIN_URL;

	else

		$url = WP_PLUGIN_URL;



	if ( 0 === strpos($url, 'http') && is_ssl() )

		$url = str_replace( 'http://', 'https://', $url );



	if ( !empty($plugin) && is_string($plugin) ) {

		$folder = dirname(plugin_basename($plugin));

		if ( '.' != $folder )

			$url .= '/' . ltrim($folder, '/');

	}



	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )

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



	return apply_filters('plugins_url', $url, $path, $plugin);

}

2515

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: