Message info
 
To:wp-svn@lists.automattic.com From:m@wordpress.org Subject:[wp-svn] [21009] trunk/wp-admin: Check context before adding media upload filters. Date:Wed, 6 Jun 2012 16:48:53 +0000 (UTC)
 

Revision
21009
Author
ryan
Date
2012-06-06 16:48:53 +0000 (Wed, 06 Jun 2012)

Log Message

Check context before adding media upload filters. Props SergeyBiryukov. fixes #20819

Modified Paths

Diff

Modified: trunk/wp-admin/custom-background.php (21008 => 21009)


--- trunk/wp-admin/custom-background.php	2012-06-06 16:00:08 UTC (rev 21008)
+++ trunk/wp-admin/custom-background.php	2012-06-06 16:48:53 UTC (rev 21009)
@@ -72,9 +72,13 @@
 		add_action("load-$page", array(&$this, 'admin_load'));
 		add_action("load-$page", array(&$this, 'take_action'), 49);
 		add_action("load-$page", array(&$this, 'handle_upload'), 49);
-		add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
-		add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
 
+		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) {
+			add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
+			add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
+			add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
+		}
+
 		if ( $this->admin_header_callback )
 			add_action("admin_head-$page", $this->admin_header_callback, 51);
 	}
@@ -388,21 +392,26 @@
 		$this->updated = true;
 	}
 
+	/**
+	 * Replace default attachment actions with "Set as background" link.
+	 *
+	 * @since 3.4.0
+	 */
 	function attachment_fields_to_edit( $form_fields, $post ) {
-		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) {
-			$form_fields = array( 'image-size' => $form_fields['image-size'] );
-			$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>' );
-			$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' );
-		}
+		$form_fields = array( 'image-size' => $form_fields['image-size'] );
+		$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>' );
+		$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' );
 
 		return $form_fields;
 	}
 
-	function filter_upload_tabs ( $tabs ){
-		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' )
-			return array( 'library' => __('Media Library') );
-
-		return $tabs;
+	/**
+	 * Leave only "Media Library" tab in the uploader window.
+	 *
+	 * @since 3.4.0
+	 */
+	function filter_upload_tabs() {
+		return array( 'library' => __('Media Library') );
 	}
 
 	public function wp_set_background_image() {

Modified: trunk/wp-admin/custom-header.php (21008 => 21009)


--- trunk/wp-admin/custom-header.php	2012-06-06 16:00:08 UTC (rev 21008)
+++ trunk/wp-admin/custom-header.php	2012-06-06 16:48:53 UTC (rev 21009)
@@ -94,9 +94,11 @@
 		if ( $this->admin_header_callback )
 			add_action("admin_head-$page", $this->admin_header_callback, 51);
 
-		add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
-		add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
-		add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
+		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) {
+			add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
+			add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
+			add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
+		}
 	}
 
 	/**
@@ -972,18 +974,16 @@
 	 * @since 3.4.0
 	 */
 	function attachment_fields_to_edit( $form_fields, $post ) {
-		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) {
-			$form_fields = array();
-			$href = esc_url(add_query_arg(array(
-				'page' => 'custom-header',
-				'step' => 2,
-				'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
-				'file' => $post->ID
-			), admin_url('themes.php')));
+		$form_fields = array();
+		$href = esc_url(add_query_arg(array(
+			'page' => 'custom-header',
+			'step' => 2,
+			'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
+			'file' => $post->ID
+		), admin_url('themes.php')));
 
-			$form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' );
-			$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' );
-		}
+		$form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' );
+		$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' );
 
 		return $form_fields;
 	}
@@ -993,11 +993,8 @@
 	 *
 	 * @since 3.4.0
 	 */
-	function filter_upload_tabs( $tabs ) {
-		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' )
-			return array( 'library' => __('Media Library') );
-
-		return $tabs;
+	function filter_upload_tabs() {
+		return array( 'library' => __('Media Library') );
 	}
 
 }