diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index d69dc57f3..a79be95ab 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -85,18 +85,22 @@ class Custom_Background { if ( empty($_POST) ) return; - check_admin_referer('custom-background'); - if ( isset($_POST['reset-background']) ) { - remove_theme_mod( 'background_image' ); + check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset'); + remove_theme_mod('background_image'); + remove_theme_mod('background_image_thumb'); return; } if ( isset($_POST['remove-background']) ) { // @TODO: Uploaded files are not removed here. + check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove'); set_theme_mod('background_image', ''); + set_theme_mod('background_image_thumb', ''); + return; } if ( isset($_POST['background-repeat']) ) { + check_admin_referer('custom-background'); if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) ) $repeat = $_POST['background-repeat']; else @@ -104,6 +108,7 @@ class Custom_Background { set_theme_mod('background_repeat', $repeat); } if ( isset($_POST['background-position']) ) { + check_admin_referer('custom-background'); if ( in_array($_POST['background-position'], array('center', 'right', 'left')) ) $position = $_POST['background-position']; else @@ -111,6 +116,7 @@ class Custom_Background { set_theme_mod('background_position', $position); } if ( isset($_POST['background-attachment']) ) { + check_admin_referer('custom-background'); if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) ) $attachment = $_POST['background-attachment']; else @@ -118,6 +124,7 @@ class Custom_Background { set_theme_mod('background_attachment', $attachment); } if ( isset($_POST['background-color']) ) { + check_admin_referer('custom-background'); $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); if ( strlen($color) == 6 || strlen($color) == 3 ) set_theme_mod('background_color', $color); @@ -156,23 +163,23 @@ class Custom_Background {
-
- +
+
@@ -184,7 +191,7 @@ if ( get_background_image() ) {

- +
@@ -196,19 +203,19 @@ if ( get_background_image() ) {

- +
- + -
+
- +

@@ -299,7 +306,7 @@ if ( get_background_image() ) { if ( empty($_FILES) ) return; - check_admin_referer('custom-background'); + check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES['import'], $overrides); @@ -329,10 +336,6 @@ if ( get_background_image() ) { $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); set_theme_mod('background_image_thumb', esc_url( $thumbnail[0] ) ); - - set_theme_mod('background_position', get_theme_mod('background_position', 'left') ); - set_theme_mod('background_repeat', get_theme_mod('background_repeat', 'tile') ); - set_theme_mod('background-attachment', get_theme_mod('background_position', 'fixed') ); do_action('wp_create_file_in_uploads', $file, $id); // For replication $this->updated = true; diff --git a/wp-admin/js/custom-background.dev.js b/wp-admin/js/custom-background.dev.js index b105d9ac2..877939541 100644 --- a/wp-admin/js/custom-background.dev.js +++ b/wp-admin/js/custom-background.dev.js @@ -1,8 +1,8 @@ -var buttons = ['#pickcolor'], farbtastic; +var farbtastic; function pickColor(color) { - jQuery('#background-color').val(color); farbtastic.setColor(color); + jQuery('#background-color').val(color); jQuery('#custom-background-image').css('background-color', color); } @@ -10,6 +10,7 @@ jQuery(document).ready(function() { jQuery('#pickcolor').click(function() { jQuery('#colorPickerDiv').show(); }); + jQuery('#background-color').keyup(function() { var _hex = jQuery('#background-color').val(); var hex = _hex; @@ -21,32 +22,29 @@ jQuery(document).ready(function() { if ( hex.length == 4 || hex.length == 7 ) pickColor( hex ); }); + jQuery('input[name="background-position"]').change(function() { - jQuery('#custom-background-image').css('background-position', 'top '+jQuery(this).val()); + jQuery('#custom-background-image').css('background-position', 'top ' + jQuery(this).val()); }); + jQuery('select[name="background-repeat"]').change(function() { jQuery('#custom-background-image').css('background-repeat', jQuery(this).val()); }); + + jQuery('input[name="background-attachment"]').change(function() { + jQuery('#custom-background-image').css('background-attachment', jQuery(this).val()); + }); farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); - pickColor(customBackgroundL10n.backgroundcolor); -}); + pickColor(jQuery('#background-color').val()); -jQuery(document).mousedown(function(){ - hide_picker(); // Make the picker disappear if you click outside its div element -}); - -function hide_picker(what) { - var update = false; - jQuery('#colorPickerDiv').each(function(){ - var id = jQuery(this).attr('id'); - if ( id == what ) - return; - - var display = jQuery(this).css('display'); - if ( display == 'block' ) - jQuery(this).fadeOut(2); + jQuery(document).mousedown(function(){ + jQuery('#colorPickerDiv').each(function(){ + var display = jQuery(this).css('display'); + if ( display == 'block' ) + jQuery(this).fadeOut(2); + }); }); -} \ No newline at end of file +}); diff --git a/wp-admin/js/custom-background.js b/wp-admin/js/custom-background.js index 1bdee366f..5371933ee 100644 --- a/wp-admin/js/custom-background.js +++ b/wp-admin/js/custom-background.js @@ -1 +1 @@ -var buttons=["#pickcolor"],farbtastic;function pickColor(color){jQuery("#background-color").val(color);farbtastic.setColor(color);jQuery("#custom-background-image").css("background-color",color)}jQuery(document).ready(function(){jQuery("#pickcolor").click(function(){jQuery("#colorPickerDiv").show()});jQuery("#background-color").keyup(function(){var _hex=jQuery("#background-color").val();var hex=_hex;if(hex[0]!="#"){hex="#"+hex}hex=hex.replace(/[^#a-fA-F0-9]+/,"");if(hex!=_hex){jQuery("#background-color").val(hex)}if(hex.length==4||hex.length==7){pickColor(hex)}});jQuery('input[name="background-position"]').change(function(){jQuery("#custom-background-image").css("background-position","top "+jQuery(this).val())});jQuery('select[name="background-repeat"]').change(function(){jQuery("#custom-background-image").css("background-repeat",jQuery(this).val())});farbtastic=jQuery.farbtastic("#colorPickerDiv",function(color){pickColor(color)});pickColor(customBackgroundL10n.backgroundcolor)});jQuery(document).mousedown(function(){hide_picker()});function hide_picker(what){var update=false;jQuery("#colorPickerDiv").each(function(){var id=jQuery(this).attr("id");if(id==what){return}var display=jQuery(this).css("display");if(display=="block"){jQuery(this).fadeOut(2)}})}; \ No newline at end of file +var farbtastic;function pickColor(a){farbtastic.setColor(a);jQuery("#background-color").val(a);jQuery("#custom-background-image").css("background-color",a)}jQuery(document).ready(function(){jQuery("#pickcolor").click(function(){jQuery("#colorPickerDiv").show()});jQuery("#background-color").keyup(function(){var b=jQuery("#background-color").val();var a=b;if(a[0]!="#"){a="#"+a}a=a.replace(/[^#a-fA-F0-9]+/,"");if(a!=b){jQuery("#background-color").val(a)}if(a.length==4||a.length==7){pickColor(a)}});jQuery('input[name="background-position"]').change(function(){jQuery("#custom-background-image").css("background-position","top "+jQuery(this).val())});jQuery('select[name="background-repeat"]').change(function(){jQuery("#custom-background-image").css("background-repeat",jQuery(this).val())});jQuery('input[name="background-attachment"]').change(function(){jQuery("#custom-background-image").css("background-attachment",jQuery(this).val())});farbtastic=jQuery.farbtastic("#colorPickerDiv",function(a){pickColor(a)});pickColor(jQuery("#background-color").val());jQuery(document).mousedown(function(){jQuery("#colorPickerDiv").each(function(){var a=jQuery(this).css("display");if(a=="block"){jQuery(this).fadeOut(2)}})})}); \ No newline at end of file