Show Background preview and options when no Image is uploaded. Display "Updated" div upon updates. Fix Colour Picker not loading after uploading a background image. See #12186

git-svn-id: http://svn.automattic.com/wordpress/trunk@13765 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-19 09:33:29 +00:00
parent 0b4c703fd8
commit 0c47af2d38
1 changed files with 16 additions and 31 deletions

View File

@ -89,10 +89,7 @@ class Custom_Background {
* @since unknown * @since unknown
*/ */
function js_includes() { function js_includes() {
$step = $this->step(); wp_enqueue_script('farbtastic');
if ( 1 == $step )
wp_enqueue_script('farbtastic');
} }
/** /**
@ -101,10 +98,7 @@ class Custom_Background {
* @since unknown * @since unknown
*/ */
function css_includes() { function css_includes() {
$step = $this->step(); wp_enqueue_style('farbtastic');
if ( 1 == $step )
wp_enqueue_style('farbtastic');
} }
/** /**
@ -153,6 +147,8 @@ class Custom_Background {
else else
set_theme_mod('background_color', ''); set_theme_mod('background_color', '');
} }
$this->updated = true;
} }
/** /**
@ -161,9 +157,7 @@ class Custom_Background {
* @since unknown * @since unknown
*/ */
function js() { function js() {
$step = $this->step(); $this->js_1();
if ( 1 == $step )
$this->js_1();
} }
/** /**
@ -234,13 +228,11 @@ class Custom_Background {
<div class="wrap" id="custom-background"> <div class="wrap" id="custom-background">
<?php screen_icon(); ?> <?php screen_icon(); ?>
<h2><?php _e('Custom Background'); ?></h2> <h2><?php _e('Custom Background'); ?></h2>
<?php if ( isset($_GET['updated']) && $_GET['updated'] ) { ?> <?php if ( !empty($this->updated) ) { ?>
<div id="message" class="updated"> <div id="message" class="updated">
<p><?php printf(__('Background updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p> <p><?php printf(__('Background updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p>
</div> </div>
<?php } <?php } ?>
if ( get_background_image() || get_background_color() ) { ?>
<p><?php _e('This is your current background.'); ?></p> <p><?php _e('This is your current background.'); ?></p>
<?php <?php
if ( $this->admin_image_div_callback ) { if ( $this->admin_image_div_callback ) {
@ -256,13 +248,7 @@ if ( get_background_image() || get_background_color() ) { ?>
<img class="custom-background-image" src="<?php background_image(); ?>" /> <img class="custom-background-image" src="<?php background_image(); ?>" />
<?php } ?> <?php } ?>
</div> </div>
<?php } <?php } ?>
} else { ?>
<p><?php _e('There is currently no background image.'); ?></p> <?php
}
if ( get_background_image() ) : ?>
<h3><?php _e('Change Display Options') ?></h3> <h3><?php _e('Change Display Options') ?></h3>
<form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>"> <form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>">
<table> <table>
@ -327,8 +313,6 @@ if ( get_background_image() ) : ?>
<p class="submit"><input type="submit" class="button" name="save-background-options" value="<?php esc_attr_e('Save Changes'); ?>" /></p> <p class="submit"><input type="submit" class="button" name="save-background-options" value="<?php esc_attr_e('Save Changes'); ?>" /></p>
</form> </form>
<?php endif; ?>
<h3><?php _e('Upload New Background Image'); ?></h3> <h3><?php _e('Upload New Background Image'); ?></h3>
<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo esc_attr(add_query_arg('step', 2)) ?>"> <form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo esc_attr(add_query_arg('step', 2)) ?>">
<label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" /> <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
@ -363,7 +347,7 @@ if ( get_background_image() ) : ?>
$file = wp_handle_upload($_FILES['import'], $overrides); $file = wp_handle_upload($_FILES['import'], $overrides);
if ( isset($file['error']) ) if ( isset($file['error']) )
die( $file['error'] ); wp_die( $file['error'] );
$url = $file['url']; $url = $file['url'];
$type = $file['type']; $type = $file['type'];
@ -372,10 +356,11 @@ if ( get_background_image() ) : ?>
// Construct the object array // Construct the object array
$object = array( $object = array(
'post_title' => $filename, 'post_title' => $filename,
'post_content' => $url, 'post_content' => $url,
'post_mime_type' => $type, 'post_mime_type' => $type,
'guid' => $url); 'guid' => $url
);
// Save the data // Save the data
$id = wp_insert_attachment($object, $file); $id = wp_insert_attachment($object, $file);
@ -385,6 +370,7 @@ if ( get_background_image() ) : ?>
set_theme_mod('background_image', esc_url($url)); set_theme_mod('background_image', esc_url($url));
do_action('wp_create_file_in_uploads', $file, $id); // For replication do_action('wp_create_file_in_uploads', $file, $id); // For replication
$this->updated = true;
return $this->finished(); return $this->finished();
} }
@ -394,8 +380,7 @@ if ( get_background_image() ) : ?>
* @since unknown * @since unknown
*/ */
function finished() { function finished() {
$_GET['updated'] = 1; $this->step_1();
$this->step_1();
} }
/** /**