+/**
+ * Register a selection of default headers to be displayed by the custom header admin UI.
+ *
+ * @since 3.0.0
+ *
+ * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys.
+ */
+function register_default_headers( $headers ) {
+ global $_wp_default_headers;
+
+ $_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers );
+}
+
+/**
+ * Unregister default headers.
+ *
+ * This function must be called after register_default_headers() has already added the
+ * header you want to remove.
+ *
+ * @see register_default_headers()
+ * @since 3.0.0
+ *
+ * @param string|array The header string id (key of array) to remove, or an array thereof.
+ * @return True on success, false on failure.
+ */
+function unregister_default_headers( $header ) {
+ global $_wp_default_headers;
+ if ( is_array( $header ) ) {
+ array_map( 'unregister_default_headers', $header );
+ } elseif ( isset( $_wp_default_headers[ $header ] ) ) {
+ unset( $_wp_default_headers[ $header ] );
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Retrieve background image for custom background.
+ *
+ * @since 3.0.0
+ *
+ * @return string
+ */
+function get_background_image() {
+ $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : '';
+
+ return get_theme_mod('background_image', $default);
+}
+
+/**
+ * Display background image path.
+ *
+ * @since 3.0.0
+ */
+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.
+ *
+ * The parameter $header_callback callback will be required to display the
+ * content for the 'wp_head' action. The parameter $admin_header_callback
+ * callback will be added to Custom_Background class and that will be added
+ * to the 'admin_menu' action.
+ *
+ * @since 3.0.0
+ * @uses Custom_Background Sets up for $admin_header_callback for administration panel display.
+ *
+ * @param callback $header_callback Call on 'wp_head' action.
+ * @param callback $admin_header_callback Call on custom background administration screen.
+ * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional.
+ */
+function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {
+ if ( isset($GLOBALS['custom_background']) )
+ return;
+
+ if ( empty($header_callback) )
+ $header_callback = '_custom_background_cb';
+
+ add_action('wp_head', $header_callback);
+
+ add_theme_support( 'custom-background' );
+
+ if ( ! is_admin() )
+ return;
+ require_once(ABSPATH . 'wp-admin/custom-background.php');
+ $GLOBALS['custom_background'] =& new Custom_Background($admin_header_callback, $admin_image_div_callback);
+ add_action('admin_menu', array(&$GLOBALS['custom_background'], 'init'));
+}
+
+/**
+ * Default custom background callback.
+ *
+ * @since 3.0.0
+ * @see add_custom_background()
+ * @access protected
+ */
+function _custom_background_cb() {
+ $background = get_background_image();
+ $color = get_background_color();
+ if ( ! $background && ! $color )
+ return;
+
+ $style = $color ? "background-color: #$color;" : '';
+
+ if ( $background ) {
+ $image = " background-image: url('$background');";
+
+ $repeat = get_theme_mod( 'background_repeat', 'repeat' );
+ if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
+ $repeat = 'repeat';
+ $repeat = " background-repeat: $repeat;";
+
+ $position = get_theme_mod( 'background_position_x', 'left' );
+ if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
+ $position = 'left';
+ $position = " background-position: top $position;";
+
+ $attachment = get_theme_mod( 'background_attachment', 'scroll' );
+ if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
+ $attachment = 'scroll';
+ $attachment = " background-attachment: $attachment;";
+
+ $style .= $image . $repeat . $position . $attachment;
+ }
+?>
+<style type="text/css">
+body { <?php echo trim( $style ); ?> }
+</style>
+<?php
+}
+
+/**
+ * Add callback for custom TinyMCE editor stylesheets.
+ *
+ * The parameter $stylesheet is the name of the stylesheet, relative to
+ * the theme root. It also accepts an array of stylesheets.
+ * It is optional and defaults to 'editor-style.css'.
+ *
+ * @since 3.0.0
+ *
+ * @param mixed $stylesheet Optional. Stylesheet name or array thereof, relative to theme root.
+ * Defaults to 'editor-style.css'
+ */
+function add_editor_style( $stylesheet = 'editor-style.css' ) {
+
+ add_theme_support( 'editor-style' );
+
+ if ( ! is_admin() )
+ return;
+
+ global $editor_styles;
+ $editor_styles = (array) $editor_styles;
+ $stylesheet = (array) $stylesheet;
+ if ( is_rtl() ) {
+ $rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]);
+ $stylesheet[] = $rtl_stylesheet;
+ }
+
+ $editor_styles = array_merge( $editor_styles, $stylesheet );
+}
+