Make WordPress Core


Ignore:
Timestamp:
10/19/2016 06:14:21 PM (8 years ago)
Author:
westonruter
Message:

Customize: Introduce custom CSS for extending theme styles.

  • Custom CSS is associated with a given theme and is displayed in an inline style element at the wp_head hook after the wp_print_styles is called so that it overrides any enqueued stylesheets.
  • A wp_get_custom_css() function is used for accessing the CSS associated with the current theme (or another theme) and a wp_get_custom_css filter for manipulating it.
  • CSS is managed in customizer via a new "Additional CSS" section with a single textarea control.
  • WP_Customize_Section::$description_hidden is introduced for hiding extended descriptions in customizer sections behind a help toggle as done with panels.
  • CSS is stored in a custom_css post type with the theme (stylesheet) slug as the post_name.
  • WP_Customize_Custom_CSS_Setting is introduced to handle validation of CSS, previewing, and persisting the CSS to the custom_css post type.
  • The custom_css setting is tied to a new unfiltered_css capability which maps to unfiltered_html by default.
  • Escaping the message in the notification template is removed to allow markup (code tags) to be rendered.

See https://make.wordpress.org/core/2016/10/11/feature-proposal-better-theme-customizations-via-custom-css-with-live-previews/

Props johnregan3, celloexpressions, folletto, westonruter.
Fixes #35395.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r38813 r38829  
    301301        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-section.php' );
    302302
     303        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-custom-css-setting.php' );
    303304        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php' );
    304305        require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php' );
     
    24942495            <ul>
    24952496                <# _.each( data.notifications, function( notification ) { #>
    2496                     <li class="notice notice-{{ notification.type || 'info' }} {{ data.altNotice ? 'notice-alt' : '' }}" data-code="{{ notification.code }}" data-type="{{ notification.type }}">{{ notification.message || notification.code }}</li>
     2497                    <li class="notice notice-{{ notification.type || 'info' }} {{ data.altNotice ? 'notice-alt' : '' }}" data-code="{{ notification.code }}" data-type="{{ notification.type }}">{{{ notification.message || notification.code }}}</li>
    24972498                <# } ); #>
    24982499            </ul>
     
    32213222        ) ) );
    32223223
    3223 
    32243224        /* Custom Header */
    32253225
     
    33673367            'type' => 'dropdown-pages',
    33683368        ) );
     3369
     3370        /* Custom CSS */
     3371        $this->add_section( 'custom_css', array(
     3372            'title'              => __( 'Additional CSS' ),
     3373            'priority'           => 140,
     3374            'description_hidden' => true,
     3375            'description'        => sprintf( '%s<br /><a href="%s" class="external-link" target="_blank">%s<span class="screen-reader-text">%s</span></a>',
     3376                __( 'CSS allows you to customize the appearance and layout of your site with code. Separate CSS is saved for each of your themes.' ),
     3377                'https://codex.wordpress.org/Know_Your_Sources#CSS',
     3378                __( 'Learn more about CSS' ),
     3379                __( '(link opens in a new window)' )
     3380            ),
     3381        ) );
     3382
     3383        $custom_css_setting = new WP_Customize_Custom_CSS_Setting( $this, sprintf( 'custom_css[%s]', get_stylesheet() ), array(
     3384            'capability' => 'unfiltered_css',
     3385        ) );
     3386        $this->add_setting( $custom_css_setting );
     3387
     3388        $this->add_control( 'custom_css', array(
     3389            'type'     => 'textarea',
     3390            'section'  => 'custom_css',
     3391            'settings' => array( 'default' => $custom_css_setting->id ),
     3392        ) );
    33693393    }
    33703394
     
    33893413            }
    33903414        }
    3391 
    33923415        return 0 !== count( get_pages() );
    33933416    }
Note: See TracChangeset for help on using the changeset viewer.