Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17789 closed defect (bug) (invalid)

WP_CONTENT_URL Defined before wp-config.php causes incorrect links when defining WP_SITEURL

Reported by: sethmatics's profile sethmatics Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

When attempting to use to defined constants to make wordpress more "cross domain friendly" for my development subdomains we found an issue.

define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME']);
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']);
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/wp-content');

However, the constant WP_CONTENT_URL is defined before loading the wp-config file so the last define fails. Similar to ticket #13941, I'm having an issue with how content_url() function is returning the WP_CONTENT_URL which I can't modify to match the rest of my constants.

*when testing, make sure that your WP_SITEURL is different then the one defined in the database, maybe by using a "www." prefix for example.

How do you get the "bug" to occur?

  1. Define the above in wp-config.php
  2. echo out get_stylesheet_directory() and note that it follows the database content instead of the content you intended to define.

Change History (5)

#1 @dd32
13 years ago

  • Keywords reporter-feedback added

the constant WP_CONTENT_URL is defined before loading the wp-config file so the last define fails.

Come again? The constant can't be defined before wp-config.php is loaded.. Since it needs the details from the database definitions within the wp-config.php file in order to determine them.

The only way it could be defined, would be if you're placing the defines after wp-config.php includes wp-settings.php.

Just tested by placing the code you've suggested into a wp-config.php for a site at http://localhost/, the output of get_stylesheet_directory_uri() is http://dd32-laptop/wp-content/themes/twentyeleven as expected.

#2 @sethmatics
13 years ago

If you used the above code on "localhost" then the expected output would be "http://localhost/wp-content/themes/twentyeleven". as the html header should have "host: localhost" as one of its parameters (unless I just don't know your configuration).

Maybe a better test would be to put use:

define('WP_CONTENT_URL', 'http://google.com/wp-content');

Obviously the stylesheet would fail to load if the constant loads up correctly. You can also test using

if(defined('WP_CONTENT_URL')) die('WP_CONTENT_URL is already defined');

Maybe I'm just missing something but I spent about 5 hours trying to get it to work today when I used the above if statement only to find out it was already defined... making it impossible to define again.

Last edited 13 years ago by sethmatics (previous) (diff)

#3 @dd32
13 years ago

If you used the above code on "localhost" then the expected output would be " http://localhost/wp-content/themes/twentyeleven". as the html header should have "host: localhost" as one of its parameters (unless I just don't know your configuration).

Sorry, I mean't, I used a site that was setup using http://localhost/, and instead, added your code and accessed it via http://dd32-laptop/ (ie. Localhost, but with a dd32-laptop as the host header)

I can verify, that WP_CONTENT_URL is NOT defined before wp-config.php is loaded, unless you've got it defined in either a php pre-include or inside WordPress's index.php, wp-blog-header.php, wp-settings or wp-load.php. The only constant which will be already defined is ABSPATH.

#4 @sethmatics
13 years ago

  • Resolution set to invalid
  • Status changed from new to closed

I'm sorry, this last statement explained what I needed. Noting now that I was trying to define the constant after the wp-settings.php file as it worked for the other two constants. Feeling rather silly after reading the code above my define functions that says:

/* That's all, stop editing! Happy blogging. */

#5 @dd32
13 years ago

  • Milestone Awaiting Review deleted

No problem; I perhaps should've asked that question to start with :)

Note: See TracTickets for help on using tickets.