Make WordPress Core


Ignore:
Timestamp:
02/15/2009 04:50:45 PM (16 years ago)
Author:
westi
Message:

Extend plugins_url to allow you to specify the plugin file you want to be relative to so slugs don't need to be hardcoded. Fixes #6341.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r10554 r10578  
    15051505
    15061506/**
    1507  * Retrieve the url to the plugins directory.
     1507 * Retrieve the url to the plugins directory or to a specific file within that directory.
     1508 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
    15081509 *
    15091510 * @package WordPress
     
    15111512 *
    15121513 * @param string $path Optional. Path relative to the plugins url.
     1514 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__
    15131515 * @return string Plugins url link with optional path appended.
    15141516*/
    1515 function plugins_url($path = '') {
     1517function plugins_url($path = '', $plugin = '') {
    15161518    $scheme = ( is_ssl() ? 'https' : 'http' );
    15171519    $url = WP_PLUGIN_URL;
     
    15211523    }
    15221524
     1525    if ( !empty($plugin) && is_string($plugin) )
     1526    {
     1527        $folder = dirname(plugin_basename($plugin));
     1528        if ('.' != $folder)
     1529            $url .= '/' . ltrim($folder, '/');
     1530    }
     1531   
    15231532    if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
    15241533        $url .= '/' . ltrim($path, '/');
Note: See TracChangeset for help on using the changeset viewer.