Opened 4 years ago

Last modified 13 months ago

#9873 new defect (bug)

enforce a consistent home and siteurl www. pref

Reported by: Denis-de-Bernardy Owned by:
Priority: normal Milestone: Future Release
Component: Users Version: 2.8
Severity: normal Keywords: has-patch
Cc: mikeschinkel@…, andrew@…, ipstenu@…

Description

Seen on a few sites. home and siteurl with inconsistent www prefs prevents the admin user's cookie from getting picked up properly, upon logging in.

code I currently use to prevent the issue is this:

add_action('login_head', 'fix_www_pref');

function fix_www_pref() {
	$home_url = get_option('home');
	$site_url = get_option('siteurl');
		
	$home_www = strpos($home_url, '://www.') !== false;
	$site_www = strpos($site_url, '://www.') !== false;
		
	if ( $home_www != $site_www ) {
		if ( $home_www )
			$site_url = str_replace('://', '://www.', $site_url);
		else
			$site_url = str_replace('://www.', '://', $site_url);
		update_option('site_url', $site_url);
	}
} # fix_www_pref()

there's probably a better way and a better location for this.

Attachments (1)

options.php.diff (1.4 KB) - added by norcross 14 months ago.
catch $_POST values for urls and check / replace if needed

Download all attachments as: .zip

Change History (12)

  • Milestone changed from 2.8 to Future Release

punting pending patch

see also #10095 (closed issue), which highlights a side-effect

see also #10447 for more potential side effects

Related: #10970

Related: #11945

  • Cc mikeschinkel@… added

Closed #20430 as a duplicate.

Crops up on support forums once in a while.

catch $_POST values for urls and check / replace if needed

  • Cc andrew@… added
  • Keywords has-patch added
  • Type changed from enhancement to defect (bug)
  • Version changed from 2.8 to 3.4
  • Version changed from 3.4 to 2.8

Version number indicates when the bug was initially introduced/reported.

  • Cc ipstenu@… added
Note: See TracTickets for help on using tickets.