From 4b766eb312be9b70e1d2421fba2072a3ed846d61 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 3 Mar 2010 17:10:43 +0000 Subject: [PATCH] Background color selection. Props lancewillett. see #12186 git-svn-id: http://svn.automattic.com/wordpress/trunk@13574 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/custom-background.php | 103 ++++++++++++++++++++++++++++++++- wp-includes/theme.php | 28 ++++++++- 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index bf5f33f11..22ecc7995 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -57,7 +57,10 @@ class Custom_Background { $page = add_theme_page(__('Background'), __('Background'), 'switch_themes', 'custom-background', array(&$this, 'admin_page')); - add_action("admin_head-$page", array(&$this, 'take_action'), 50); + add_action("admin_print_scripts-$page", array(&$this, 'js_includes')); + add_action("admin_print_styles-$page", array(&$this, 'css_includes')); + add_action("admin_head-$page", array(&$this, 'js'), 50); + add_action("admin_head-$page", array(&$this, 'take_action'), 49); if ( $this->admin_header_callback ) add_action("admin_head-$page", $this->admin_header_callback, 51); } @@ -80,6 +83,30 @@ class Custom_Background { return $step; } + /** + * Setup the enqueue for the JavaScript files. + * + * @since unknown + */ + function js_includes() { + $step = $this->step(); + + if ( 1 == $step ) + wp_enqueue_script('farbtastic'); + } + + /** + * Setup the enqueue for the CSS files + * + * @since unknown + */ + function css_includes() { + $step = $this->step(); + + if ( 1 == $step ) + wp_enqueue_style('farbtastic'); + } + /** * Execute custom background modification. * @@ -119,6 +146,70 @@ class Custom_Background { } if ( isset($_POST['remove-background']) ) set_theme_mod('background_image', ''); + if ( isset( $_POST['background-color'] ) ) { + $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); + if ( strlen($color) == 6 || strlen($color) == 3 ) + set_theme_mod('background_color', $color); + else + set_theme_mod('background_color', ''); + } + } + + /** + * Execute Javascript depending on step. + * + * @since unknown + */ + function js() { + $step = $this->step(); + if ( 1 == $step ) + $this->js_1(); + } + + /** + * Display Javascript based on Step 1. + * + * @since unknown + */ + function js_1() { ?> + +admin_image_div_callback); } else { ?> -
+
+ @@ -201,6 +293,13 @@ if ( get_background_image() ) : ?> + +
+ + + + +
diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 5375ab31f..033a4df9b 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1357,7 +1357,7 @@ function register_default_headers( $headers ) { * @return string */ function get_background_image() { - $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : ''; + $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : ''; return get_theme_mod('background_image', $default); } @@ -1371,6 +1371,29 @@ function background_image() { echo get_background_image(); } +/** + * Retrieve value for custom background color. + * + * @since 3.0.0 + * @uses BACKGROUND_COLOR + * + * @return string + */ +function get_background_color() { + $default = defined('BACKGROUND_COLOR') ? BACKGROUND_COLOR : ''; + + return get_theme_mod('background_color', $default); +} + +/** + * Display background color value. + * + * @since 3.0.0 + */ +function background_color() { + echo get_background_color(); +} + /** * Add callbacks for background image display. * @@ -1437,7 +1460,8 @@ function _custom_background_cb() { ?>