Make WordPress Core

Ticket #21627: 21627.3.patch

File 21627.3.patch, 4.1 KB (added by peterwilsoncc, 9 years ago)
  • src/wp-admin/customize.php

    From 0cdc2848b19b8ea48fc48ea2129817f3337ad6ee Mon Sep 17 00:00:00 2001
    From: Peter Wilson <peter@example.com>
    Date: Mon, 27 Apr 2015 14:31:28 +1000
    Subject: [PATCH] Filter for custom-background CSS selector
    
    ---
     src/wp-admin/customize.php              | 2 ++
     src/wp-includes/js/customize-preview.js | 7 ++++---
     src/wp-includes/post-template.php       | 2 +-
     src/wp-includes/theme.php               | 8 +++++++-
     4 files changed, 14 insertions(+), 5 deletions(-)
    
    diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php
    index c8bd6e3..8b870bb 100644
    a b do_action( 'customize_controls_print_scripts' ); 
    224224                'theme'    => array(
    225225                        'stylesheet' => $wp_customize->get_stylesheet(),
    226226                        'active'     => $wp_customize->is_theme_active(),
     227                        'bgElement'  => get_theme_support( 'custom-background', 'element-selector' ),
     228                        'bgClass'    => get_theme_support( 'custom-background', 'html-class' ),
    227229                ),
    228230                'url'      => array(
    229231                        'preview'       => esc_url_raw( $url ? $url : home_url( '/' ) ),
  • src/wp-includes/js/customize-preview.js

    diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js
    index e58c8d6..1a0c136 100644
    a b  
    131131                });
    132132
    133133                api.when.apply( api, bg ).done( function( color, image, position_x, repeat, attachment ) {
    134                         var body = $(document.body),
     134                        var element = $(window.parent._wpCustomizeSettings.theme.bgElement),
    135135                                head = $('head'),
    136136                                style = $('#custom-background-css'),
    137137                                update;
    138138
    139139                        update = function() {
    140140                                var css = '';
     141                                var selector = window.parent._wpCustomizeSettings.theme.bgElement + '.' + window.parent._wpCustomizeSettings.theme.bgClass;
    141142
    142143                                // The body will support custom backgrounds if either
    143144                                // the color or image are set.
    144145                                //
    145146                                // See get_body_class() in /wp-includes/post-template.php
    146                                 body.toggleClass( 'custom-background', !! ( color() || image() ) );
     147                                element.toggleClass( 'custom-background', !! ( color() || image() ) );
    147148
    148149                                if ( color() )
    149150                                        css += 'background-color: ' + color() + ';';
     
    157158
    158159                                // Refresh the stylesheet by removing and recreating it.
    159160                                style.remove();
    160                                 style = $('<style type="text/css" id="custom-background-css">body.custom-background { ' + css + ' }</style>').appendTo( head );
     161                                style = $('<style type="text/css" id="custom-background-css">' + selector + ' { ' + css + ' }</style>').appendTo( head );
    161162                        };
    162163
    163164                        $.each( arguments, function() {
  • src/wp-includes/post-template.php

    diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php
    index 2a6569f..a05583a 100644
    a b function get_body_class( $class = '' ) { 
    669669        }
    670670
    671671        if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
    672                 $classes[] = 'custom-background';
     672                $classes[] = get_theme_support( 'custom-background', 'html-class' );
    673673
    674674        $page = $wp_query->get( 'page' );
    675675
  • src/wp-includes/theme.php

    diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php
    index 1b372da..ee7de78 100644
    a b function _custom_background_cb() { 
    13561356
    13571357                $style .= $image . $repeat . $position . $attachment;
    13581358        }
     1359
     1360        $element    = get_theme_support( 'custom-background', 'element-selector' );
     1361        $html_class = get_theme_support( 'custom-background', 'html-class' );
     1362        $selector   = $element . '.' . $html_class;
    13591363?>
    13601364<style type="text/css" id="custom-background-css">
    1361 body.custom-background { <?php echo trim( $style ); ?> }
     1365<?php echo $selector; ?> { <?php echo trim( $style ); ?> }
    13621366</style>
    13631367<?php
    13641368}
    function add_theme_support( $feature ) { 
    16031607                                'wp-head-callback'       => '_custom_background_cb',
    16041608                                'admin-head-callback'    => '',
    16051609                                'admin-preview-callback' => '',
     1610                                'element-selector'       => 'body',
     1611                                'html-class'             => 'custom-background'
    16061612                        );
    16071613
    16081614                        $jit = isset( $args[0]['__jit'] );