Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#8712 closed defect (bug) (invalid)

Previewing Themes

Reported by: shinsou's profile shinsou Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Themes Keywords:
Focuses: Cc:


Let's say you're using a theme which uses a function called "maybe_add_widgets()".
Let's say you have two versions of that theme with "maybe_add_widgets()"; version 1 and version 2.
Now, just for the sake of it, let's say that version 2 has a style.php which contains all of style.css' data but is a bit dynamic AND that the style.php is loaded as the main style sheet (and not style.css).
To add to it, the style.php also loads the wp-config.php just so that it can carry out variables saved in some sort of settings.

Now, if you were to activate version 1 and then try to preview version 2, the CSS of that file will return a "You cannot redeclare maybe_add_widgets in line blah blah blah". How do you stop that error?

Change History (2)

#1 @shinsou
15 years ago

Just to add to it, I know that this is something that is uncommon but as it can happen, there should be some sort of fix for it. I'm thinking that maybe you guys should do something along these lines:

When you preview a theme, make the database switch themes, but when the page is loaded, switch it back to the original one (lest the user wants to use the theme).

#2 @DD32
15 years ago

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

It would be appreciated if you'd use the Support forums for help requests, Trac is for reporting and tracking of bugs and current enhancements. Whilst i could Ignore it and just close this ticket, I'll close it and give an explanation of your problem:

Your issue, Is that while previewing a theme, the template, stylesheet and a nonce are passed as $_GET variables, This informs WordPress that it is a theme-preview attempt, and WordPress ignores the database options.

In the case of having a PHP stylesheet which dynamically generates CSS, You'll need to pass the same GET variables and nonce to your style.php script, Using a PHP script as a stylesheet is a bad move IMO, Its effectivly doubling your server load since it needs to load WordPress for every check of the CSS file too (Which allthough caching helps, most browsers will re-check quite often).

My suggestion: Dont include a external php stylesheet which loads WP; Include a normal style.css script that has the majority of styles, and output a <style>...</style> block in your themes header, That'll reduce the server load, increase loading times, and you wont have the theme preview issues.

Note: See TracTickets for help on using tickets.