Make WordPress Core

Ticket #22058: 22058.diff

File 22058.diff, 10.6 KB (added by cdog, 12 years ago)
  • wp-includes/class-wp-customize-manager.php

     
    847847                ) );
    848848
    849849                $this->add_control( 'background_position_x', array(
    850                         'label'      => __( 'Background Position' ),
    851                         'section'    => 'background_image',
    852                         'type'       => 'radio',
    853                         'choices'    => array(
    854                                 'left'       => __('Left'),
    855                                 'center'     => __('Center'),
    856                                 'right'      => __('Right'),
     850                        'label'   => __( 'Horizontal Background Position' ),
     851                        'section' => 'background_image',
     852                        'type'    => 'radio',
     853                        'choices' => array(
     854                                'left'   => __( 'Left' ),
     855                                'center' => __( 'Center' ),
     856                                'right'  => __( 'Right' ),
    857857                        ),
    858858                ) );
    859859
     860                $this->add_setting( 'background_position_y', array(
     861                        'default'        => 'top',
     862                        'theme_supports' => 'custom-background',
     863                ) );
     864
     865                $this->add_control( 'background_position_y', array(
     866                        'label'   => __( 'Vertical Background Position' ),
     867                        'section' => 'background_image',
     868                        'type'    => 'radio',
     869                        'choices' => array(
     870                                'top'    => __( 'Top' ),
     871                                'center' => __( 'Center' ),
     872                                'bottom' => __( 'Bottom' )
     873                        ),
     874                ) );
     875
    860876                $this->add_setting( 'background_attachment', array(
    861877                        'default'        => 'fixed',
    862878                        'theme_supports' => 'custom-background',
     
    875891                // If the theme is using the default background callback, we can update
    876892                // the background CSS using postMessage.
    877893                if ( get_theme_support( 'custom-background', 'wp-head-callback' ) === '_custom_background_cb' ) {
    878                         foreach ( array( 'color', 'image', 'position_x', 'repeat', 'attachment' ) as $prop ) {
     894                        foreach ( array( 'attachment', 'color', 'image', 'position_x', 'position_y', 'repeat' ) as $prop ) {
    879895                                $this->get_setting( 'background_' . $prop )->transport = 'postMessage';
    880896                        }
    881897                }
  • wp-includes/js/customize-preview.js

     
    9898                preview.send( 'ready' );
    9999
    100100                /* Custom Backgrounds */
    101                 bg = $.map(['color', 'image', 'position_x', 'repeat', 'attachment'], function( prop ) {
     101                bg = $.map( [ 'attachment', 'color', 'image', 'position_x', 'position_y', 'repeat' ], function( prop ) {
    102102                        return 'background_' + prop;
    103103                });
    104104
    105                 api.when.apply( api, bg ).done( function( color, image, position_x, repeat, attachment ) {
     105                api.when.apply( api, bg ).done( function( attachment, color, image, position_x, position_y, repeat ) {
    106106                        var body = $(document.body),
    107107                                head = $('head'),
    108108                                style = $('#custom-background-css'),
     
    126126                                        css += 'background-color: ' + color() + ';';
    127127
    128128                                if ( image() ) {
     129                                        css += 'background-attachment: ' + attachment() + ';';
    129130                                        css += 'background-image: url("' + image() + '");';
    130                                         css += 'background-position: top ' + position_x() + ';';
     131                                        css += 'background-position: ' + position_x() + ' ' + position_y() + ';';
    131132                                        css += 'background-repeat: ' + repeat() + ';';
    132                                         css += 'background-attachment: ' + attachment() + ';';
    133133                                }
    134134
    135135                                // Refresh the stylesheet by removing and recreating it.
  • wp-includes/theme.php

     
    11671167                        $repeat = 'repeat';
    11681168                $repeat = " background-repeat: $repeat;";
    11691169
    1170                 $position = get_theme_mod( 'background_position_x', 'left' );
    1171                 if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
    1172                         $position = 'left';
    1173                 $position = " background-position: top $position;";
     1170                $position_x = get_theme_mod( 'background_position_x', 'left' );
    11741171
     1172                if ( ! in_array( $position_x, array( 'center', 'left', 'right' ) ) )
     1173                        $position_x = 'left';
     1174
     1175                $position_y = get_theme_mod( 'background_position_y', 'top' );
     1176
     1177                if ( ! in_array( $position_y, array( 'bottom', 'center', 'top' ) ) )
     1178                        $position_y = 'top';
     1179
     1180                $position = ' background-position: ' . $position_x . ' ' . $position_y . ';';
     1181
    11751182                $attachment = get_theme_mod( 'background_attachment', 'scroll' );
    11761183                if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
    11771184                        $attachment = 'scroll';
     
    17321739                }());
    17331740        </script>
    17341741        <?php
    1735 }
    1736  No newline at end of file
     1742}
  • wp-admin/js/custom-background.js

     
    1212                        }
    1313                });
    1414
    15                 $('input[name="background-position-x"]').change(function() {
    16                         bgImage.css('background-position', $(this).val() + ' top');
    17                 });
     15                $( 'input[name="background-position-x"]' ).change( function() {
     16                        bgPosition = bgImage.css( 'background-position' ).split( ' ' );
    1817
     18                        bgImage.css( 'background-position', $( this ).val() + ' ' + bgPosition[1] );
     19                } );
     20
     21                $( 'input[name="background-position-y"]' ).change( function() {
     22                        bgPosition = bgImage.css( 'background-position' ).split( ' ' );
     23
     24                        bgImage.css( 'background-position', bgPosition[0] + ' ' + $( this ).val() );
     25                } );
     26
    1927                $('input[name="background-repeat"]').change(function() {
    2028                        bgImage.css('background-repeat', $(this).val());
    2129                });
     
    7179                        frame.open();
    7280                });
    7381        });
    74 })(jQuery);
    75  No newline at end of file
     82})(jQuery);
  • wp-admin/js/customize-controls.js

     
    914914                // Control visibility for default controls
    915915                $.each({
    916916                        'background_image': {
    917                                 controls: [ 'background_repeat', 'background_position_x', 'background_attachment' ],
     917                                controls: [ 'background_repeat', 'background_position_x', 'background_position_y', 'background_attachment' ],
    918918                                callback: function( to ) { return !! to }
    919919                        },
    920920                        'show_on_front': {
  • wp-admin/custom-background.php

     
    141141                        set_theme_mod('background_repeat', $repeat);
    142142                }
    143143
    144                 if ( isset($_POST['background-position-x']) ) {
    145                         check_admin_referer('custom-background');
    146                         if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) )
    147                                 $position = $_POST['background-position-x'];
     144                if ( isset( $_POST[ 'background-position-x' ] ) ) {
     145                        check_admin_referer( 'custom-background' );
     146
     147                        if ( in_array( $_POST[ 'background-position-x' ], array( 'center', 'left', 'right') ) )
     148                                $position_x = $_POST[ 'background-position-x' ];
    148149                        else
    149                                 $position = 'left';
    150                         set_theme_mod('background_position_x', $position);
     150                                $position_x = 'left';
     151
     152                        set_theme_mod( 'background_position_x', $position_x );
    151153                }
    152154
     155                if ( isset( $_POST[ 'background-position-y' ] ) ) {
     156                        check_admin_referer( 'custom-background' );
     157
     158                        if ( in_array( $_POST[ 'background-position-y' ], array( 'bottom', 'center', 'top' ) ) )
     159                                $position_y = $_POST[ 'background-position-y' ];
     160                        else
     161                                $position_y = 'top';
     162
     163                        set_theme_mod( 'background_position_y', $position_y );
     164                }
     165
    153166                if ( isset($_POST['background-attachment']) ) {
    154167                        check_admin_referer('custom-background');
    155168                        if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
     
    206219        // background-image URL must be single quote, see below
    207220        $background_styles .= ' background-image: url(\'' . set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ) . '\');'
    208221                . ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';'
    209                 . ' background-position: top ' . get_theme_mod('background_position_x', 'left');
     222                . ' background-position: ' . get_theme_mod( 'background_position_x', 'left' ) . ' ' . get_theme_mod( 'background_position_y', 'top' );
    210223}
    211224?>
    212225<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
     
    273286<tbody>
    274287<?php if ( get_background_image() ) : ?>
    275288<tr valign="top">
    276 <th scope="row"><?php _e( 'Position' ); ?></th>
     289<th scope="row"><?php _e( 'Horizontal Position' ); ?></th>
    277290<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
    278291<label>
    279 <input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> />
    280 <?php _e('Left') ?>
     292<input name="background-position-x" type="radio" value="left"<?php checked( 'left', get_theme_mod( 'background_position_x', 'left' ) ); ?> />
     293<?php _e( 'Left' ); ?>
    281294</label>
    282295<label>
    283 <input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> />
    284 <?php _e('Center') ?>
     296<input name="background-position-x" type="radio" value="center"<?php checked( 'center', get_theme_mod( 'background_position_x', 'left' ) ); ?> />
     297<?php _e( 'Center' ); ?>
    285298</label>
    286299<label>
    287 <input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> />
    288 <?php _e('Right') ?>
     300<input name="background-position-x" type="radio" value="right"<?php checked( 'right', get_theme_mod( 'background_position_x', 'left' ) ); ?> />
     301<?php _e( 'Right' ); ?>
    289302</label>
    290303</fieldset></td>
    291304</tr>
    292305
    293306<tr valign="top">
     307<th scope="row"><?php _e( 'Vertical Position' ); ?></th>
     308<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
     309<label>
     310<input name="background-position-y" type="radio" value="top"<?php checked( 'top', get_theme_mod( 'background_position_y', 'top' ) ); ?> />
     311<?php _e( 'Top' ); ?>
     312</label>
     313<label>
     314<input name="background-position-y" type="radio" value="center"<?php checked( 'center', get_theme_mod( 'background_position_y', 'top' ) ); ?> />
     315<?php _e( 'Center' ); ?>
     316</label>
     317<label>
     318<input name="background-position-y" type="radio" value="bottom"<?php checked( 'bottom', get_theme_mod( 'background_position_y', 'top' ) ); ?> />
     319<?php _e( 'Bottom' ); ?>
     320</label>
     321</fieldset></td>
     322</tr>
     323
     324<tr valign="top">
    294325<th scope="row"><?php _e( 'Repeat' ); ?></th>
    295326<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
    296327<label><input type="radio" name="background-repeat" value="no-repeat"<?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('No Repeat'); ?></label>