我有2个单独的wp安装,它们共享同一个数据库。我的目标是为两个网站使用相同的帖子表和帖子元表。
我通过在第二个站点的config.php中添加代码:
来实现define( 'CUSTOM_POST_TABLE', 'site1_posts' );
define( 'CUSTOM_POST_META_TABLE', 'site1_postmeta' );
另外我在wp-includes / wp-db.php中添加了公共函数表,代码行1026-1076
if ( isset( $tables['posts'] ) && defined( 'CUSTOM_POST_TABLE' ) )
$tables['posts'] = CUSTOM_POST_TABLE;
if ( isset( $tables['postmeta'] ) && defined( 'CUSTOM_POST_META_TABLE' ) )
$tables['postmeta'] = CUSTOM_POST_META_TABLE;
现在两个网站共享相同的帖子,但问题是下次wordpress将被更新时,我将从wp-includes / wp-db.php中删除更改
所以我试图用第二个网站Override arguments of public function in Wordpress的function.php文件中的另一个函数覆盖公共函数,但网站崩溃并返回500错误。可能我做错了。
我尝试的代码是
add_filter( 'tables', 'my_tables', 11, 2 );
public function my_tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
if ( isset( $tables['posts'] ) && defined( 'CUSTOM_POST_TABLE' ) )
$tables['posts'] = CUSTOM_POST_TABLE;
if ( isset( $tables['postmeta'] ) && defined( 'CUSTOM_POST_META_TABLE' ) )
$tables['postmeta'] = CUSTOM_POST_META_TABLE;
}
return $tables;
}
wp-includes / wp-db.php中的原始代码是
public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
switch ( $scope ) {
case 'all' :
$tables = array_merge( $this->global_tables, $this->tables );
if ( is_multisite() )
$tables = array_merge( $tables, $this->ms_global_tables );
break;
case 'blog' :
$tables = $this->tables;
break;
case 'global' :
$tables = $this->global_tables;
if ( is_multisite() )
$tables = array_merge( $tables, $this->ms_global_tables );
break;
case 'ms_global' :
$tables = $this->ms_global_tables;
break;
case 'old' :
$tables = $this->old_tables;
break;
default :
return array();
}
if ( $prefix ) {
if ( ! $blog_id )
$blog_id = $this->blogid;
$blog_prefix = $this->get_blog_prefix( $blog_id );
$base_prefix = $this->base_prefix;
$global_tables = array_merge( $this->global_tables, $this->ms_global_tables );
foreach ( $tables as $k => $table ) {
if ( in_array( $table, $global_tables ) )
$tables[ $table ] = $base_prefix . $table;
else
$tables[ $table ] = $blog_prefix . $table;
unset( $tables[ $k ] );
}
if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) )
$tables['users'] = CUSTOM_USER_TABLE;
if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) )
$tables['usermeta'] = CUSTOM_USER_META_TABLE;
}
return $tables;
}
如何覆盖它,以便在下次更新后我不会失去我的更改?