128 $this->updated = true; |
128 $this->updated = true; |
129 wp_safe_redirect( $_POST['_wp_http_referer'] ); |
129 wp_safe_redirect( $_POST['_wp_http_referer'] ); |
130 return; |
130 return; |
131 } |
131 } |
132 |
132 |
133 if ( isset($_POST['background-repeat']) ) { |
133 if ( isset( $_POST['background-preset'] ) ) { |
134 check_admin_referer('custom-background'); |
134 check_admin_referer( 'custom-background' ); |
135 if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) ) |
135 |
136 $repeat = $_POST['background-repeat']; |
136 if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { |
137 else |
137 $preset = $_POST['background-preset']; |
|
138 } else { |
|
139 $preset = 'default'; |
|
140 } |
|
141 |
|
142 set_theme_mod( 'background_preset', $preset ); |
|
143 } |
|
144 |
|
145 if ( isset( $_POST['background-position'] ) ) { |
|
146 check_admin_referer( 'custom-background' ); |
|
147 |
|
148 $position = explode( ' ', $_POST['background-position'] ); |
|
149 |
|
150 if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { |
|
151 $position_x = $position[0]; |
|
152 } else { |
|
153 $position_x = 'left'; |
|
154 } |
|
155 |
|
156 if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { |
|
157 $position_y = $position[1]; |
|
158 } else { |
|
159 $position_y = 'top'; |
|
160 } |
|
161 |
|
162 set_theme_mod( 'background_position_x', $position_x ); |
|
163 set_theme_mod( 'background_position_y', $position_y ); |
|
164 } |
|
165 |
|
166 if ( isset( $_POST['background-size'] ) ) { |
|
167 check_admin_referer( 'custom-background' ); |
|
168 |
|
169 if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { |
|
170 $size = $_POST['background-size']; |
|
171 } else { |
|
172 $size = 'auto'; |
|
173 } |
|
174 |
|
175 set_theme_mod( 'background_size', $size ); |
|
176 } |
|
177 |
|
178 if ( isset( $_POST['background-repeat'] ) ) { |
|
179 check_admin_referer( 'custom-background' ); |
|
180 |
|
181 $repeat = $_POST['background-repeat']; |
|
182 |
|
183 if ( 'no-repeat' !== $repeat ) { |
138 $repeat = 'repeat'; |
184 $repeat = 'repeat'; |
139 set_theme_mod('background_repeat', $repeat); |
185 } |
140 } |
186 |
141 |
187 set_theme_mod( 'background_repeat', $repeat ); |
142 if ( isset($_POST['background-position-x']) ) { |
188 } |
143 check_admin_referer('custom-background'); |
189 |
144 if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) ) |
190 if ( isset( $_POST['background-attachment'] ) ) { |
145 $position = $_POST['background-position-x']; |
191 check_admin_referer( 'custom-background' ); |
146 else |
192 |
147 $position = 'left'; |
193 $attachment = $_POST['background-attachment']; |
148 set_theme_mod('background_position_x', $position); |
194 |
149 } |
195 if ( 'fixed' !== $attachment ) { |
150 |
196 $attachment = 'scroll'; |
151 if ( isset($_POST['background-attachment']) ) { |
197 } |
152 check_admin_referer('custom-background'); |
198 |
153 if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) ) |
199 set_theme_mod( 'background_attachment', $attachment ); |
154 $attachment = $_POST['background-attachment']; |
|
155 else |
|
156 $attachment = 'fixed'; |
|
157 set_theme_mod('background_attachment', $attachment); |
|
158 } |
200 } |
159 |
201 |
160 if ( isset($_POST['background-color']) ) { |
202 if ( isset($_POST['background-color']) ) { |
161 check_admin_referer('custom-background'); |
203 check_admin_referer('custom-background'); |
162 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); |
204 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); |
214 $background_styles .= 'background-color: #' . $bgcolor . ';'; |
256 $background_styles .= 'background-color: #' . $bgcolor . ';'; |
215 |
257 |
216 $background_image_thumb = get_background_image(); |
258 $background_image_thumb = get_background_image(); |
217 if ( $background_image_thumb ) { |
259 if ( $background_image_thumb ) { |
218 $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); |
260 $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); |
|
261 $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
|
262 $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); |
|
263 $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); |
|
264 $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
|
265 $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
219 |
266 |
220 // Background-image URL must be single quote, see below. |
267 // Background-image URL must be single quote, see below. |
221 $background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');' |
268 $background_styles .= " background-image: url('$background_image_thumb');" |
222 . ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';' |
269 . " background-size: $background_size;" |
223 . ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
270 . " background-position: $background_position_x $background_position_y;" |
|
271 . " background-repeat: $background_repeat;" |
|
272 . " background-attachment: $background_attachment;"; |
224 } |
273 } |
225 ?> |
274 ?> |
226 <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> |
275 <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> |
227 <?php if ( $background_image_thumb ) { ?> |
276 <?php if ( $background_image_thumb ) { ?> |
228 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br /> |
277 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br /> |
251 <tr> |
300 <tr> |
252 <th scope="row"><?php _e('Restore Original Image'); ?></th> |
301 <th scope="row"><?php _e('Restore Original Image'); ?></th> |
253 <td> |
302 <td> |
254 <form method="post"> |
303 <form method="post"> |
255 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> |
304 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> |
256 <?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/> |
305 <?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/> |
257 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?> |
306 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?> |
258 </form> |
307 </form> |
259 </td> |
308 </td> |
260 </tr> |
309 </tr> |
261 <?php endif; ?> |
310 <?php endif; ?> |
262 |
311 |
|
312 <?php if ( current_user_can( 'upload_files' ) ): ?> |
263 <tr> |
313 <tr> |
264 <th scope="row"><?php _e('Select Image'); ?></th> |
314 <th scope="row"><?php _e('Select Image'); ?></th> |
265 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post"> |
315 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post"> |
266 <p> |
316 <p> |
267 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
317 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
268 <input type="file" id="upload" name="import" /> |
318 <input type="file" id="upload" name="import" /> |
269 <input type="hidden" name="action" value="save" /> |
319 <input type="hidden" name="action" value="save" /> |
270 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> |
320 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> |
271 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> |
321 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> |
272 </p> |
322 </p> |
273 <p> |
323 <p> |
274 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
324 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
275 <button id="choose-from-library-link" class="button" |
325 <button id="choose-from-library-link" class="button" |
276 data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>" |
326 data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>" |
277 data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></button> |
327 data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></button> |
278 </p> |
328 </p> |
279 </form> |
329 </form> |
280 </td> |
330 </td> |
281 </tr> |
331 </tr> |
|
332 <?php endif; ?> |
282 </tbody> |
333 </tbody> |
283 </table> |
334 </table> |
284 |
335 |
285 <h3><?php _e('Display Options') ?></h3> |
336 <h3><?php _e( 'Display Options' ); ?></h3> |
286 <form method="post"> |
337 <form method="post"> |
287 <table class="form-table"> |
338 <table class="form-table"> |
288 <tbody> |
339 <tbody> |
289 <?php if ( get_background_image() ) : ?> |
340 <?php if ( get_background_image() ) : ?> |
290 <tr> |
341 <input name="background-preset" type="hidden" value="custom"> |
291 <th scope="row"><?php _e( 'Position' ); ?></th> |
342 |
292 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend> |
343 <?php |
293 <label> |
344 $background_position = sprintf( |
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' ) ) ); ?> /> |
345 '%s %s', |
295 <?php _e('Left') ?> |
346 get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ), |
296 </label> |
347 get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ) |
297 <label> |
348 ); |
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' ) ) ); ?> /> |
349 |
299 <?php _e('Center') ?> |
350 $background_position_options = array( |
300 </label> |
351 array( |
301 <label> |
352 'left top' => array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
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' ) ) ); ?> /> |
353 'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt' ), |
303 <?php _e('Right') ?> |
354 'right top' => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
304 </label> |
355 ), |
|
356 array( |
|
357 'left center' => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
|
358 'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon' ), |
|
359 'right center' => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
|
360 ), |
|
361 array( |
|
362 'left bottom' => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
|
363 'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt' ), |
|
364 'right bottom' => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
|
365 ), |
|
366 ); |
|
367 ?> |
|
368 <tr> |
|
369 <th scope="row"><?php _e( 'Image Position' ); ?></th> |
|
370 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> |
|
371 <div class="background-position-control"> |
|
372 <?php foreach ( $background_position_options as $group ) : ?> |
|
373 <div class="button-group"> |
|
374 <?php foreach ( $group as $value => $input ) : ?> |
|
375 <label> |
|
376 <input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>> |
|
377 <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span> |
|
378 <span class="screen-reader-text"><?php echo $input['label']; ?></span> |
|
379 </label> |
|
380 <?php endforeach; ?> |
|
381 </div> |
|
382 <?php endforeach; ?> |
|
383 </div> |
305 </fieldset></td> |
384 </fieldset></td> |
306 </tr> |
385 </tr> |
307 |
386 |
308 <tr> |
387 <tr> |
309 <th scope="row"><?php _e( 'Repeat' ); ?></th> |
388 <th scope="row"><label for="background-size"><?php _e( 'Image Size' ); ?></label></th> |
310 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend> |
389 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Size' ); ?></span></legend> |
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> |
390 <select id="background-size" name="background-size"> |
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> |
391 <option value="auto"<?php selected( 'auto', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _ex( 'Original', 'Original Size' ); ?></option> |
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> |
392 <option value="contain"<?php selected( 'contain', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fit to Screen' ); ?></option> |
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> |
393 <option value="cover"<?php selected( 'cover', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fill Screen' ); ?></option> |
|
394 </select> |
315 </fieldset></td> |
395 </fieldset></td> |
316 </tr> |
396 </tr> |
317 |
397 |
318 <tr> |
398 <tr> |
319 <th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th> |
399 <th scope="row"><?php _ex( 'Repeat', 'Background Repeat' ); ?></th> |
320 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend> |
400 <td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Repeat', 'Background Repeat' ); ?></span></legend> |
321 <label> |
401 <input name="background-repeat" type="hidden" value="no-repeat"> |
322 <input name="background-attachment" type="radio" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> /> |
402 <label><input type="checkbox" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?>> <?php _e( 'Repeat Background Image' ); ?></label> |
323 <?php _e( 'Scroll' ); ?> |
403 </fieldset></td> |
324 </label> |
404 </tr> |
325 <label> |
405 |
326 <input name="background-attachment" type="radio" value="fixed" <?php checked( 'fixed', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> /> |
406 <tr> |
327 <?php _e( 'Fixed' ); ?> |
407 <th scope="row"><?php _ex( 'Scroll', 'Background Scroll' ); ?></th> |
328 </label> |
408 <td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Scroll', 'Background Scroll' ); ?></span></legend> |
|
409 <input name="background-attachment" type="hidden" value="fixed"> |
|
410 <label><input name="background-attachment" type="checkbox" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?>> <?php _e( 'Scroll with Page' ); ?></label> |
329 </fieldset></td> |
411 </fieldset></td> |
330 </tr> |
412 </tr> |
331 <?php endif; // get_background_image() ?> |
413 <?php endif; // get_background_image() ?> |
332 <tr> |
414 <tr> |
333 <th scope="row"><?php _e( 'Background Color' ); ?></th> |
415 <th scope="row"><?php _e( 'Background Color' ); ?></th> |