[wp-trac] [WordPress Trac] #54443: Database Error Breaks "custom_css_post_id" Theme Mod
WordPress Trac
noreply at wordpress.org
Mon Nov 15 11:41:06 UTC 2021
#54443: Database Error Breaks "custom_css_post_id" Theme Mod
---------------------------------+-----------------------------
Reporter: domainsupport | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: trunk
Severity: normal | Keywords:
Focuses: css, administration |
---------------------------------+-----------------------------
We have now seen this issue on a couple of WordPress installations and it
is rare but it happens.
When MySQL falls over during a page load (for RAM issues or whatever) the
request on line 1863 of **/wp-includes/theme.php** ...
{{{#!php
<?php
$post_id = get_theme_mod( 'custom_css_post_id' );
}}}
... fails or it might be line 1866 ...
{{{#!php
<?php
$post = get_post( $post_id );
}}}
... that fails.
Either way, when line 1877 is executed and the database has by then
recovered ...
{{{#!php
<?php
set_theme_mod( 'custom_css_post_id', $post ?
$post->ID : -1 );
}}}
... this results in the **custom_css_post_id** theme mod being set to -1
and all the Additional CSS is seemed to be wiped out from the Customizer.
At this point the content of the post with post_type set as custom_css in
the database has to be copied back into "Customizer - Additional CSS".
Here is an example of a PHP error around the time that this happened ...
please note that we have seen it happen on completely different themes and
most recently on the latest version of WordPress (yesterday) ...
{{{
[24-Feb-2021 20:46:45 UTC] WordPress database error Server shutdown in
progress for query SELECT * FROM wp_posts WHERE ID = 2213700 LIMIT 1 made
by require('wp-blog-header.php'), require_once('wp-includes/template-
loader.php'), include('/plugins/wp-property-feed/templates/archive-
wppf_property.php'), get_header, locate_template, load_template,
require_once('/themes/twentyseventeen/header.php'), wp_head,
do_action('wp_head'), WP_Hook->do_action, WP_Hook->apply_filters,
wp_custom_css_cb, wp_get_custom_css, wp_get_custom_css_post, get_post,
WP_Post::get_instance
}}}
To fix this issue from re-occuring I think that **set_theme_mod** on line
1877 is replaced with ...
{{{#!php
<?php
if ($post) {
set_theme_mod( 'custom_css_post_id',
$post->ID );
}
}}}
... so that the theme mod cannot be broken and CSS cannot be lost when the
database has a blip.
What do you think?
Oliver
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54443>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list