一、__FILE__与dirname(__FILE__)与basename(__FILE__)使用:
假设现在的目录及文件结构如下,我们所要测试的变量在wp_smtp_admin.php文件中:
wp-content\plugins\wp-smtp\wp-smtp.php
wp-content\plugins\wp-smtp\wp_smtp_admin.php
wp-content\plugins\wp-smtp\img\blq_32_32.jpg
测试结果如下:
echo __FILE__ . "<br />"; //输出 F:\xampp\htdocs\wordpress\wp-content\plugins\wp-smtp\wp_smtp_admin.php echo dirname(__FILE__) . "<br />"; //输出 F:\xampp\htdocs\wordpress\wp-content\plugins\wp-smtp echo basename(__FILE__) . "<br />"; //输出 wp_smtp_admin.php
二、测试wordpress自带的一些函数:
echo plugin_basename(__FILE__) . "<br />"; //输出 wp-smtp/wp_smtp_admin.php echo dirname(plugin_basename(__FILE__)) . "<br />"; //输出 wp-smtp echo plugin_dir_url(__FILE__) . "<br />"; //输出 echo plugin_dir_path(__FILE__) . "<br />"; //输出 F:\xampp\htdocs\wordpress\wp-content\plugins\wp-smtp/ echo plugins_url() . "<br />"; //输出 https://localhost/wordpress/wp-content/plugins echo plugins_url('',__FILE__) . "<br />"; //输出 https://localhost/wordpress/wp-content/plugins/wp-smtp echo plugins_url('/img/blq_32_32.jpg',__FILE__) . "<br />"; //输出 https://localhost/wordpress/wp-content/plugins/wp-smtp/img/blq_32_32.jpg