Make WordPress Core

Ticket #26386: 26386.3.diff

File 26386.3.diff, 4.9 KB (added by hennell, 9 years ago)

Add background size option to customizer & custom background options.

  • wp-admin/custom-background.php

    diff --git wp-admin/custom-background.php wp-admin/custom-background.php
    index dc19842..2ce3eee 100644
    class Custom_Background { 
    207207                        set_theme_mod('background_position_x', $position);
    208208                }
    209209
     210                if ( isset($_POST['background-size']) ) {
     211                        check_admin_referer('custom-background');
     212                        if ( in_array($_POST['background-size'], array('auto', 'cover', 'contain')) )
     213                                $size = $_POST['background-size'];
     214                        else
     215                                $size = 'auto';
     216                        set_theme_mod('background_size', $size);
     217                }
     218
    210219                if ( isset($_POST['background-attachment']) ) {
    211220                        check_admin_referer('custom-background');
    212221                        if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
    class Custom_Background { 
    265274                        // Background-image URL must be single quote, see below.
    266275                        $background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
    267276                                . ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';'
    268                                 . ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
     277                                . ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) . ';'
     278                                . ' background-size: ' . get_theme_mod('background_size', get_theme_support('custom-background', 'default-size')) ;
    269279                }
    270280        ?>
    271281        <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
    class Custom_Background { 
    361371</tr>
    362372
    363373<tr>
     374<th scope="row"><?php _e( 'Size' ); ?></th>
     375<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Size' ); ?></span></legend>
     376<label><input type="radio" name="background-size" value="auto"<?php checked( 'auto', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?> /> <?php _e('Auto'); ?></label>
     377        <label><input type="radio" name="background-size" value="cover"<?php checked( 'cover', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?> /> <?php _e('Cover'); ?></label>
     378        <label><input type="radio" name="background-size" value="contain"<?php checked( 'contain', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?> /> <?php _e('Contain'); ?></label>
     379</fieldset></td>
     380</tr>
     381
     382<tr>
    364383<th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th>
    365384<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
    366385<label>
  • wp-includes/class-wp-customize-manager.php

    diff --git wp-includes/class-wp-customize-manager.php wp-includes/class-wp-customize-manager.php
    index c3a8273..e57a99d 100644
    final class WP_Customize_Manager { 
    11011101                        ),
    11021102                ) );
    11031103
     1104                $this->add_setting( 'background_size', array(
     1105                        'default'        => get_theme_support( 'custom-background', 'default-size' ),
     1106                        'theme_supports' => 'custom-background',
     1107                ) );
     1108
     1109                $this->add_control( 'background_size', array(
     1110                        'label'      => __( 'Background Size' ),
     1111                        'section'    => 'background_image',
     1112                        'type'       => 'radio',
     1113                        'choices'    => array(
     1114                                'auto'       => __('Auto'),
     1115                                'cover'      => __('Cover'),
     1116                                'contain'    => __('Contain'),
     1117                        ),
     1118                ) );
     1119
    11041120                $this->add_setting( 'background_position_x', array(
    11051121                        'default'        => get_theme_support( 'custom-background', 'default-position-x' ),
    11061122                        'theme_supports' => 'custom-background',
  • wp-includes/theme.php

    diff --git wp-includes/theme.php wp-includes/theme.php
    index 038310d..c8db99e 100644
    function _custom_background_cb() { 
    13331333                        $position = 'left';
    13341334                $position = " background-position: top $position;";
    13351335
     1336                $size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size'));
     1337                if ( ! in_array( $size, array('auto', 'cover', 'contain')))
     1338                        $size = 'auto';
     1339                $size = " background-size: $size;";
     1340
    13361341                $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
    13371342                if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
    13381343                        $attachment = 'scroll';
    13391344                $attachment = " background-attachment: $attachment;";
    13401345
    1341                 $style .= $image . $repeat . $position . $attachment;
     1346                $style .= $image . $repeat . $position . $size . $attachment;
    13421347        }
    13431348?>
    13441349<style type="text/css" id="custom-background-css">
    function add_theme_support( $feature ) { 
    15821587                                'default-image'          => '',
    15831588                                'default-repeat'         => 'repeat',
    15841589                                'default-position-x'     => 'left',
     1590                                'default-size'           => 'auto',
    15851591                                'default-attachment'     => 'scroll',
    15861592                                'default-color'          => '',
    15871593                                'wp-head-callback'       => '_custom_background_cb',