Make WordPress Core

Ticket #38672: 38672.wp_update_custom_css_post.0.diff

File 38672.wp_update_custom_css_post.0.diff, 3.0 KB (added by westonruter, 8 years ago)
  • src/wp-includes/customize/class-wp-customize-custom-css-setting.php

    diff --git src/wp-includes/customize/class-wp-customize-custom-css-setting.php src/wp-includes/customize/class-wp-customize-custom-css-setting.php
    index eadd47c..f0c11b7 100644
    final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { 
    287287                $args = apply_filters( 'customize_update_custom_css_post_content_args', $args, $css, $setting );
    288288                $args = wp_array_slice_assoc( $args, array( 'post_content', 'post_content_filtered' ) );
    289289
    290                 $args = array_merge(
    291                         $args,
    292                         array(
    293                                 'post_title' => $this->stylesheet,
    294                                 'post_name' => sanitize_title( $this->stylesheet ),
    295                                 'post_type' => 'custom_css',
    296                                 'post_status' => 'publish',
    297                         )
    298                 );
     290                $args['stylesheet'] = $this->stylesheet;
     291                $r = wp_update_custom_css_post( $args );
    299292
    300                 // Update post if it already exists, otherwise create a new one.
    301                 $post = wp_get_custom_css_post( $this->stylesheet );
    302                 if ( $post ) {
    303                         $args['ID'] = $post->ID;
    304                         $post_id = wp_update_post( wp_slash( $args ) );
    305                 } else {
    306                         $post_id = wp_insert_post( wp_slash( $args ) );
    307                 }
    308                 if ( ! $post_id ) {
     293                if ( $r instanceof WP_Error ) {
    309294                        return false;
    310295                }
     296                $post_id = $r->ID;
    311297
    312298                // Cache post ID in theme mod for performance to avoid additional DB query.
    313299                if ( $this->manager->get_stylesheet() === $this->stylesheet ) {
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index eea50a5..69c5665 100644
    function wp_get_custom_css( $stylesheet = '' ) { 
    17081708}
    17091709
    17101710/**
     1711 * Update the `custom_css` post for a given theme.
     1712 *
     1713 * @since 4.7.0
     1714 * @access public
     1715 *
     1716 * @param array $args {
     1717 *     @type string $post_content          CSS.
     1718 *     @type string $post_content_filtered Pre-processed CSS. Normally empty string. Optional.
     1719 *     @type string $stylesheet            Stylesheet (child theme) to update.
     1720 * }
     1721 * @return WP_Post|WP_Error Post on success, error on failure.
     1722 */
     1723function wp_update_custom_css_post( $args ) {
     1724        $args = array_merge(
     1725                array(
     1726                        'post_content' => '',
     1727                        'post_content_filtered' => '',
     1728                        'stylesheet' => get_stylesheet(),
     1729                ),
     1730                $args
     1731        );
     1732
     1733        $args = array_merge(
     1734                $args,
     1735                array(
     1736                        'post_title' => $args['stylesheet'],
     1737                        'post_name' => sanitize_title( $args['stylesheet'] ),
     1738                        'post_type' => 'custom_css',
     1739                        'post_status' => 'publish',
     1740                )
     1741        );
     1742
     1743        // Update post if it already exists, otherwise create a new one.
     1744        $post = wp_get_custom_css_post( $args['stylesheet'] );
     1745        if ( $post ) {
     1746                $args['ID'] = $post->ID;
     1747                $r = wp_update_post( wp_slash( $args ), true );
     1748        } else {
     1749                $r = wp_insert_post( wp_slash( $args ), true );
     1750        }
     1751
     1752        if ( $r instanceof WP_Error ) {
     1753                return $r;
     1754        } else {
     1755                return get_post( $r );
     1756        }
     1757}
     1758
     1759/**
    17111760 * Add callback for custom TinyMCE editor stylesheets.
    17121761 *
    17131762 * The parameter $stylesheet is the name of the stylesheet, relative to