本文介绍了Wordpress 获取插件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

是否有任何函数可以返回我的插件在 WordPress 中的完整路径?

Is there any function that would return the full path of my plugin in WordPress?

例子是

path/wp-contents/plugins/myplugin

我尝试过 plugin_dir_path(__FILE__) 但返回当前目录.

I have tried plugin_dir_path(__FILE__) but returns the current dir.

推荐答案

是的,根据 plugin_dir_path 它会给你当前的插件文件路径.但是,根据您在此处询问的内容,不幸的是,您可以执行以下操作,但没有直接的方法,

Yeah as per description of plugin_dir_path it will give you current plugin file path. But as per what you asking here you can do something like below unfortunately no direct way,

$plugin_dir = ABSPATH . 'wp-content/plugins/plugin-folder/';

18-09-2021

最佳实践是使用最新版本的 WP_PLUGIN_DIR 如下:

The best practice is to use with latest version is WP_PLUGIN_DIR as follow:

$plugin_dir = WP_PLUGIN_DIR . '/plugin-folder';

这篇关于Wordpress 获取插件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:31
查看更多