wordpress的插件目次在wp-content/plugins/下,一个插件一个目次,装置插件时能够把解压的插件上传到这个目次下或许在wordpress背景装置插件。
插件途径相干函数:
plugins_url()
猎取当前插件的目次的 URI,比方一个插件位于/wp-content/plugins/myplugin下,该目次下放有插件的主文件名为myplugin.php,在myplugin.php中实行下面的代码,效果以下
echo plugins_url(); //输出:http://www.seo628.com/wp-content/plugins echo plugins_url('',__FILE__); //输出:http://www.seo628.com/wp-content/plugins/myplugin echo plugins_url('js/myscript.js',__FILE__); //输出:http://www.seo628.com/wp-content/plugins/myplugin/js/myscript.js
plugin_dir_url()
返回当前插件的目次 URI,比方
echo plugin_dir_url(__FILE__ ); //输出:http://www.seo628.com/wp-content/plugins/myplugin/
注重末端有反斜杠。
plugin_dir_path()
返回当前插件目次的服务器绝对途径,比方
echo plugin_dir_path(__FILE__ ); //输出:/home/user/public_html/wp-content/plugins/myplugin/
能够用来援用文件,比方
<?php define('MYPLUGINNAME_PATH', plugin_dir_path(__FILE__) ); require MYPLUGINNAME_PATH . 'includes/class-metabox.php'; require MYPLUGINNAME_PATH . 'includes/class-widget.php'; ?>
plugin_basename()
返回挪用该函数的插件文件名称(包括插件途径)
比方在插件myplugin下的myplugin.php文件中挪用该函数,效果以下
echo plugin_basename(__FILE__); //输出:myplugin/myplugin.php
如果在myplugin/include/test.php文件中挪用(test.php经由过程include援用到myplugin.php中),效果以下
echo plugin_basename(__FILE__); //输出:myplugin/include/test.php
Url 途径相干常量
WordPress 中另有一组用define定义的常量代表途径。
WP_CONTENT_DIR
wp-content 目次的服务器绝对途径,比方
/home/user/public_html/wp-content
WP_CONTENT_URL
wp-content 目次的 URI 地点,比方
http://www.seo628.com/wp-content
WP_PLUGIN_DIR
插件目次的服务器绝对途径,比方
/home/user/public_html/wp-content/plugins
WP_PLUGIN_URL
插件目次的 URI 地点,比方
http://www.seo628.com/wp-content/plugins
更多wordpress相干技术文章,请接见wordpress教程栏目举行进修!
以上就是wordpress插件文件目次在哪的细致内容,更多请关注ki4网别的相干文章!