WordPress:Running a Development Copy of WordPress

来自站长百科
Fludlen讨论 | 贡献2008年6月25日 (三) 15:49的版本
跳转至: 导航、​ 搜索
可打印版不再被支持且可能有渲染错误。请更新您的浏览器书签并改用浏览器默认的打印功能。

How To Run 2 Copies of WordPress From 1 Database

怎样在一个数据库中运行两个WordPress的副本

This hack is broken for version 2.3.1 - but you can use the solution at the bottom of the page for version 2.5

这个方法是适用于 2.3.1版本 –但是你也可以在网页的底部为 2.5版本使用这个方法。

Solution until version 2.3.1

直到2.3.1版本的解决方法

A common problem faced by theme and plugin developers is the desire to test your plugins on live data, but without making messy changes to your live site during development.

主题和插件开发者通常面临的一个问题是,他们希望在变化的数据上测试你的插件,但是在测试时,希望不会将你的站点扰乱。

For example, I have my live site at http://www.ben-xo.com/v6/

例如,我的在线站点位于http://www.ben-xo.com/v6/

But I keep my development site at http://localhost/~xo/ben-xo.com/dev/v6/

但是我正在发展的站点位于http://localhost/~xo/ben-xo.com/dev/v6/

Here's a hack (for WordPress 2 - tested on 2.0.2) which will let you easily run both a local and a remote copy of your WordPress install without having to make any changes to your database or config files!

下面是一个解决办法(关于WordPress2的-在2.0.2上测试了),让你轻松地运行一个本地和一个远程的WordPress副本的安装不会更改你的数据库或者配置文件!

Please note that with this hack activated, Wordpress will IGNORE what you configure as your siteurl and home in your Options, and work them out for itself.

请注意当这个插件激活了,WordPress会忽视你在你的选项中的siteurlhome上的配置,因此你自己要解决这些配置。

The hack goes in wp-includes/functions.php

插件进入wp-includes/functions.php

/* Options functions */

/* 选项函数*/

function get_settings($setting) {

 global $wpdb;
 $value = wp_cache_get($setting, 'options');

   /* Ben XO's siteurl hack */
   if( 'siteurl' == $setting or 'home' == $setting ) {
   $_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); 
   // filesystem path of this page's directory (index.php or whatever)
   $_REAL_BASE_DIR = realpath(dirname(__FILE__) . 
     DIRECTORY_SEPARATOR . '..'); 
   // filesystem path of this file's parent directory 
   // (that wp-includes is within)
   $_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR)); 
   // just the subfolder part between <installation_path> and the page
   $INSTALLATION_PATH = $_MY_PATH_PART
     ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) )
     : dirname($_SERVER['SCRIPT_NAME'])
   ; 
   // we subtract the subfolder part from the end of <installation_path>, 
   // leaving us with just <installation_path> :)
   $value = 'http' . ($_SERVER['HTTPS'] ? 's' : null) .
            '://' . $_SERVER['HTTP_HOST'] . $INSTALLATION_PATH
   ;
 }
 /* end Ben XO's siteurl hack */

 if ( false === $value ) {
   if ( defined('WP_INSTALLING') )
     $wpdb->hide_errors();


function get_settings($setting) {

 global $wpdb;
 $value = wp_cache_get($setting, 'options');

   /* Ben XO's siteurl hack */
   if( 'siteurl' == $setting or 'home' == $setting ) {
   $_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); 
   // 这个网页目录的文件系统路径(index.php 或者其它的)
   $_REAL_BASE_DIR = realpath(dirname(__FILE__) . 
     DIRECTORY_SEPARATOR . '..'); 
   // 这个文件的母目录的文件系统路径    // (wp-includes在里面)
   $_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR)); 
   // <installation_path> 和网页之间的子文件夹部分
   $INSTALLATION_PATH = $_MY_PATH_PART
     ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) )
     : dirname($_SERVER['SCRIPT_NAME'])
   ; 
   // 我们在<installation_path>的结尾部分减去了子文件夹, 
   // 我们只有了<installation_path> :)
   $value = 'http' . ($_SERVER['HTTPS'] ? 's' : null) .
            '://' . $_SERVER['HTTP_HOST'] . $INSTALLATION_PATH
   ;
 }
 /* end Ben XO's siteurl hack */

 if ( false === $value ) {
   if ( defined('WP_INSTALLING') )
     $wpdb->hide_errors();



With this hack in place, you can now use exactly the same database and exactly the same files for both your local and remote WordPress install. Possibly the only thing you'd need to do is put different settings in wp-config.php if you want to use a remote database.

在适当的位置有了这个插件之后,现在你可以为你的本地和远程WordPress安装使用同样的数据库和文件了。如果你想要使用一个远程数据库的话,可能你需要做的事就是将不同的设置放到wp-config.php中。

This hack is based on my comment on the PHP online documentation.

这个插件是以我对于PHP在线文件的评论为基础的。

Please Note: this hack is untested if your server runs PHP in Safe Mode. If you have any problems, please post them on the Discussion page.

请注意:如果你的服务器在安全的模式中运行PHP,这个插件并没有得到测试。如果你有什么问题,请将问题发表到 讨论网页上


Solution for wordpress 2.5

wordpress 2.5 的解决办法

Edit the file wp-includes/options.php

编辑文件wp-includes/options.php

In the function get_option, add Ben's hack immediately after the line which says global $wpdb. It should look like the following:

在函数get_option中,在global $wpdb一行的后面添加Ben的hack。看起来像:

function get_option( $setting ) {

global $wpdb;

/* Ben XO's siteurl hack */

if( 'siteurl' == $setting or 'home' == $setting )

{

$_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // filesystem path of this page's directory (index.php or whatever)

$_REAL_BASE_DIR = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'); // filesystem path of this file's parent directory // (that wp-includes is within)

$_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR)); // just the subfolder part between <installation_path> and the page

$INSTALLATION_PATH = $_MY_PATH_PART ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) ) : dirname($_SERVER['SCRIPT_NAME']) ; // we subtract the subfolder part from the end of <installation_path>, // leaving us with just <installation_path> :)

$value = 'http' . ($_SERVER['HTTPS'] ? 's' : null) . '://' . $_SERVER['HTTP_HOST'] . $INSTALLATION_PATH ;

return $value;

} /* end Ben XO's siteurl hack */


// Allow plugins to short-circuit options. $pre = apply_filters( 'pre_option_' . $setting, false ); if ( false !== $pre ) return $pre;

// ... rest of the function continues (do not copy this line!)

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.



function get_option( $setting ) {

global $wpdb;

/* Ben XO's siteurl hack */

if( 'siteurl' == $setting or 'home' == $setting )

{

$_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // 这个网页目录的文件系统路径 (index.php 或者其它的)

$_REAL_BASE_DIR = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'); // 这个文件的母目录的文件系统路径 // (wp-includes 是在里面)

$_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR)); //在 <installation_path> 和网页之间的子文件夹部分

$INSTALLATION_PATH = $_MY_PATH_PART ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) ) : dirname($_SERVER['SCRIPT_NAME']) ; // 我们在<installation_path>的尾部减去了子文件夹部分, // 我们只剩下了 <installation_path> :)

$value = 'http' . ($_SERVER['HTTPS'] ? 's' : null) . '://' . $_SERVER['HTTP_HOST'] . $INSTALLATION_PATH ;

return $value;

} /* end Ben XO's siteurl hack */


// 允许插件缩短选项 $pre = apply_filters( 'pre_option_' . $setting, false ); if ( false !== $pre ) return $pre;

// ...其它的函数继续运行 (不要复制这一行!)

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.