数据库中的我的网站URL显示sitea.com
. 是否可以通过functions.php
进入siteb.com
, 但仍保持sitea.com
在数据库中?
我目前的情况是,我有三个在本地工作的开发人员,我们希望使用一个数据库。我们都连接到一个远程数据库,然而,来自本地开发环境和远程数据库的URL是不同的,这会导致链接中断。
有没有办法改变siteurl
在里面functions.php
而在数据库中仍然有相同的URL?
提前谢谢。
数据库中的我的网站URL显示sitea.com
. 是否可以通过functions.php
进入siteb.com
, 但仍保持sitea.com
在数据库中?
我目前的情况是,我有三个在本地工作的开发人员,我们希望使用一个数据库。我们都连接到一个远程数据库,然而,来自本地开发环境和远程数据库的URL是不同的,这会导致链接中断。
有没有办法改变siteurl
在里面functions.php
而在数据库中仍然有相同的URL?
提前谢谢。
而不是修改函数。php您可以修改wp配置。php,您可以使用以下内容:
define(\'WP_HOME\',\'http://example.com\');
define(\'WP_SITEURL\',\'http://example.com\');
来源:https://codex.wordpress.org/Changing_The_Site_URL#Edit_wp-config.php这根本不应该由您的主题来处理,而是由您的本地wp配置来处理。php文件。通过包装在条件中,可以有条件地加载本地和唯一的wp配置定义file_exists
. 以下是Mark Jaquith的一个例子:
if ( file_exists( dirname( __FILE__ ) . \'/local-config.php\' ) ) {
include( dirname( __FILE__ ) . \'/local-config.php\' );
define( \'WP_LOCAL_DEV\', true ); // We\'ll talk about this later
} else {
define( \'DB_NAME\', \'production_db\' );
define( \'DB_USER\', \'production_user\' );
define( \'DB_PASSWORD\', \'production_password\' );
define( \'DB_HOST\', \'production_db_host\' );
}
有关更多详细信息,请参见此处:https://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/这个theme_root_uri
筛选器将允许返回的URLget_stylesheet_directory_uri()
和get_template_directory_uri()
要即时更改:
/**
* Filters the URI for themes directory.
*
* @since 1.5.0
*
* @param string $theme_root_uri The URI for themes directory.
* @param string $siteurl WordPress web address which is set in General Options.
* @param string $stylesheet_or_template Stylesheet or template name of the theme.
*/
function wpse_theme_root_uri( $theme_root_uri, $siteurl, $stylesheet_or_template ) {
// $siteurl will be http://sitea.com via get_option( \'siteurl\' )
return str_replace( $siteurl, \'http://siteb.com\', $theme_root_uri );
}
add_filter( \'theme_root_uri\', \'wpse_theme_root_uri\', 10, 3 );
Theplugins_url
筛选器将允许返回的URLplugin_dir_url()
以类似方式更改:/**
* Filters the URL to the plugins directory.
*
* @since 2.8.0
*
* @param string $url The complete URL to the plugins directory including scheme and path.
* @param string $path Path relative to the URL to the plugins directory. Blank string
* if no path is specified.
* @param string $plugin The plugin file path to be relative to. Blank string if no plugin
* is specified.
*/
function wpse_plugins_url( $url, $path, $plugin ) {
return str_replace( get_option( \'siteurl\' ), \'http://siteb.com\', $url );
}
add_filter( \'plugins_url\', \'wpse_plugins_url\', 10, 3 );
正在查看/wp-includes/link-template.php
, 有很多其他函数返回URL,但可以使用与上面演示的相同方法对其进行过滤。选项的值siteurl
和home
也可以动态修改:
function wpse_pre_option_siteurl_and_home( $pre_option, $option ) {
return \'http://siteb.com\';
}
add_filter( \'pre_option_siteurl\', \'wpse_pre_option_siteurl_and_home\', 10, 2 );
add_filter( \'pre_option_home\', \'wpse_pre_option_siteurl_and_home\', 10, 2 );
有没有办法在WordPress管理区域小部件上显示数据库大小?我不希望它出现在页面的顶部或底部,我需要它出现在我正在创建的小部件中。。谢谢