Wordpress get plugin directory

前端 未结 14 980
广开言路
广开言路 2021-01-31 02:09

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

Example is

path/wp-contents/plugins/myplugin

I have tr

14条回答
  •  自闭症患者
    2021-01-31 02:38

    Kinda late to this party, but just in case some else stumbles upon this.

    plugin_dir_path(__FILE__) will always return the current path (where the file calling it is located).
    If you want the root, use the code below:

    plugin_dir_path( dirname( __FILE__ ) )
    

    You can then define a constant:

    define( 'YOUR_PLUGIN_DIR', plugin_dir_path( dirname( __FILE__ ) ) );
    require_once YOUR_PLUGIN_PATH . 'includes/admin-page.php'
    require_once YOUR_PLUGIN_PATH . 'admin/classes.php'
    

提交回复
热议问题