wordpress 学习第三篇

我们来看看wp-load.php的内容。

<?php
/**
 * Bootstrap file for setting the ABSPATH constant
 * and loading the wp-config.php file. The wp-config.php
 * file will then load the wp-settings.php file, which
 * will then set up the WordPress environment.
 *
 * If the wp-config.php file is not found then an error
 * will be displayed asking the visitor to set up the
 * wp-config.php file.
 *
 * Will also search for wp-config.php in WordPress' parent
 * directory to allow the WordPress directory to remain
 * untouched.
 *
 * @package WordPress
 */

/** Define ABSPATH as this files directory */
define( 'ABSPATH', dirname(__FILE__) . '/' );

if ( defined('E_RECOVERABLE_ERROR') )
	error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
else
	error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);

if ( file_exists( ABSPATH . 'wp-config.php') ) {

	/** The config file resides in ABSPATH */
	require_once( ABSPATH . 'wp-config.php' );

} elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {

	/** The config file resides one level above ABSPATH but is not part of another install*/
	require_once( dirname(ABSPATH) . '/wp-config.php' );

} else {

	// A config file doesn't exist

	// Set a path for the link to the installer
	if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
	else $path = 'wp-admin/';

	// Die with an error message
	require_once( ABSPATH . '/wp-includes/classes.php' );
	require_once( ABSPATH . '/wp-includes/functions.php' );
	require_once( ABSPATH . '/wp-includes/plugin.php' );
	$text_direction = /*WP_I18N_TEXT_DIRECTION*/"ltr"/*/WP_I18N_TEXT_DIRECTION*/;
	wp_die(sprintf(/*WP_I18N_NO_CONFIG*/"There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%ssetup-config.php' class='button'>Create a Configuration File</a>"/*/WP_I18N_NO_CONFIG*/, $path), /*WP_I18N_ERROR_TITLE*/"WordPress › Error"/*/WP_I18N_ERROR_TITLE*/, array('text_direction' => $text_direction));

}

?>
首先就定义了ABSPATH,非常的有意义。所以在wordpress的主题以及插件中,如果你获得wordpress根目录的话,就可以用ABSPATH。这就是预定义的好处。不用每一次都用dirname(__FILE__),所以编写代码是非常有意思的事情,不要以为你能实现一个功能就可以了,关键要看可维护性以及科学性如何。是否最佳。

然后就是错误处理函数。编程中也要经常考虑到的事情。

下面仔细分析的话就知道是该载入wp-setting.php了。

如果没有发现wp-setting.php的话,会给出提示信息的。

file_exists( ABSPATH . 'wp-config.php') 和file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' )这里是什么意思呢?

为什么要比较这个ABSPATH和dirname(ABSPATH) ?这个是非常精细的思考。这里面是有一些wordpress的技巧在里面,也就是可以把wp-config.php这个文件放到index.php这个文件的上层目录中去。笔者把wp-config.php从目录中删除,然后放到父目录上面,程序照常工作。下面的代码就是如果没有找到wp-config.php,wp给出的一个提示。因为这是wp安装程序的一部分。。。。


dirname()返回文件或者文件夹的父目录。

<?php
    define( 'ABSPATH', dirname(__FILE__) . '/' );
    echo ABSPATH;
    echo "<br />";
    echo dirname(ABSPATH);

?>

简单的来测了一下。

结果如下:

G:\phpinstall\www\wp/
G:\phpinstall\www

斜杠在这可以不考虑,因为这是windows和linux的区别。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值