plugin_dir_path()
plugin_dir_path( string $file )
获取传入的插件文件的文件系统目录路径(带斜杠)。
Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$file | (string) | 必需 | 插件的文件名(文件名)。 |
返回(Return)
(string)包含插件的目录的文件系统路径。
源码(Source)
/** * Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in. * * @since 2.8.0 * * @param string $file The filename of the plugin (__FILE__). * @return string the filesystem path of the directory that contains the plugin. */ function plugin_dir_path( $file ) { return trailingslashit( dirname( $file ) ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.8.0 | wp-includes/plugin.php:750 | 0 | 1 function |
笔记(Notes)
包括一个插件子文件夹中的所有PHP文件,避免添加不必要的全局文件,只需使用WP核心函数就可以确定在任何地方都可用的路径。
获取当前文件的目录:
定义路径常数
plugin_dir_path() 为WP2原创文章,链接:https://www.wp2.cn/functions/plugin_dir_path/