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

git-svn-id: http://svn.automattic.com/wordpress/trunk@15196 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-06-10 18:28:25 +00:00
parent 4c53975440
commit 69164abe07
2 changed files with 25 additions and 48 deletions

View File

@ -281,11 +281,11 @@ if ( get_background_image() ) {
<th scope="row"><?php _e( 'Attachment' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
<label>
<input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'fixed')); ?> />
<input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> />
<?php _e('Scroll') ?>
</label>
<label>
<input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'fixed')); ?> />
<input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> />
<?php _e('Fixed') ?>
</label>
</fieldset></td>

View File

@ -1535,57 +1535,34 @@ function add_custom_background($header_callback = '', $admin_header_callback = '
function _custom_background_cb() {
$background = get_background_image();
$color = get_background_color();
if ( !$background && !$color )
if ( ! $background && ! $color )
return;
switch ( get_theme_mod('background_repeat', 'repeat') ) {
case 'no-repeat':
$repeat = 'background-repeat: no-repeat;';
break;
case 'repeat-x':
$repeat = 'background-repeat: repeat-x;';
break;
case 'repeat-y':
$repeat = 'background-repeat: repeat-y;';
break;
default:
$repeat = 'background-repeat: repeat;';
$style = $color ? "background-color: #$color;" : '';
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', 'repeat' );
if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
$repeat = 'repeat';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', 'left' );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
$position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', 'scroll' );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
$attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position . $attachment;
}
switch ( get_theme_mod('background_position_x', 'left') ) {
case 'center':
$position = 'background-position: top center;';
break;
case 'right':
$position = 'background-position: top right;';
break;
default:
$position = 'background-position: top left;';
}
if ( 'scroll' == get_theme_mod('background_attachment', 'fixed') )
$attachment = 'background-attachment: scroll;';
else
$attachment = 'background-attachment: fixed;';
if ( !empty($background ) )
$image = "background-image: url('$background');";
else
$image = '';
if ( !empty($color) )
$color = "background-color: #$color;";
else
$color = '';
?>
<style type="text/css">
body {
<?php echo $image; ?>
<?php echo $color; ?>
<?php echo $repeat; ?>
<?php echo $position; ?>
<?php echo $attachment; ?>
}
body { <?php echo trim( $style ); ?> }
</style>
<?php
}