wp/wp-admin/custom-background.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * The custom background script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * The custom background class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class Custom_Background {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	 * Callback for administration header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 * @var callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	public $admin_header_callback;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * Callback for header div.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @var callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	public $admin_image_div_callback;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	 * @var bool
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	private $updated;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 * Constructor - Register administration header callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 * @param callback $admin_header_callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	 * @param callback $admin_image_div_callback Optional custom image div output callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	public function __construct($admin_header_callback = '', $admin_image_div_callback = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		$this->admin_header_callback = $admin_header_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$this->admin_image_div_callback = $admin_image_div_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		add_action( 'admin_menu', array( $this, 'init' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
		add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
		// Unused since 3.5.0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 * Set up the hooks for the Custom Background admin page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
	public function init() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
		$page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
		if ( ! $page ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
		add_action( "load-$page", array( $this, 'admin_load' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
		add_action( "load-$page", array( $this, 'take_action' ), 49 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
		add_action( "load-$page", array( $this, 'handle_upload' ), 49 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
		if ( $this->admin_header_callback ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
			add_action( "admin_head-$page", $this->admin_header_callback, 51 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Set up the enqueue for the CSS & JavaScript files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	public function admin_load() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
			'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
				'<p>' . __( 'You can customize the look of your site without touching any of your theme&#8217;s code by using a custom background. Your background can be an image or a color.' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
				'<p>' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the &#8220;Choose Image&#8221; button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
				'<p>' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. &#8220;#ff0000&#8221; for red, or by choosing a color using the color picker.' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
				'<p>' . __( 'Don&#8217;t forget to click on the Save Changes button when you are finished.' ) . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
			'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
			'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		wp_enqueue_media();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		wp_enqueue_script('custom-background');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		wp_enqueue_style('wp-color-picker');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	 * Execute custom background modification.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	public function take_action() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		if ( empty($_POST) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		if ( isset($_POST['reset-background']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			remove_theme_mod('background_image');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
			remove_theme_mod('background_image_thumb');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		if ( isset($_POST['remove-background']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
			// @TODO: Uploaded files are not removed here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
			set_theme_mod('background_image', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
			set_theme_mod('background_image_thumb', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
			$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
			wp_safe_redirect( $_POST['_wp_http_referer'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		if ( isset($_POST['background-repeat']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			check_admin_referer('custom-background');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
				$repeat = $_POST['background-repeat'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
				$repeat = 'repeat';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			set_theme_mod('background_repeat', $repeat);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		if ( isset($_POST['background-position-x']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
			check_admin_referer('custom-background');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
				$position = $_POST['background-position-x'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
				$position = 'left';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
			set_theme_mod('background_position_x', $position);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
		if ( isset($_POST['background-attachment']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
			check_admin_referer('custom-background');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
			if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
				$attachment = $_POST['background-attachment'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
				$attachment = 'fixed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
			set_theme_mod('background_attachment', $attachment);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		if ( isset($_POST['background-color']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
			check_admin_referer('custom-background');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			$color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			if ( strlen($color) == 6 || strlen($color) == 3 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
				set_theme_mod('background_color', $color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
				set_theme_mod('background_color', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	 * Display the custom background page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
	public function admin_page() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
<div class="wrap" id="custom-background">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
<h2><?php _e( 'Custom Background' ); ?></h2>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
<?php if ( current_user_can( 'customize' ) ) { ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
<div class="notice notice-info hide-if-no-customize">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	<p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
		<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
		printf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%1$s">Customizer</a>.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
			admin_url( 'customize.php?autofocus[control]=background_image' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
		?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	</p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
<?php } ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
<?php if ( ! empty( $this->updated ) ) { ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
<div id="message" class="updated">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
<p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
</div>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
<?php } ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
<h3><?php _e( 'Background Image' ); ?></h3>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
<tbody>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
<tr>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
<th scope="row"><?php _e( 'Preview' ); ?></th>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
<td>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
	if ( $this->admin_image_div_callback ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
		call_user_func( $this->admin_image_div_callback );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
		$background_styles = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
		if ( $bgcolor = get_background_color() )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
			$background_styles .= 'background-color: #' . $bgcolor . ';';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
		$background_image_thumb = get_background_image();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
		if ( $background_image_thumb ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
			$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
			// Background-image URL must be single quote, see below.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
			$background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
				. ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
				. ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
	?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
		<?php if ( $background_image_thumb ) { ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
		<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
		<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
		<?php } ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
	</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	<?php } ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
</tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
<?php if ( get_background_image() ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
<th scope="row"><?php _e('Remove Image'); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
<td>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
<form method="post">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
<?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
<?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
<?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
<?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
<?php if ( $default_image && get_background_image() != $default_image ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
<th scope="row"><?php _e('Restore Original Image'); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
<td>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
<form method="post">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
<?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
<?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
<?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
</tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
<?php endif; ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
<th scope="row"><?php _e('Select Image'); ?></th>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
<td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		<input type="file" id="upload" name="import" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
		<input type="hidden" name="action" value="save" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		<?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
		<button id="choose-from-library-link" class="button"
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>"
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
			data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></button>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
<h3><?php _e('Display Options') ?></h3>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
<form method="post">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
<?php if ( get_background_image() ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
<th scope="row"><?php _e( 'Position' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
<label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
<input name="background-position-x" type="radio" value="left"<?php checked( 'left', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
<?php _e('Left') ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
<label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
<input name="background-position-x" type="radio" value="center"<?php checked( 'center', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
<?php _e('Center') ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
<label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
<input name="background-position-x" type="radio" value="right"<?php checked( 'right', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
<?php _e('Right') ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
</fieldset></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
<th scope="row"><?php _e( 'Repeat' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
<label><input type="radio" name="background-repeat" value="no-repeat"<?php checked( 'no-repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('No Repeat'); ?></label>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
	<label><input type="radio" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile'); ?></label>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
	<label><input type="radio" name="background-repeat" value="repeat-x"<?php checked( 'repeat-x', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile Horizontally'); ?></label>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
	<label><input type="radio" name="background-repeat" value="repeat-y"<?php checked( 'repeat-y', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile Vertically'); ?></label>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
</fieldset></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
<th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
<label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
<input name="background-attachment" type="radio" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
<?php _e( 'Scroll' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
<label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
<input name="background-attachment" type="radio" value="fixed" <?php checked( 'fixed', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
<?php _e( 'Fixed' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
</fieldset></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
<?php endif; // get_background_image() ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
<th scope="row"><?php _e( 'Background Color' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
$default_color = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
if ( current_theme_supports( 'custom-background', 'default-color' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	$default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color ?> />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
</fieldset></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
<?php wp_nonce_field('custom-background'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
<?php submit_button( null, 'primary', 'save-background-options' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	 * Handle an Image upload for the background image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	public function handle_upload() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		if ( empty($_FILES) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		$overrides = array('test_form' => false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		$uploaded_file = $_FILES['import'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		$file = wp_handle_upload($uploaded_file, $overrides);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		if ( isset($file['error']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			wp_die( $file['error'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		$url = $file['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		$type = $file['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		$file = $file['file'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		$filename = basename($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		// Construct the object array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		$object = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			'post_title' => $filename,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			'post_content' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			'guid' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			'context' => 'custom-background'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		// Save the data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		$id = wp_insert_attachment($object, $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
		// Add the meta-data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
		update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
		set_theme_mod('background_image', esc_url_raw($url));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		set_theme_mod('background_image_thumb', esc_url_raw( $thumbnail[0] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
		/** This action is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
		do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	 * AJAX handler for adding custom background context to an attachment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	 * Triggered when the user adds a new background image from the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	 * Media Manager.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
	public function ajax_background_add() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
		check_ajax_referer( 'background-add', 'nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
		if ( ! current_user_can( 'edit_theme_options' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
		$attachment_id = absint( $_POST['attachment_id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
		if ( $attachment_id < 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
		update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
		wp_send_json_success();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
	 * @deprecated 3.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
	public function attachment_fields_to_edit( $form_fields ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
	 * @deprecated 3.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
	public function filter_upload_tabs( $tabs ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
	 * @deprecated 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	public function wp_set_background_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		$attachment_id = absint($_POST['attachment_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		/** This filter is documented in wp-admin/includes/media.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		$sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		$size = 'thumbnail';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		if ( in_array( $_POST['size'], $sizes ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			$size = esc_attr( $_POST['size'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		$url = wp_get_attachment_image_src( $attachment_id, $size );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		$thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
		set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
}