Customize: Ensure `theme_mod`-cache of `custom_css` lookup of `-1` short-circuits a `WP_Query` from being made.
Props dlh, westonruter. See #35395. Merges [39688] to the 4.7 branch. Fixes #39259. Built from https://develop.svn.wordpress.org/branches/4.7@39694 git-svn-id: http://core.svn.wordpress.org/branches/4.7@39634 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d93d3febfe
commit
cc4a680493
|
@ -1653,18 +1653,17 @@ function wp_get_custom_css_post( $stylesheet = '' ) {
|
||||||
|
|
||||||
if ( $post_id > 0 && get_post( $post_id ) ) {
|
if ( $post_id > 0 && get_post( $post_id ) ) {
|
||||||
$post = get_post( $post_id );
|
$post = get_post( $post_id );
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// `-1` indicates no post exists; no query necessary.
|
||||||
|
if ( ! $post && -1 !== $post_id ) {
|
||||||
$query = new WP_Query( $custom_css_query_vars );
|
$query = new WP_Query( $custom_css_query_vars );
|
||||||
$post = $query->post;
|
$post = $query->post;
|
||||||
/*
|
/*
|
||||||
* Cache the lookup. See WP_Customize_Custom_CSS_Setting::update().
|
* Cache the lookup. See wp_update_custom_css_post().
|
||||||
* @todo This should get cleared if a custom_css post is added/removed.
|
* @todo This should get cleared if a custom_css post is added/removed.
|
||||||
*/
|
*/
|
||||||
if ( $post ) {
|
set_theme_mod( 'custom_css_post_id', $post ? $post->ID : -1 );
|
||||||
set_theme_mod( 'custom_css_post_id', $post->ID );
|
|
||||||
} elseif ( -1 !== $post_id ) {
|
|
||||||
set_theme_mod( 'custom_css_post_id', -1 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$query = new WP_Query( $custom_css_query_vars );
|
$query = new WP_Query( $custom_css_query_vars );
|
||||||
|
@ -1788,11 +1787,17 @@ function wp_update_custom_css_post( $css, $args = array() ) {
|
||||||
} else {
|
} else {
|
||||||
$r = wp_insert_post( wp_slash( $post_data ), true );
|
$r = wp_insert_post( wp_slash( $post_data ), true );
|
||||||
|
|
||||||
|
if ( ! is_wp_error( $r ) ) {
|
||||||
|
if ( get_stylesheet() === $args['stylesheet'] ) {
|
||||||
|
set_theme_mod( 'custom_css_post_id', $r );
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger creation of a revision. This should be removed once #30854 is resolved.
|
// Trigger creation of a revision. This should be removed once #30854 is resolved.
|
||||||
if ( ! is_wp_error( $r ) && 0 === count( wp_get_post_revisions( $r ) ) ) {
|
if ( 0 === count( wp_get_post_revisions( $r ) ) ) {
|
||||||
wp_save_post_revision( $r );
|
wp_save_post_revision( $r );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( is_wp_error( $r ) ) {
|
if ( is_wp_error( $r ) ) {
|
||||||
return $r;
|
return $r;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7.1-alpha-39693';
|
$wp_version = '4.7.1-alpha-39694';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue