71 |
71 |
72 add_action("load-$page", array(&$this, 'admin_load')); |
72 add_action("load-$page", array(&$this, 'admin_load')); |
73 add_action("load-$page", array(&$this, 'take_action'), 49); |
73 add_action("load-$page", array(&$this, 'take_action'), 49); |
74 add_action("load-$page", array(&$this, 'handle_upload'), 49); |
74 add_action("load-$page", array(&$this, 'handle_upload'), 49); |
75 |
75 |
76 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { |
|
77 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); |
|
78 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); |
|
79 add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); |
|
80 } |
|
81 |
|
82 if ( $this->admin_header_callback ) |
76 if ( $this->admin_header_callback ) |
83 add_action("admin_head-$page", $this->admin_header_callback, 51); |
77 add_action("admin_head-$page", $this->admin_header_callback, 51); |
84 } |
78 } |
85 |
79 |
86 /** |
80 /** |
92 get_current_screen()->add_help_tab( array( |
86 get_current_screen()->add_help_tab( array( |
93 'id' => 'overview', |
87 'id' => 'overview', |
94 'title' => __('Overview'), |
88 'title' => __('Overview'), |
95 'content' => |
89 'content' => |
96 '<p>' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . |
90 '<p>' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . |
97 '<p>' . __( 'To use a background image, simply upload it, then choose your display options below. 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>' . |
91 '<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 “Choose Image” 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>' . |
98 '<p>' . __( 'You can also choose a background color. If you know the hexadecimal code for the color you want, enter it in the Background Color field. If not, click on the Select a Color link, and a color picker will allow you to choose the exact shade you want.' ) . '</p>' . |
92 '<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. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
99 '<p>' . __( 'Don’t forget to click on the Save Changes button when you are finished.' ) . '</p>' |
93 '<p>' . __( 'Don’t forget to click on the Save Changes button when you are finished.' ) . '</p>' |
100 ) ); |
94 ) ); |
101 |
95 |
102 get_current_screen()->set_help_sidebar( |
96 get_current_screen()->set_help_sidebar( |
103 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
97 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
104 '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' . |
98 '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' . |
105 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' |
99 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' |
106 ); |
100 ); |
107 |
101 |
108 add_thickbox(); |
102 wp_enqueue_media(); |
109 wp_enqueue_script('media-upload'); |
|
110 wp_enqueue_script('custom-background'); |
103 wp_enqueue_script('custom-background'); |
111 wp_enqueue_style('farbtastic'); |
104 wp_enqueue_style('wp-color-picker'); |
112 } |
105 } |
113 |
106 |
114 /** |
107 /** |
115 * Execute custom background modification. |
108 * Execute custom background modification. |
116 * |
109 * |
252 </tr> |
245 </tr> |
253 |
246 |
254 <?php endif; ?> |
247 <?php endif; ?> |
255 <tr valign="top"> |
248 <tr valign="top"> |
256 <th scope="row"><?php _e('Select Image'); ?></th> |
249 <th scope="row"><?php _e('Select Image'); ?></th> |
257 <td><form enctype="multipart/form-data" id="upload-form" method="post" action=""> |
250 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action=""> |
258 <p> |
251 <p> |
259 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
252 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
260 <input type="file" id="upload" name="import" /> |
253 <input type="file" id="upload" name="import" /> |
261 <input type="hidden" name="action" value="save" /> |
254 <input type="hidden" name="action" value="save" /> |
262 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> |
255 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> |
263 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> |
256 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> |
264 </p> |
257 </p> |
265 <?php |
|
266 $image_library_url = get_upload_iframe_src( 'image', null, 'library' ); |
|
267 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); |
|
268 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); |
|
269 ?> |
|
270 <p> |
258 <p> |
271 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
259 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
272 <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a> |
260 <a id="choose-from-library-link" class="button" |
|
261 data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>" |
|
262 data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></a> |
273 </p> |
263 </p> |
274 </form> |
264 </form> |
275 </td> |
265 </td> |
276 </tr> |
266 </tr> |
277 </tbody> |
267 </tbody> |
325 </tr> |
315 </tr> |
326 <?php endif; // get_background_image() ?> |
316 <?php endif; // get_background_image() ?> |
327 <tr valign="top"> |
317 <tr valign="top"> |
328 <th scope="row"><?php _e( 'Background Color' ); ?></th> |
318 <th scope="row"><?php _e( 'Background Color' ); ?></th> |
329 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
319 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
330 <?php $show_clear = get_theme_mod('background_color') ? '' : ' style="display:none"'; ?> |
320 <?php |
331 <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> |
321 $default_color = ''; |
332 <a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php current_theme_supports( 'custom-background', 'default-color' ) ? _e( 'Default' ) : _e( 'Clear' ); ?></a>)</span> |
322 if ( current_theme_supports( 'custom-background', 'default-color' ) ) |
333 <input type="hidden" id="defaultcolor" value="<?php if ( current_theme_supports( 'custom-background', 'default-color' ) ) echo '#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ); ?>" /> |
323 $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; |
334 <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> |
324 ?> |
|
325 <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color ?> /> |
335 </fieldset></td> |
326 </fieldset></td> |
336 </tr> |
327 </tr> |
337 </tbody> |
328 </tbody> |
338 </table> |
329 </table> |
339 |
330 |
355 if ( empty($_FILES) ) |
346 if ( empty($_FILES) ) |
356 return; |
347 return; |
357 |
348 |
358 check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); |
349 check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); |
359 $overrides = array('test_form' => false); |
350 $overrides = array('test_form' => false); |
360 $file = wp_handle_upload($_FILES['import'], $overrides); |
351 |
|
352 $uploaded_file = $_FILES['import']; |
|
353 $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false ); |
|
354 if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) |
|
355 wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
356 |
|
357 $file = wp_handle_upload($uploaded_file, $overrides); |
361 |
358 |
362 if ( isset($file['error']) ) |
359 if ( isset($file['error']) ) |
363 wp_die( $file['error'] ); |
360 wp_die( $file['error'] ); |
364 |
361 |
365 $url = $file['url']; |
362 $url = $file['url']; |
391 do_action('wp_create_file_in_uploads', $file, $id); // For replication |
388 do_action('wp_create_file_in_uploads', $file, $id); // For replication |
392 $this->updated = true; |
389 $this->updated = true; |
393 } |
390 } |
394 |
391 |
395 /** |
392 /** |
396 * Replace default attachment actions with "Set as background" link. |
393 * Unused since 3.5.0. |
397 * |
394 * |
398 * @since 3.4.0 |
395 * @since 3.4.0 |
399 */ |
396 */ |
400 function attachment_fields_to_edit( $form_fields, $post ) { |
397 function attachment_fields_to_edit( $form_fields ) { |
401 $form_fields = array( 'image-size' => $form_fields['image-size'] ); |
|
402 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-attachment-id="' . $post->ID . '" class="wp-set-background">' . __( 'Set as background' ) . '</a></td></tr>' ); |
|
403 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); |
|
404 |
|
405 return $form_fields; |
398 return $form_fields; |
406 } |
399 } |
407 |
400 |
408 /** |
401 /** |
409 * Leave only "Media Library" tab in the uploader window. |
402 * Unused since 3.5.0. |
410 * |
403 * |
411 * @since 3.4.0 |
404 * @since 3.4.0 |
412 */ |
405 */ |
413 function filter_upload_tabs() { |
406 function filter_upload_tabs( $tabs ) { |
414 return array( 'library' => __('Media Library') ); |
407 return $tabs; |
415 } |
408 } |
416 |
409 |
417 public function wp_set_background_image() { |
410 public function wp_set_background_image() { |
418 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; |
411 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; |
419 $attachment_id = absint($_POST['attachment_id']); |
412 $attachment_id = absint($_POST['attachment_id']); |