plugins_url()
最后更新于:2021-11-27 18:46:18
plugins_url( string$path=”, string$plugin=”)Retrieves a URL within the plugins or mu-plugins directory.
参数
- $path
-
(string) (Optional) Extra path appended to the end of the URL, including the relative directory if $plugin is supplied.
Default value: ”
- $plugin
-
(string) (Optional) 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 value: ”
响应
(string) Plugins URL link with optional paths appended.
源文件
文件: gc-includes/link-template.php
function plugins_url( $path = '', $plugin = '' ) {
$path = gc_normalize_path( $path );
$plugin = gc_normalize_path( $plugin );
$mu_plugin_dir = gc_normalize_path( GCMU_PLUGIN_DIR );
if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) {
$url = GCMU_PLUGIN_URL;
} else {
$url = GC_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 );
}