Ticket #12186: background_js_valid.patch
File background_js_valid.patch, 7.7 KB (added by , 15 years ago) |
---|
-
wp-admin/custom-background.php
85 85 if ( empty($_POST) ) 86 86 return; 87 87 88 check_admin_referer('custom-background');89 90 88 if ( isset($_POST['reset-background']) ) { 91 remove_theme_mod( 'background_image' ); 89 check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset'); 90 remove_theme_mod('background_image'); 91 remove_theme_mod('background_image_thumb'); 92 92 return; 93 93 } 94 94 if ( isset($_POST['remove-background']) ) { 95 95 // @TODO: Uploaded files are not removed here. 96 check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove'); 96 97 set_theme_mod('background_image', ''); 98 set_theme_mod('background_image_thumb', ''); 99 return; 97 100 } 98 101 99 102 if ( isset($_POST['background-repeat']) ) { 103 check_admin_referer('custom-background'); 100 104 if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) ) 101 105 $repeat = $_POST['background-repeat']; 102 106 else … … 104 108 set_theme_mod('background_repeat', $repeat); 105 109 } 106 110 if ( isset($_POST['background-position']) ) { 111 check_admin_referer('custom-background'); 107 112 if ( in_array($_POST['background-position'], array('center', 'right', 'left')) ) 108 113 $position = $_POST['background-position']; 109 114 else … … 111 116 set_theme_mod('background_position', $position); 112 117 } 113 118 if ( isset($_POST['background-attachment']) ) { 119 check_admin_referer('custom-background'); 114 120 if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) ) 115 121 $attachment = $_POST['background-attachment']; 116 122 else … … 118 124 set_theme_mod('background_attachment', $attachment); 119 125 } 120 126 if ( isset($_POST['background-color']) ) { 127 check_admin_referer('custom-background'); 121 128 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); 122 129 if ( strlen($color) == 6 || strlen($color) == 3 ) 123 130 set_theme_mod('background_color', $color); … … 156 163 <td> 157 164 <?php 158 165 $background_styles = ''; 159 if ( get_background_color() ) {160 $background_styles .= "background-color: # " . get_background_color() . ";";166 if ( $bgcolor = get_background_color() ) { 167 $background_styles .= "background-color: #{$bgcolor};"; 161 168 } 162 169 163 170 if ( get_background_image() ) { … … 171 178 ?> 172 179 <div id="custom-background-image" style="<?php echo $background_styles; ?>"> 173 180 <?php if ( get_background_image() ) { ?> 174 <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" /><br />175 <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" />181 <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /><br /> 182 <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /> 176 183 <?php } ?> 177 184 <br class="clear" /> 178 185 </div> … … 184 191 <th scope="row"><?php _e('Remove Image'); ?></th> 185 192 <td><p><?php _e('This will remove the background image. You will not be able to restore any customizations.') ?></p> 186 193 <form method="post" action=""> 187 <?php wp_nonce_field('custom-background '); ?>194 <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?> 188 195 <input type="submit" class="button" name="remove-background" value="<?php esc_attr_e('Remove Background'); ?>" /> 189 196 </form> 190 197 </td> … … 196 203 <th scope="row"><?php _e('Restore Original Image'); ?></th> 197 204 <td><p><?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?></p> 198 205 <form method="post" action=""> 199 <?php wp_nonce_field('custom-background '); ?>206 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> 200 207 <input type="submit" class="button" name="reset-background" value="<?php esc_attr_e('Restore Original Image'); ?>" /> 201 208 </form> 202 209 </td> 203 210 </tr> 204 </form> 211 205 212 <?php endif; ?> 206 213 <tr valign="top"> 207 214 <th scope="row"><?php _e('Upload Image'); ?></th> 208 <td><form enctype="multipart/form-data" id="upload Form" method="post" action="">215 <td><form enctype="multipart/form-data" id="upload-form" method="post" action=""> 209 216 <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" /> 210 217 <input type="hidden" name="action" value="save" /> 211 <?php wp_nonce_field('custom-background ') ?>218 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 212 219 <p class="submit"> 213 220 <input type="submit" value="<?php esc_attr_e('Upload'); ?>" /> 214 221 </p> … … 299 306 if ( empty($_FILES) ) 300 307 return; 301 308 302 check_admin_referer('custom-background ');309 check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); 303 310 $overrides = array('test_form' => false); 304 311 $file = wp_handle_upload($_FILES['import'], $overrides); 305 312 … … 329 336 330 337 $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); 331 338 set_theme_mod('background_image_thumb', esc_url( $thumbnail[0] ) ); 332 333 set_theme_mod('background_position', get_theme_mod('background_position', 'left') );334 set_theme_mod('background_repeat', get_theme_mod('background_repeat', 'tile') );335 set_theme_mod('background-attachment', get_theme_mod('background_position', 'fixed') );336 339 337 340 do_action('wp_create_file_in_uploads', $file, $id); // For replication 338 341 $this->updated = true; -
wp-admin/js/custom-background.dev.js
1 var buttons = ['#pickcolor'],farbtastic;1 var farbtastic; 2 2 3 3 function pickColor(color) { 4 4 jQuery('#background-color').val(color); 5 farbtastic.setColor(color);6 5 jQuery('#custom-background-image').css('background-color', color); 6 farbtastic.setColor(color); 7 7 } 8 8 9 9 jQuery(document).ready(function() { 10 10 jQuery('#pickcolor').click(function() { 11 11 jQuery('#colorPickerDiv').show(); 12 12 }); 13 13 14 jQuery('#background-color').keyup(function() { 14 15 var _hex = jQuery('#background-color').val(); 15 16 var hex = _hex; … … 21 22 if ( hex.length == 4 || hex.length == 7 ) 22 23 pickColor( hex ); 23 24 }); 25 24 26 jQuery('input[name="background-position"]').change(function() { 25 jQuery('#custom-background-image').css('background-position', 'top ' +jQuery(this).val());27 jQuery('#custom-background-image').css('background-position', 'top ' + jQuery(this).val()); 26 28 }); 29 27 30 jQuery('select[name="background-repeat"]').change(function() { 28 31 jQuery('#custom-background-image').css('background-repeat', jQuery(this).val()); 29 32 }); … … 31 34 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { 32 35 pickColor(color); 33 36 }); 34 pickColor(customBackgroundL10n.backgroundcolor); 35 }); 37 pickColor(jQuery('#background-color').val()); 36 38 37 jQuery(document).mousedown(function(){ 38 hide_picker(); // Make the picker disappear if you click outside its div element 39 }); 40 41 function hide_picker(what) { 42 var update = false; 43 jQuery('#colorPickerDiv').each(function(){ 44 var id = jQuery(this).attr('id'); 45 if ( id == what ) 46 return; 47 48 var display = jQuery(this).css('display'); 49 if ( display == 'block' ) 50 jQuery(this).fadeOut(2); 39 jQuery(document).mousedown(function(){ 40 jQuery('#colorPickerDiv').each(function(){ 41 var display = jQuery(this).css('display'); 42 if ( display == 'block' ) 43 jQuery(this).fadeOut(2); 44 }); 51 45 }); 52 } 53 No newline at end of file 46 });