Improve the custom background front-end callback. Also, background-attachment should default to scroll, not fixed. fixes #13751.
git-svn-id: https://develop.svn.wordpress.org/trunk@15196 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c1104aaed6
commit
2621ba04fe
@ -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>
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user