Allow customisation of theme mod defaults via custom-background theme support.

Give the power to theme authors to select defaults when registering
custom-background support.

Props obenland. Fixes #20816.

Built from https://develop.svn.wordpress.org/trunk@26352


git-svn-id: http://core.svn.wordpress.org/trunk@26253 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jon Cave 2013-11-24 14:05:10 +00:00
parent ba02d07c97
commit fd14a5df71
2 changed files with 23 additions and 20 deletions

View File

@ -206,8 +206,8 @@ if ( get_background_image() ) {
$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', get_background_image() ) ) ) );
// background-image URL must be single quote, see below
$background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
. ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';'
. ' background-position: top ' . get_theme_mod('background_position_x', 'left');
. ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-repeat' ) ) . ';'
. ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'background-position' ) );
}
?>
<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
@ -277,15 +277,15 @@ if ( get_background_image() ) {
<th scope="row"><?php _e( 'Position' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
<label>
<input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> />
<input name="background-position-x" type="radio" value="left"<?php checked( 'left', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'background-position' ) ) ); ?> />
<?php _e('Left') ?>
</label>
<label>
<input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> />
<input name="background-position-x" type="radio" value="center"<?php checked( 'center', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'background-position' ) ) ); ?> />
<?php _e('Center') ?>
</label>
<label>
<input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> />
<input name="background-position-x" type="radio" value="right"<?php checked( 'right', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'background-position' ) ) ); ?> />
<?php _e('Right') ?>
</label>
</fieldset></td>
@ -294,10 +294,10 @@ if ( get_background_image() ) {
<tr valign="top">
<th scope="row"><?php _e( 'Repeat' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
<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>
<label><input type="radio" name="background-repeat" value="repeat"<?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile'); ?></label>
<label><input type="radio" name="background-repeat" value="repeat-x"<?php checked('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Horizontally'); ?></label>
<label><input type="radio" name="background-repeat" value="repeat-y"<?php checked('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Vertically'); ?></label>
<label><input type="radio" name="background-repeat" value="no-repeat"<?php checked( 'no-repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-repeat' ) ) ); ?> /> <?php _e('No Repeat'); ?></label>
<label><input type="radio" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-repeat' ) ) ); ?> /> <?php _e('Tile'); ?></label>
<label><input type="radio" name="background-repeat" value="repeat-x"<?php checked( 'repeat-x', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-repeat' ) ) ); ?> /> <?php _e('Tile Horizontally'); ?></label>
<label><input type="radio" name="background-repeat" value="repeat-y"<?php checked( 'repeat-y', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-repeat' ) ) ); ?> /> <?php _e('Tile Vertically'); ?></label>
</fieldset></td>
</tr>
@ -305,12 +305,12 @@ if ( get_background_image() ) {
<th scope="row"><?php _ex( 'Attachment', 'Background 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', 'scroll')); ?> />
<?php _e('Scroll') ?>
<input name="background-attachment" type="radio" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'background-attachment' ) ) ); ?> />
<?php _e( 'Scroll' ); ?>
</label>
<label>
<input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> />
<?php _e('Fixed') ?>
<input name="background-attachment" type="radio" value="fixed" <?php checked( 'fixed', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'background-attachment' ) ) ); ?> />
<?php _e( 'Fixed' ); ?>
</label>
</fieldset></td>
</tr>

View File

@ -1171,17 +1171,17 @@ function _custom_background_cb() {
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', 'repeat' );
$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'background-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' );
$position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'background-position' ) );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
$position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', 'scroll' );
$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'background-attachment' ) );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
$attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
@ -1373,10 +1373,13 @@ function add_theme_support( $feature ) {
$args = array( 0 => array() );
$defaults = array(
'default-image' => '',
'default-color' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'default-image' => '',
'background-repeat' => 'repeat',
'background-position' => 'left',
'background-attachment' => 'scroll',
'default-color' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);