Make WordPress Core

Opened 6 months ago

Closed 5 months ago

#59861 closed defect (bug) (duplicate)

WordPress 6.4 – Initial theme activation works, page reload claims missing stylesheet

Reported by: rvervuurt's profile Rvervuurt Owned by:
Milestone: Priority: normal
Severity: major Version: 6.4
Component: General Keywords: reporter-feedback
Focuses: template Cc:

Description

Wordpress 6.4 breaks my theme setup.
Rolling back to 6.3 fixes this, but I would like to be able to update and run the latest versions. I have 50+ themes built on the same boiler plate, so if they all start updating, I have a big problem.

Case: When I activate the theme, WordPress tells me the theme is successfully activated:
https://i.imgur.com/7tGrDeu.png

This is also reflected in my database:
https://i.imgur.com/1sMwhW6.png

Visiting the page works, everything works.

UNTIL one visits the themes.php-page again:
https://i.imgur.com/m7d2Ss4.png

I suspect this is because my stylesheet-value in the database contains /templates, which is added with this function:
`
add_filter('stylesheet', function ($stylesheet) {

return dirname($stylesheet);

});

add_action('after_switch_theme', function () {

$stylesheet = get_option('stylesheet');
if (basename($stylesheet) !== 'templates') {

update_option('stylesheet', $stylesheet . '/templates');

}

});
`

I NEED the stylesheet-structure to be theme-name/templates, otherwise I just get a white page with no content whatsoever.
https://i.imgur.com/yKiehqx.png

So, I either need to find a fix for the page, so it works with wp-theme-ohd as the value for both the template and stylesheet, or WordPress needs to fix what they changed when shifting to 6.4, since it worked perfectly fine and problem free on 6.3.

Change History (10)

This ticket was mentioned in Slack in #core-performance by swissspidy. View the logs.


6 months ago

#2 @Rvervuurt
6 months ago

A possible solution is to add style.css (or a symlink to that file from the root-folder) in my /templates-folder, but that seems like a strange solution.

#3 @jorbin
6 months ago

I think this may be a duplicate of #59847. Can you test the patches being discussed on that ticket, please?

#4 @joemcgill
6 months ago

I've also just added a link to a helper plugin that should fix things if this is the same issue.

#5 @Rvervuurt
6 months ago

Adding that plugin changes one thing: WP Dashboard doesn't complain about the stylesheet missing, but if I revert to my original code and add that plugin, my page is totally blank again, same as in the last screenshot of my original post.

The other solutions in the thread @jorbin linked to, are beyond my technical skill and/or available time to try out.

For now, the only solution is making a symlink to style.css in my templates-folder, which is weird as it was unnecessary to do that with the exact same setup on WordPress 6.3

This ticket was mentioned in Slack in #core by jorbin. View the logs.


5 months ago

#7 @jorbin
5 months ago

Hi @Rvervuurt, WordPress 6.4.2 included a fix for #59847 which is similar to the issue you reported. Can you verify if this issue is still affecting you?

#8 @jorbin
5 months ago

  • Keywords reporter-feedback added

#9 @Rvervuurt
5 months ago

@jorbin I just tested locally, and it doesn't work on 6.4.2

Initially, the theme seems to be activated perfectly fine. A reload doesn't do anything, the theme is still activated.

When checking the frontpage, it's just white, but no errors in my log.
Reloading the frontpage breaks the theme and outputs "There Has Been a Critical Error on Your Website" and in the log, the theme seems to break because it can't find a custom function that's in our functions.php.

This is probably because it's looking for the functions.php-file in my /templates-folder, while it's in the root folder.

If I symlink my functions-file in my /templates, the page works sort-of, it just can't find my stylesheets, which are not in /templates/dist/styles, but in the root folder in dist/styles/.

I found out that moving all files from my templates folder into my root folder fixes the problem, and we are slowly doing this for all our clients right now.

Here's the custom stuff we do in the theme, which I remove when moving all files from templates to the root folder:
https://pastebin.com/fxsMQxRh

#10 @joemcgill
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @Rvervuurt. It seems to me that what you're describing is likely due to the same root cause I described in #60025.

Essentially, setting the stylesheet directory option in the DB and then filtering the get_stylesheet() function that returns that option from the DB was making use of a race condition where the STYLESHEETPATH environment variable used in locate_template() prior to 6.4.0 would get set to the DB option before the theme was initialized and the filter was added. This workaround could be used to load templates from a subdirectory of the theme, while making sure other theme files and stylesheets would be referenced from the root of the theme.

I'm going to close this as a duplicate of #60025 so we can keep discussions about a fix in one place. Feel free to follow and add details to the discussion on that ticket.

Note: See TracTickets for help on using tickets.