Wordpress get plugin directory

前端 未结 14 868
广开言路
广开言路 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:53

    You can define a variable into your main Php file. It should be at the root of your plugin folder. The file should be here : .../wp-content/plugins/plugin-folder/my-plugin.php

    You can add into the file this line.

        define( 'MYPLUGIN__PLUGIN_DIR_PATH', plugins_url('', __FILE__ ) );
    

    After you can use your new variable anywhere into your plugin.

        public function Test() 
        {   
                $folder2 = MYPLUGIN__PLUGIN_DIR_PATH . '/folder1/folder2/';
               // $folder2 = .../wp-content/plugins/plugin-folder/folder1/folder2/
        }
    

    I hope it will help someone.

提交回复
热议问题