站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Running a Development Copy of WordPress
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
Fludlen
(
讨论
|
贡献
)
2008年6月25日 (三) 15:49的版本
(
差异
)
←上一版本
|
最后版本
(
差异
) |
下一版本→
(
差异
)
跳转至:
导航
、
搜索
警告:您正在编辑的是本页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==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 [[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版本]]使用这个方法。 === 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 <tt>siteurl</tt> and <tt>home</tt> in your Options, and work them out for itself. ''请注意''当这个插件激活了,WordPress会忽视你在你的选项中的<tt>siteurl</tt>和<tt>home</tt>上的配置,因此你自己要解决这些配置。 The hack goes in <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; "> <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) { 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'])); // 这个网页目录的文件系统路径(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 */ </tt></div> <tt> if ( false === $value ) { if ( defined('WP_INSTALLING') ) $wpdb->hide_errors(); </tt> </div> 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. 在适当的位置有了这个插件之后,现在你可以为你的本地和远程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 的解决办法=== 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。看起来像: <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> 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; // ...其它的函数继续运行 (不要复制这一行!) </tt> {{Stub}}
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)
本页使用的模板:
模板:Stub
(
编辑
)