Customize: Split out `custom_css` query logic from `wp_get_custom_css()` into a re-usable `wp_get_custom_css_post()` function to also be used when updating.
Props georgestephanis, westonruter. See #38672, #35395. Built from https://develop.svn.wordpress.org/trunk@39185 git-svn-id: http://core.svn.wordpress.org/trunk@39125 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8e3e901559
commit
ad80e08c17
|
@ -236,20 +236,9 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update post if it already exists, otherwise create a new one.
|
// Update post if it already exists, otherwise create a new one.
|
||||||
$post_id = null;
|
$post = wp_get_custom_css_post( $this->stylesheet );
|
||||||
$query = new WP_Query( array(
|
if ( $post ) {
|
||||||
'post_type' => 'custom_css',
|
$args['ID'] = $post->ID;
|
||||||
'post_status' => get_post_stati(),
|
|
||||||
'name' => sanitize_title( $this->stylesheet ),
|
|
||||||
'number' => 1,
|
|
||||||
'no_found_rows' => true,
|
|
||||||
'cache_results' => true,
|
|
||||||
'update_post_meta_cache' => false,
|
|
||||||
'update_term_meta_cache' => false,
|
|
||||||
'suppress_filters' => true,
|
|
||||||
) );
|
|
||||||
if ( ! empty( $query->post ) ) {
|
|
||||||
$args['ID'] = $query->post->ID;
|
|
||||||
$post_id = wp_update_post( wp_slash( $args ) );
|
$post_id = wp_update_post( wp_slash( $args ) );
|
||||||
} else {
|
} else {
|
||||||
$post_id = wp_insert_post( wp_slash( $args ) );
|
$post_id = wp_insert_post( wp_slash( $args ) );
|
||||||
|
|
|
@ -1574,32 +1574,26 @@ function wp_custom_css_cb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the saved Custom CSS content.
|
* Fetch the `custom_css` post for a given theme.
|
||||||
*
|
|
||||||
* Gets the content of a Custom CSS post that matches the
|
|
||||||
* current theme.
|
|
||||||
*
|
*
|
||||||
* @since 4.7.0
|
* @since 4.7.0
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
|
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
|
||||||
*
|
* @return WP_Post|null The custom_css post or null if none exists.
|
||||||
* @return string The Custom CSS Post content.
|
|
||||||
*/
|
*/
|
||||||
function wp_get_custom_css( $stylesheet = '' ) {
|
function wp_get_custom_css_post( $stylesheet = '' ) {
|
||||||
$css = '';
|
|
||||||
|
|
||||||
if ( empty( $stylesheet ) ) {
|
if ( empty( $stylesheet ) ) {
|
||||||
$stylesheet = get_stylesheet();
|
$stylesheet = get_stylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
$custom_css_query_vars = array(
|
$custom_css_query_vars = array(
|
||||||
'post_type' => 'custom_css',
|
'post_type' => 'custom_css',
|
||||||
'post_status' => get_post_stati(),
|
'post_status' => get_post_stati(),
|
||||||
'name' => sanitize_title( $stylesheet ),
|
'name' => sanitize_title( $stylesheet ),
|
||||||
'number' => 1,
|
'number' => 1,
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
'cache_results' => true,
|
'cache_results' => true,
|
||||||
'update_post_meta_cache' => false,
|
'update_post_meta_cache' => false,
|
||||||
'update_term_meta_cache' => false,
|
'update_term_meta_cache' => false,
|
||||||
);
|
);
|
||||||
|
@ -1607,10 +1601,9 @@ function wp_get_custom_css( $stylesheet = '' ) {
|
||||||
$post = null;
|
$post = null;
|
||||||
if ( get_stylesheet() === $stylesheet ) {
|
if ( get_stylesheet() === $stylesheet ) {
|
||||||
$post_id = get_theme_mod( 'custom_css_post_id' );
|
$post_id = get_theme_mod( 'custom_css_post_id' );
|
||||||
if ( ! $post_id ) {
|
if ( ! $post_id || ! get_post( $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_Customize_Custom_CSS_Setting::update().
|
||||||
* @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.
|
||||||
|
@ -1624,6 +1617,26 @@ function wp_get_custom_css( $stylesheet = '' ) {
|
||||||
$post = $query->post;
|
$post = $query->post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the saved Custom CSS content.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
|
||||||
|
* @return string The Custom CSS Post content.
|
||||||
|
*/
|
||||||
|
function wp_get_custom_css( $stylesheet = '' ) {
|
||||||
|
$css = '';
|
||||||
|
|
||||||
|
if ( empty( $stylesheet ) ) {
|
||||||
|
$stylesheet = get_stylesheet();
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = wp_get_custom_css_post( $stylesheet );
|
||||||
if ( $post ) {
|
if ( $post ) {
|
||||||
$css = $post->post_content;
|
$css = $post->post_content;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta2-39184';
|
$wp_version = '4.7-beta2-39185';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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