Changeset 20358 for trunk/wp-admin/custom-background.php
- Timestamp:
- 04/05/2012 12:20:28 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-background.php
r20212 r20358 56 56 57 57 add_action( 'admin_menu', array( $this, 'init' ) ); 58 add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); 58 59 } 59 60 … … 72 73 add_action("load-$page", array(&$this, 'take_action'), 49); 73 74 add_action("load-$page", array(&$this, 'handle_upload'), 49); 75 add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 76 add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 74 77 75 78 if ( $this->admin_header_callback ) … … 99 102 ); 100 103 104 add_thickbox(); 105 wp_enqueue_script('media-upload'); 101 106 wp_enqueue_script('custom-background'); 102 107 wp_enqueue_style('farbtastic'); … … 127 132 set_theme_mod('background_image_thumb', ''); 128 133 $this->updated = true; 134 wp_safe_redirect( $_POST['_wp_http_referer'] ); 129 135 return; 130 136 } … … 249 255 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 250 256 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 251 </form> 257 <?php 258 $image_library_url = get_upload_iframe_src( 'image', null, 'library' ); 259 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url ); 260 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); 261 ?> 262 </form> 263 <span class="howto"><?php _ex( 'or', 'Custom Background: Choose an image from your computer - or - Choose from image library' ); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 252 264 </td> 253 265 </tr> … … 369 381 } 370 382 383 function attachment_fields_to_edit( $form_fields, $post ) { 384 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 385 $form_fields = array( 'image-size' => $form_fields['image-size'] ); 386 $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>' ); 387 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 388 } 389 390 return $form_fields; 391 } 392 393 function filter_upload_tabs ( $tabs ){ 394 if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 395 return array( 'library' => __('Media Library') ); 396 397 return $tabs; 398 } 399 400 public function wp_set_background_image() { 401 if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; 402 $attachment_id = absint($_POST['attachment_id']); 403 $sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); 404 $size = 'thumbnail'; 405 if ( in_array( $_POST['size'], $sizes ) ) 406 $size = esc_attr( $_POST['size'] ); 407 408 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 409 $url = wp_get_attachment_image_src( $attachment_id, $size ); 410 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 411 set_theme_mod( 'background_image', esc_url( $url[0] ) ); 412 set_theme_mod( 'background_image_thumb', esc_url( $thumbnail[0] ) ); 413 exit; 414 } 371 415 }
Note: See TracChangeset
for help on using the changeset viewer.