WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/09/2016 08:42:22 PM (3 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r39181 r39185  
    15751575
    15761576/**
    1577  * Fetch the saved Custom CSS content.
    1578  *
    1579  * Gets the content of a Custom CSS post that matches the
    1580  * current theme.
     1577 * Fetch the `custom_css` post for a given theme.
    15811578 *
    15821579 * @since 4.7.0
     
    15841581 *
    15851582 * @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
    1586  *
    1587  * @return string The Custom CSS Post content.
    1588  */
    1589 function wp_get_custom_css( $stylesheet = '' ) {
    1590     $css = '';
    1591 
     1583 * @return WP_Post|null The custom_css post or null if none exists.
     1584 */
     1585function wp_get_custom_css_post( $stylesheet = '' ) {
    15921586    if ( empty( $stylesheet ) ) {
    15931587        $stylesheet = get_stylesheet();
     
    15951589
    15961590    $custom_css_query_vars = array(
    1597         'post_type' => 'custom_css',
    1598         'post_status' => get_post_stati(),
    1599         'name' => sanitize_title( $stylesheet ),
    1600         'number' => 1,
    1601         'no_found_rows' => true,
    1602         'cache_results' => true,
     1591        'post_type'              => 'custom_css',
     1592        'post_status'            => get_post_stati(),
     1593        'name'                   => sanitize_title( $stylesheet ),
     1594        'number'                 => 1,
     1595        'no_found_rows'          => true,
     1596        'cache_results'          => true,
    16031597        'update_post_meta_cache' => false,
    16041598        'update_term_meta_cache' => false,
     
    16081602    if ( get_stylesheet() === $stylesheet ) {
    16091603        $post_id = get_theme_mod( 'custom_css_post_id' );
    1610         if ( ! $post_id ) {
     1604        if ( ! $post_id || ! get_post( $post_id ) ) {
    16111605            $query = new WP_Query( $custom_css_query_vars );
    16121606            $post = $query->post;
    1613 
    16141607            /*
    16151608             * Cache the lookup. See WP_Customize_Custom_CSS_Setting::update().
     
    16251618    }
    16261619
     1620    return $post;
     1621}
     1622
     1623/**
     1624 * Fetch the saved Custom CSS content.
     1625 *
     1626 * @since 4.7.0
     1627 * @access public
     1628 *
     1629 * @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
     1630 * @return string The Custom CSS Post content.
     1631 */
     1632function wp_get_custom_css( $stylesheet = '' ) {
     1633    $css = '';
     1634
     1635    if ( empty( $stylesheet ) ) {
     1636        $stylesheet = get_stylesheet();
     1637    }
     1638
     1639    $post = wp_get_custom_css_post( $stylesheet );
    16271640    if ( $post ) {
    16281641        $css = $post->post_content;
Note: See TracChangeset for help on using the changeset viewer.