WordPress: Running a Development Copy of WordPress:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第1行: 第1行:
==How To Run 2 Copies of WordPress From 1 Database==
==怎样在一个数据库中运行两个WordPress的副本==
==怎样在一个数据库中运行两个WordPress的副本==
This hack is broken for version 2.3.1 - but you can use the solution at the bottom of the page for [[WordPress:Running a Development Copy of WordPress#Solution_for_wordpress_2.5|version 2.5]]


这个方法是适用于 2.3.1版本 –但是你也可以在网页的底部为[[WordPress:Running a Development Copy of WordPress#Solution_for_wordpress_2.5| 2.5版本]]使用这个方法。
这个方法是适用于 2.3.1版本 –但是你也可以在网页的底部为[[WordPress:Running a Development Copy of WordPress#Solution_for_wordpress_2.5| 2.5版本]]使用这个方法。
=== Solution until version 2.3.1 ===


=== 直到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/
例如,我的在线站点位于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/
但是我正在发展的站点位于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副本的安装''不会更改你的数据库或者配置文件''!
下面是一个解决办法(关于WordPress2的-在2.0.2上测试了),让你轻松地运行一个本地和一个远程的WordPress副本的安装''不会更改你的数据库或者配置文件''!
''Please note'' that with this hack activated, Wordpress will IGNORE what you configure as your <tt>siteurl</tt> and <tt>home</tt> in your Options, and work them out for itself.


''请注意''当这个插件激活了,WordPress会忽视你在你的选项中的<tt>siteurl</tt>和<tt>home</tt>上的配置,因此你自己要解决这些配置。
''请注意''当这个插件激活了,WordPress会忽视你在你的选项中的<tt>siteurl</tt>和<tt>home</tt>上的配置,因此你自己要解决这些配置。


The hack goes in <tt>wp-includes/functions.php</tt>
hack 进入<tt>wp-includes/functions.php</tt>
 
插件进入<tt>wp-includes/functions.php</tt>
 
<div style="padding: 1em; line-height: 1.1em; border: 1px dashed #2f6fab; color: Black; ">
<tt>
/* Options functions */


<div style="padding: 1em; line-height: 1.1em; border: 1px dashed #2f6fab; color: Black; ">
<div style="padding: 1em; line-height: 1.1em; border: 1px dashed #2f6fab; color: Black; ">
<tt>
<tt>
/* 选项函数*/
/* 选项函数*/
function get_settings($setting) {
  global $wpdb;
  $value = wp_cache_get($setting, 'options');
</tt>
<div style="background-color: #f9f9f9;"><tt>
    /* 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 */
</tt></div>
<tt>
  if ( false === $value ) {
    if ( defined('WP_INSTALLING') )
      $wpdb->hide_errors();
</tt>
</div>


function get_settings($setting) {
function get_settings($setting) {
第129行: 第63行:




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


这个hack是以[http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server 我对于PHP在线文件的评论]为基础的。


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 <tt>wp-config.php</tt> if you want to use a remote database.
''请注意:如果你的服务器在安全的模式中运行PHP,这个hack并没有得到测试。如果你有什么问题,请将问题发表到 [[WordPress:Talk:Running_a_Development_Copy_of_WordPress|讨论网页上]]。''
 
在适当的位置有了这个插件之后,现在你可以为你的本地和远程WordPress安装使用同样的数据库和文件了。如果你想要使用一个远程数据库的话,可能你需要做的事就是将不同的设置放到<tt>wp-config.php</tt>中。
 
This hack is based on [http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server my comment on the PHP online documentation].
 
这个插件是以[http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server 我对于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 [[WordPress:Talk:Running_a_Development_Copy_of_WordPress|Discussion page]].''
 
''请注意:如果你的服务器在安全的模式中运行PHP,这个插件并没有得到测试。如果你有什么问题,请将问题发表到 [[WordPress:Talk:Running_a_Development_Copy_of_WordPress|讨论网页上]]。''
 
 
=== Solution for wordpress 2.5 ===


=== wordpress 2.5 的解决办法===
=== wordpress 2.5 的解决办法===
Edit the file wp-includes/options.php


编辑文件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。看起来像:
在函数get_option中,在global $wpdb一行的后面添加Ben的hack。看起来像:
<tt>
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!)
</tt>
{{Stub}}


<tt>
<tt>

2008年6月28日 (六) 16:30的最新版本

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

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

直到2.3.1版本的解决方法[ ]

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

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

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

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

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

hack 进入wp-includes/functions.php

/* 选项函数*/

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();


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

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

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

wordpress 2.5 的解决办法[ ]

编辑文件wp-includes/options.php

在函数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'])); // 这个网页目录的文件系统路径 (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.