我试图构建的PHP脚本有一些问题。
我需要访问位于Wordpress安装根文件夹中的a文件:
wordpress-root/live-config.php
问题是,我的脚本文件位于主题的根文件夹中,在定义常量时,我试图访问根文件夹。我的脚本文件位于:root-directory/wp-content/themes/theme-root/
如果我使用require ABSPATH . \'live-config.php\';
这不好,因为它会在当前文件所在的目录中查找(即。theme-root 目录而不是我的wordpress-root).
我只是想知道,在定义主题目录中的常量时,最好的方法是获取Wordpress安装的根文件夹?
在我的脚本中,我目前正在尝试:
/** Absolute path to the WordPress directory. */
if ( !defined(\'ABSPATH\') )
define(\'ABSPATH\', dirname(__FILE__) . \'/\');
/**
* Define type of server
*
* Depending on the type other stuff can be configured
* Note: Define them all, don\'t skip one if other is already defined
*/
define( \'WP_DEV_SERVER\', file_exists( ABSPATH . \'dev-config.php\' ) );
/**
* Load DB credentials
*/
if ( WP_DEV_SERVER )
require ABSPATH . \'dev-config.php\';
else
require ABSPATH . \'live-config.php\';
但显然在我的theme-root 实际上并没有指向wordpress-root 目录