admin_header_callback = $admin_header_callback; $this->admin_image_div_callback = $admin_image_div_callback; } /** * Set up the hooks for the Custom Background admin page. * */ function init() { if ( ! current_user_can('edit_theme_options') ) return; $this->page = $page = add_theme_page(__('Background', 'shiword'), __('Background', 'shiword'), 'edit_theme_options', 'custom-background', array(&$this, 'admin_page')); add_action("load-$page", array(&$this, 'admin_load')); add_action("load-$page", array(&$this, 'take_action'), 49); if ( $this->admin_header_callback ) add_action("admin_head-$page", $this->admin_header_callback, 51); } /** * Set up the enqueue for the CSS & JavaScript files. * */ function admin_load() { global $shiword_version; wp_enqueue_script( 'sw-custom-bg-script', get_template_directory_uri() . '/js/admin-custom_background.dev.js', array( 'jquery', 'farbtastic' ), $shiword_version, true ); wp_enqueue_style( 'sw-custom-bg-style', get_template_directory_uri() . '/css/admin-custom_background.css', array( 'farbtastic' ), false, 'screen' ); } /** * Execute custom background modification. * */ function take_action() { if ( empty($_POST) ) return; if ( isset($_POST['remove-background']) ) { check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove'); set_theme_mod('background_image', ''); set_theme_mod('background_image_thumb', ''); $this->updated = true; return; } 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); else set_theme_mod('background_color', ''); } if ( isset($_POST['default-bg']) ) { check_admin_referer('custom-background'); $this->process_default_bg_images(); if ( in_array($_POST['default-bg'], array('bamboo','flowers','equalizer','negative')) ) { set_theme_mod('background_image', esc_url($this->default_bg_images[$_POST['default-bg']]['url'])); set_theme_mod('background_image_thumb', esc_url($this->default_bg_images[$_POST['default-bg']]['thumbnail_url']) ); } } $this->updated = true; } /* Process the default headers */ function process_default_bg_images() { $default_bg_images = array( 'bamboo' => array( 'url' => '%s/images/backgrounds/bamboo.png', 'thumbnail_url' => '%s/images/backgrounds/bamboo-thumbnail.jpg', 'description' => __( 'Bamboo', 'shiword' ), 'color' => '#E5E2CC' ), 'flowers' => array( 'url' => '%s/images/backgrounds/flowers.png', 'thumbnail_url' => '%s/images/backgrounds/flowers-thumbnail.jpg', 'description' => __( 'Flowers', 'shiword' ), 'color' => '#404040' ), 'equalizer' => array( 'url' => '%s/images/backgrounds/equalizer.png', 'thumbnail_url' => '%s/images/backgrounds/equalizer-thumbnail.jpg', 'description' => __( 'Equalizer', 'shiword' ), 'color' => '#007cbc' ), 'negative' => array( 'url' => '%s/images/backgrounds/negative.png', 'thumbnail_url' => '%s/images/backgrounds/negative-thumbnail.jpg', 'description' => __( 'Negative', 'shiword' ), 'color' => '#ffc07d' ) ); $this->default_bg_images = $default_bg_images; foreach ( array_keys($this->default_bg_images) as $header ) { $this->default_bg_images[$header]['url'] = sprintf( $this->default_bg_images[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); $this->default_bg_images[$header]['thumbnail_url'] = sprintf( $this->default_bg_images[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); } } /** * Display UI for selecting one of several default backgrounds. * */ function show_default_bg_selector() { foreach ( $this->default_bg_images as $header_key => $header ) { $header_thumbnail = $header['thumbnail_url']; $header_url = $header['url']; $header_desc = $header['description']; ?>

:
process_default_bg_images(); ?>

updated) ) { ?>

Visit your site to see how it looks.', 'shiword' ), home_url( '/' ) ); ?>

admin_image_div_callback ) { call_user_func($this->admin_image_div_callback); } else { ?>



show_default_bg_selector(); ?>

class="hide-if-no-js" id="clearcolor"> ()