Wordpress siteurl的问题导致无法登陆

是这样的:

Wordpress的wp_options表里有一个配置项:siteurl,用于配置外部访问的url基准地址。现在我本地部署,可以用3个地址来访问:127.0.0.1、localhost、192.168.0.100。

问题是,数据库里配置的是192.168.0.100的地址,当从浏览器里以127.0.0.1或者localhost访问时,就会强制重定向,并且始终无法登陆。

FUCK。

Mediawiki也有这个问题,不过mw好就好在这个配置项不是放在数据库里的,而且如果注释掉的话,就会禁用这个功能,直接使用客户端的请求url。

搜索了一下,发现了这个:https://wordpress.org/support/topic/disable-automatic-redirect-to-siteurl

说是只要把主题(难道是因为我默认启用了主题导致这个问题?)里的functions.php里加上一句:remove_action('template_redirect', 'redirect_canonical');

我试了一下,没用。代码里完全写死了。

FUCK。

这个问题暂时没办法解决。


顺便想修改一下cookie的失效时间,发现Wordpress里的数值写死了:wp-includes/users.php

			// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
			// If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
			$logged_in_cookie    = wp_parse_auth_cookie( '', 'logged_in' );
			/** This filter is documented in wp-includes/pluggable.php */
			$default_cookie_life = apply_filters( 'auth_cookie_expiration', (<strong><span style="color:#ff0000;"> 2 * DAY_IN_SECONDS </span></strong>), $ID, false );
			$remember            = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life );


把这里的2改成2000,看看有没有效果。但是我估计如果下次重新启动XAMPP的话,估计还是需要重新登陆。


这个问题目前看来,应该是修改link_template.php里的这个函数:

/**
 * Retrieve the site url for a given site.
 *
 * Returns the 'site_url' option with the appropriate protocol, 'https' if
 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
 * overridden.
 *
 * @since 3.0.0
 *
 * @param int $blog_id (optional) Blog ID. Defaults to current blog.
 * @param string $path Optional. Path relative to the site url.
 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
 * @return string Site url link with optional path appended.
*/
function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
	if ( empty( $blog_id ) || !is_multisite() ) {
		$url = get_option( 'siteurl' );
	} else {
		switch_to_blog( $blog_id );
		$url = get_option( 'siteurl' );
		restore_current_blog();
	}

	$url = set_url_scheme( $url, $scheme );

	if ( $path && is_string( $path ) )
		$url .= '/' . ltrim( $path, '/' );

	/**
	 * Filter the site URL.
	 *
	 * @since 2.7.0
	 *
	 * @param string      $url     The complete site URL including scheme and path.
	 * @param string      $path    Path relative to the site URL. Blank string if no path is specified.
	 * @param string|null $scheme  Scheme to give the site URL context. Accepts 'http', 'https', 'login',
	 *                             'login_post', 'admin', 'relative' or null.
	 * @param int|null    $blog_id Blog ID, or null for the current blog.
	 */
	return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
}
这里get_option查询数据库获得siteurl的配置,我如何修改这个逻辑,改为直接从客户端的请求url里面提取呢??

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值