Make WordPress Core

Changeset 15196


Ignore:
Timestamp:
06/10/2010 06:28:25 PM (13 years ago)
Author:
nacin
Message:

Improve the custom background front-end callback. Also, background-attachment should default to scroll, not fixed. fixes #13751.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-background.php

    r15054 r15196  
    282282<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
    283283<label>
    284 <input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'fixed')); ?> />
     284<input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> />
    285285<?php _e('Scroll') ?>
    286286</label>
    287287<label>
    288 <input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'fixed')); ?> />
     288<input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> />
    289289<?php _e('Fixed') ?>
    290290</label>
  • trunk/wp-includes/theme.php

    r15167 r15196  
    15361536    $background = get_background_image();
    15371537    $color = get_background_color();
    1538     if ( !$background && !$color )
     1538    if ( ! $background && ! $color )
    15391539        return;
    15401540
    1541     switch ( get_theme_mod('background_repeat', 'repeat') ) {
    1542         case 'no-repeat':
    1543             $repeat = 'background-repeat: no-repeat;';
    1544             break;
    1545         case 'repeat-x':
    1546             $repeat = 'background-repeat: repeat-x;';
    1547             break;
    1548         case 'repeat-y':
    1549             $repeat = 'background-repeat: repeat-y;';
    1550             break;
    1551         default:
    1552             $repeat = 'background-repeat: repeat;';
     1541    $style = $color ? "background-color: #$color;" : '';
     1542
     1543    if ( $background ) {
     1544        $image = " background-image: url('$background');";
     1545
     1546        $repeat = get_theme_mod( 'background_repeat', 'repeat' );
     1547        if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
     1548            $repeat = 'repeat';
     1549        $repeat = " background-repeat: $repeat;";
     1550   
     1551        $position = get_theme_mod( 'background_position_x', 'left' );
     1552        if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
     1553            $position = 'left';
     1554        $position = " background-position: top $position;";
     1555   
     1556        $attachment = get_theme_mod( 'background_attachment', 'scroll' );
     1557        if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
     1558            $attachment = 'scroll';
     1559        $attachment = " background-attachment: $attachment;";
     1560
     1561        $style .= $image . $repeat . $position . $attachment;
    15531562    }
    1554 
    1555     switch ( get_theme_mod('background_position_x', 'left') ) {
    1556         case 'center':
    1557             $position = 'background-position: top center;';
    1558             break;
    1559         case 'right':
    1560             $position = 'background-position: top right;';
    1561             break;
    1562         default:
    1563             $position = 'background-position: top left;';
    1564     }
    1565 
    1566     if ( 'scroll' == get_theme_mod('background_attachment', 'fixed') )
    1567         $attachment = 'background-attachment: scroll;';
    1568     else
    1569         $attachment = 'background-attachment: fixed;';
    1570 
    1571     if ( !empty($background ) )
    1572         $image = "background-image: url('$background');";
    1573     else
    1574         $image = '';
    1575 
    1576     if ( !empty($color) )
    1577         $color = "background-color: #$color;";
    1578     else
    1579         $color = '';
    15801563?>
    15811564<style type="text/css">
    1582 body {
    1583     <?php echo $image; ?>
    1584     <?php echo $color; ?>
    1585     <?php echo $repeat; ?>
    1586     <?php echo $position; ?>
    1587     <?php echo $attachment; ?>
    1588 }
     1565body { <?php echo trim( $style ); ?> }
    15891566</style>
    15901567<?php
Note: See TracChangeset for help on using the changeset viewer.