WordPress.org

Make WordPress Core

Changeset 13186


Ignore:
Timestamp:
02/18/2010 12:14:56 AM (12 years ago)
Author:
ryan
Message:

Add some options to custom background admin. Needs styling. see #12186

Location:
trunk
Files:
2 edited

Legend:

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

    r13043 r13186  
    9494            remove_theme_mods();
    9595        }
    96         if ( isset($_POST['repeat-background']) ) {
    97             check_admin_referer('custom-background');
    98             $repeat = $_POST['repeat-background'] ? true: false;
     96        if ( isset($_POST['background-repeat']) ) {
     97            check_admin_referer('custom-background');
     98            if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat')) )
     99                $repeat = $_POST['background-repeat'];
     100            else
     101                $repeat = 'repeat';
    99102            set_theme_mod('background_repeat', $repeat);
    100         } elseif ( isset($_POST['save-background-options']) ) {
    101             set_theme_mod('background_repeat', false);
     103        }
     104        if ( isset($_POST['background-position']) ) {
     105            check_admin_referer('custom-background');
     106            if ( in_array($_POST['background-position'], array('center', 'right', 'left')) )
     107                $position = $_POST['background-position'];
     108            else
     109                $position = 'left';
     110            set_theme_mod('background_position', $position);
     111        }
     112        if ( isset($_POST['background-attachment']) ) {
     113            check_admin_referer('custom-background');
     114            if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
     115                $attachment = $_POST['background-attachment'];
     116            else
     117                $attachment = 'fixed';
     118            set_theme_mod('background_attachment', $attachment);
    102119        }
    103120        if ( isset($_POST['remove-background']) ) {
     
    133150} else {
    134151?>
    135 <div id="background-image">
    136 <img src="<?php background_image(); ?>" />
     152<div id="custom-background-image">
     153<img class="custom-background-image" src="<?php background_image(); ?>" />
    137154</div>
    138155<?php } ?>
    139156</div>
     157
     158<?php if ( get_background_image() ) : ?>
    140159<div class="wrap">
    141 <h2><?php _e('Upload New Background Image'); ?></h2><p><?php _e('Here you can upload a new background image.'); ?></p>
    142 
     160
     161<h2><?php _e('Change Display Options') ?></h2>
     162<form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>">
     163<table>
     164<thead>
     165<tr>
     166<th scope="col"><?php _e( 'Position' ); ?></th>
     167<th scope="col"><?php _e( 'Repeat' ); ?></th>
     168<th scope="col"><?php _e( 'Attachment' ); ?></th>
     169</tr>
     170
     171<tbody>
     172<tr>
     173<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Position' ); ?></span></legend>
     174<label>
     175<input name="background-position" type="radio" value="left" <?php checked('left', get_theme_mod('background_position')); ?> />
     176<?php _e('Left') ?>
     177</label>
     178<label>
     179<input name="background-position" type="radio" value="center" <?php checked('center', get_theme_mod('background_position')); ?> />
     180<?php _e('Center') ?>
     181</label>
     182<label>
     183<input name="background-position" type="radio" value="right" <?php checked('right', get_theme_mod('background_position')); ?> />
     184<?php _e('Right') ?>
     185</label>
     186</fieldset></td>
     187
     188<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Repeat' ); ?></span></legend>
     189<label>
     190<input name="background-repeat" type="radio" value="no-repeat" <?php checked('no-repeat', get_theme_mod('background_repeat')); ?> />
     191<?php _e('No repeat') ?>
     192</label>
     193<label>
     194<input name="background-repeat" type="radio" value="repeat" <?php checked('repeat', get_theme_mod('background_repeat')); ?> />
     195<?php _e('Tile') ?>
     196</label>
     197</fieldset></td>
     198
     199<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Attachment' ); ?></span></legend>
     200<label>
     201<input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment')); ?> />
     202<?php _e('Scroll') ?>
     203</label>
     204<label>
     205<input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment')); ?> />
     206<?php _e('Fixed') ?>
     207</label>
     208</fieldset></td>
     209</tr>
     210</tbody>
     211</table>
     212
     213<?php wp_nonce_field('custom-background'); ?>
     214<input type="submit" class="button" name="save-background-options" value="<?php esc_attr_e('Save Changes'); ?>" />
     215</form>
     216</div>
     217<?php endif; ?>
     218
     219<div class="wrap">
     220<h2><?php _e('Upload New Background Image'); ?></h2>
    143221<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo esc_attr(add_query_arg('step', 2)) ?>" style="margin: auto; width: 50%;">
    144222<label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
     
    149227</p>
    150228</form>
    151 
    152 </div>
    153 
    154 <div class="wrap">
    155 
    156 <h2><?php _e('Change Display Options') ?></h2>
    157 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>">
    158 <label for="repeat-background">
    159 <p><input name="repeat-background" type="checkbox" id="repeat-background" value="1" <?php checked(true, get_theme_mod('background_repeat')); ?> />
    160 <?php _e('Tile the background.') ?></label></p>
    161 <?php wp_nonce_field('custom-background'); ?>
    162 <input type="submit" class="button" name="save-background-options" value="<?php esc_attr_e('Save Changes'); ?>" />
    163 </form>
    164 </div>
    165 
    166 <?php if ( get_theme_mod('background_image') ) : ?>
    167 <div class="wrap">
    168 <h2><?php _e('Reset Background Image'); ?></h2>
    169 <p><?php _e('This will restore the original background image. You will not be able to retrieve any customizations.') ?></p>
    170 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>">
    171 <?php wp_nonce_field('custom-background'); ?>
    172 <input type="submit" class="button" name="reset-background" value="<?php esc_attr_e('Restore Original Background'); ?>" />
    173 </form>
    174 </div>
    175 <?php endif;
    176 
    177 if ( get_background_image() ) :
    178 ?>
     229</div>
     230
     231<?php if ( get_background_image() ) : ?>
    179232<div class="wrap">
    180233<h2><?php _e('Remove Background Image'); ?></h2>
  • trunk/wp-includes/theme.php

    r13041 r13186  
    13991399
    14001400    $repeat = get_theme_mod('background_repeat');
    1401     $repeat = $repeat ? '' : ' no-repeat';
     1401    if ( 'no-repeat' == $repeat )
     1402        $repeat = 'background-repeat: no-repeat;';
     1403    else
     1404        $repeat = 'background-repeat: repeat;';
     1405    $position = get_theme_mod('background_position');
     1406    if  ( 'center' == $position )
     1407        $position = 'background-position: center;';
     1408    elseif ( 'right' == $position )
     1409        $position = 'background-position: right;';
     1410    else
     1411        $position = 'background-position: left;';
     1412    $attachment = get_theme_mod('background_attachment');
     1413    if ( 'scroll' == $attachment )
     1414        $attachment = 'background-attachment: scroll;';
     1415    else
     1416        $attachment = 'background-attachment: fixed;';
    14021417?>
    14031418<style type="text/css">
    14041419body {
    1405     background: url('<?php background_image(); ?>') fixed <?php echo $repeat ?>;
     1420    background-image:url('<?php background_image(); ?>');
     1421    <?php echo $repeat; ?>
     1422    <?php echo $position; ?>
     1423    <?php echo $attachment; ?>
    14061424}
    14071425</style>
Note: See TracChangeset for help on using the changeset viewer.