wp/wp-admin/upload.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once __DIR__ . '/admin.php';
    11 
    11 
    12 if ( ! current_user_can( 'upload_files' ) ) {
    12 if ( ! current_user_can( 'upload_files' ) ) {
    13 	wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
    13 	wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
    14 }
    14 }
    15 
    15 
    16 $mode  = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
    16 $mode  = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
    17 $modes = array( 'grid', 'list' );
    17 $modes = array( 'grid', 'list' );
    18 
    18 
    19 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes ) ) {
    19 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes, true ) ) {
    20 	$mode = $_GET['mode'];
    20 	$mode = $_GET['mode'];
    21 	update_user_option( get_current_user_id(), 'media_library_mode', $mode );
    21 	update_user_option( get_current_user_id(), 'media_library_mode', $mode );
    22 }
    22 }
    23 
    23 
    24 if ( 'grid' === $mode ) {
    24 if ( 'grid' === $mode ) {
    27 	wp_enqueue_script( 'media' );
    27 	wp_enqueue_script( 'media' );
    28 
    28 
    29 	remove_action( 'admin_head', 'wp_admin_canonical_url' );
    29 	remove_action( 'admin_head', 'wp_admin_canonical_url' );
    30 
    30 
    31 	$q = $_GET;
    31 	$q = $_GET;
    32 	// let JS handle this
    32 	// Let JS handle this.
    33 	unset( $q['s'] );
    33 	unset( $q['s'] );
    34 	$vars   = wp_edit_attachments_query_vars( $q );
    34 	$vars   = wp_edit_attachments_query_vars( $q );
    35 	$ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
    35 	$ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
    36 	foreach ( $vars as $key => $value ) {
    36 	foreach ( $vars as $key => $value ) {
    37 		if ( ! $value || in_array( $key, $ignore ) ) {
    37 		if ( ! $value || in_array( $key, $ignore, true ) ) {
    38 			unset( $vars[ $key ] );
    38 			unset( $vars[ $key ] );
    39 		}
    39 		}
    40 	}
    40 	}
    41 
    41 
    42 	wp_localize_script(
    42 	wp_localize_script(
    70 		)
    70 		)
    71 	);
    71 	);
    72 
    72 
    73 	get_current_screen()->set_help_sidebar(
    73 	get_current_screen()->set_help_sidebar(
    74 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    74 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    75 		'<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen">Documentation on Media Library</a>' ) . '</p>' .
    75 		'<p>' . __( '<a href="https://wordpress.org/support/article/media-library-screen/">Documentation on Media Library</a>' ) . '</p>' .
    76 		'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    76 		'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    77 	);
    77 	);
    78 
    78 
    79 	$title       = __( 'Media Library' );
    79 	$title       = __( 'Media Library' );
    80 	$parent_file = 'upload.php';
    80 	$parent_file = 'upload.php';
    81 
    81 
    82 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
    82 	require_once ABSPATH . 'wp-admin/admin-header.php';
    83 	?>
    83 	?>
    84 	<div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query(); ?>">
    84 	<div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query(); ?>">
    85 		<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
    85 		<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
    86 
    86 
    87 		<?php
    87 		<?php
    96 
    96 
    97 		<div class="error hide-if-js">
    97 		<div class="error hide-if-js">
    98 			<p>
    98 			<p>
    99 			<?php
    99 			<?php
   100 			printf(
   100 			printf(
   101 				/* translators: %s: list view URL */
   101 				/* translators: %s: List view URL. */
   102 				__( 'The grid view for the Media Library requires JavaScript. <a href="%s">Switch to the list view</a>.' ),
   102 				__( 'The grid view for the Media Library requires JavaScript. <a href="%s">Switch to the list view</a>.' ),
   103 				'upload.php?mode=list'
   103 				'upload.php?mode=list'
   104 			);
   104 			);
   105 			?>
   105 			?>
   106 			</p>
   106 			</p>
   107 		</div>
   107 		</div>
   108 	</div>
   108 	</div>
   109 	<?php
   109 	<?php
   110 	include( ABSPATH . 'wp-admin/admin-footer.php' );
   110 	require_once ABSPATH . 'wp-admin/admin-footer.php';
   111 	exit;
   111 	exit;
   112 }
   112 }
   113 
   113 
   114 $wp_list_table = _get_list_table( 'WP_Media_List_Table' );
   114 $wp_list_table = _get_list_table( 'WP_Media_List_Table' );
   115 $pagenum       = $wp_list_table->get_pagenum();
   115 $pagenum       = $wp_list_table->get_pagenum();
   116 
   116 
   117 // Handle bulk actions
   117 // Handle bulk actions.
   118 $doaction = $wp_list_table->current_action();
   118 $doaction = $wp_list_table->current_action();
   119 
   119 
   120 if ( $doaction ) {
   120 if ( $doaction ) {
   121 	check_admin_referer( 'bulk-media' );
   121 	check_admin_referer( 'bulk-media' );
   122 
   122 
   123 	if ( 'delete_all' == $doaction ) {
   123 	if ( 'delete_all' === $doaction ) {
   124 		$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
   124 		$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
   125 		$doaction = 'delete';
   125 		$doaction = 'delete';
   126 	} elseif ( isset( $_REQUEST['media'] ) ) {
   126 	} elseif ( isset( $_REQUEST['media'] ) ) {
   127 		$post_ids = $_REQUEST['media'];
   127 		$post_ids = $_REQUEST['media'];
   128 	} elseif ( isset( $_REQUEST['ids'] ) ) {
   128 	} elseif ( isset( $_REQUEST['ids'] ) ) {
   129 		$post_ids = explode( ',', $_REQUEST['ids'] );
   129 		$post_ids = explode( ',', $_REQUEST['ids'] );
   130 	}
   130 	}
   131 
   131 
   132 	$location = 'upload.php';
   132 	$location = 'upload.php';
   133 	if ( $referer = wp_get_referer() ) {
   133 	$referer  = wp_get_referer();
       
   134 	if ( $referer ) {
   134 		if ( false !== strpos( $referer, 'upload.php' ) ) {
   135 		if ( false !== strpos( $referer, 'upload.php' ) ) {
   135 			$location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
   136 			$location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
   136 		}
   137 		}
   137 	}
   138 	}
   138 
   139 
   153 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   154 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   154 					wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
   155 					wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
   155 				}
   156 				}
   156 
   157 
   157 				if ( ! wp_trash_post( $post_id ) ) {
   158 				if ( ! wp_trash_post( $post_id ) ) {
   158 					wp_die( __( 'Error in moving to Trash.' ) );
   159 					wp_die( __( 'Error in moving the item to Trash.' ) );
   159 				}
   160 				}
   160 			}
   161 			}
   161 			$location = add_query_arg(
   162 			$location = add_query_arg(
   162 				array(
   163 				array(
   163 					'trashed' => count( $post_ids ),
   164 					'trashed' => count( $post_ids ),
   174 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   175 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   175 					wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
   176 					wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
   176 				}
   177 				}
   177 
   178 
   178 				if ( ! wp_untrash_post( $post_id ) ) {
   179 				if ( ! wp_untrash_post( $post_id ) ) {
   179 					wp_die( __( 'Error in restoring from Trash.' ) );
   180 					wp_die( __( 'Error in restoring the item from Trash.' ) );
   180 				}
   181 				}
   181 			}
   182 			}
   182 			$location = add_query_arg( 'untrashed', count( $post_ids ), $location );
   183 			$location = add_query_arg( 'untrashed', count( $post_ids ), $location );
   183 			break;
   184 			break;
   184 		case 'delete':
   185 		case 'delete':
   189 				if ( ! current_user_can( 'delete_post', $post_id_del ) ) {
   190 				if ( ! current_user_can( 'delete_post', $post_id_del ) ) {
   190 					wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
   191 					wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
   191 				}
   192 				}
   192 
   193 
   193 				if ( ! wp_delete_attachment( $post_id_del ) ) {
   194 				if ( ! wp_delete_attachment( $post_id_del ) ) {
   194 					wp_die( __( 'Error in deleting.' ) );
   195 					wp_die( __( 'Error in deleting the attachment.' ) );
   195 				}
   196 				}
   196 			}
   197 			}
   197 			$location = add_query_arg( 'deleted', count( $post_ids ), $location );
   198 			$location = add_query_arg( 'deleted', count( $post_ids ), $location );
   198 			break;
   199 			break;
   199 		default:
   200 		default:
   200 			/** This action is documented in wp-admin/edit-comments.php */
   201 			$screen = get_current_screen()->id;
   201 			$location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $doaction, $post_ids );
   202 
       
   203 			/** This action is documented in wp-admin/edit.php */
       
   204 			$location = apply_filters( "handle_bulk_actions-{$screen}", $location, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
   202 	}
   205 	}
   203 
   206 
   204 	wp_redirect( $location );
   207 	wp_redirect( $location );
   205 	exit;
   208 	exit;
   206 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
   209 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
   220 get_current_screen()->add_help_tab(
   223 get_current_screen()->add_help_tab(
   221 	array(
   224 	array(
   222 		'id'      => 'overview',
   225 		'id'      => 'overview',
   223 		'title'   => __( 'Overview' ),
   226 		'title'   => __( 'Overview' ),
   224 		'content' =>
   227 		'content' =>
   225 				 '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first. You can use the Screen Options tab to customize the display of this screen.' ) . '</p>' .
   228 				'<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first. You can use the Screen Options tab to customize the display of this screen.' ) . '</p>' .
   226 				 '<p>' . __( 'You can narrow the list by file type/status or by date using the dropdown menus above the media table.' ) . '</p>' .
   229 				'<p>' . __( 'You can narrow the list by file type/status or by date using the dropdown menus above the media table.' ) . '</p>' .
   227 				 '<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>',
   230 				'<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>',
   228 	)
   231 	)
   229 );
   232 );
   230 get_current_screen()->add_help_tab(
   233 get_current_screen()->add_help_tab(
   231 	array(
   234 	array(
   232 		'id'      => 'actions-links',
   235 		'id'      => 'actions-links',
   233 		'title'   => __( 'Available Actions' ),
   236 		'title'   => __( 'Available Actions' ),
   234 		'content' =>
   237 		'content' =>
   235 				 '<p>' . __( 'Hovering over a row reveals action links: Edit, Delete Permanently, and View. Clicking Edit or on the media file&#8217;s name displays a simple screen to edit that individual file&#8217;s metadata. Clicking Delete Permanently will delete the file from the media library (as well as from any posts to which it is currently attached). View will take you to the display page for that file.' ) . '</p>',
   238 				'<p>' . __( 'Hovering over a row reveals action links: Edit, Delete Permanently, and View. Clicking Edit or on the media file&#8217;s name displays a simple screen to edit that individual file&#8217;s metadata. Clicking Delete Permanently will delete the file from the media library (as well as from any posts to which it is currently attached). View will take you to the display page for that file.' ) . '</p>',
   236 	)
   239 	)
   237 );
   240 );
   238 get_current_screen()->add_help_tab(
   241 get_current_screen()->add_help_tab(
   239 	array(
   242 	array(
   240 		'id'      => 'attaching-files',
   243 		'id'      => 'attaching-files',
   241 		'title'   => __( 'Attaching Files' ),
   244 		'title'   => __( 'Attaching Files' ),
   242 		'content' =>
   245 		'content' =>
   243 				 '<p>' . __( 'If a media file has not been attached to any content, you will see that in the Uploaded To column, and can click on Attach to launch a small popup that will allow you to search for existing content and attach the file.' ) . '</p>',
   246 				'<p>' . __( 'If a media file has not been attached to any content, you will see that in the Uploaded To column, and can click on Attach to launch a small popup that will allow you to search for existing content and attach the file.' ) . '</p>',
   244 	)
   247 	)
   245 );
   248 );
   246 
   249 
   247 get_current_screen()->set_help_sidebar(
   250 get_current_screen()->set_help_sidebar(
   248 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   251 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   249 	'<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen">Documentation on Media Library</a>' ) . '</p>' .
   252 	'<p>' . __( '<a href="https://wordpress.org/support/article/media-library-screen/">Documentation on Media Library</a>' ) . '</p>' .
   250 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   253 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   251 );
   254 );
   252 
   255 
   253 get_current_screen()->set_screen_reader_content(
   256 get_current_screen()->set_screen_reader_content(
   254 	array(
   257 	array(
   256 		'heading_pagination' => __( 'Media items list navigation' ),
   259 		'heading_pagination' => __( 'Media items list navigation' ),
   257 		'heading_list'       => __( 'Media items list' ),
   260 		'heading_list'       => __( 'Media items list' ),
   258 	)
   261 	)
   259 );
   262 );
   260 
   263 
   261 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   264 require_once ABSPATH . 'wp-admin/admin-header.php';
   262 ?>
   265 ?>
   263 
   266 
   264 <div class="wrap">
   267 <div class="wrap">
   265 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   268 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   266 
   269 
   270 	<a href="<?php echo admin_url( 'media-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a>
   273 	<a href="<?php echo admin_url( 'media-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a>
   271 						<?php
   274 						<?php
   272 }
   275 }
   273 
   276 
   274 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
   277 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
   275 	/* translators: %s: search keywords */
   278 	/* translators: %s: Search query. */
   276 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
   279 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
   277 }
   280 }
   278 ?>
   281 ?>
   279 
   282 
   280 <hr class="wp-header-end">
   283 <hr class="wp-header-end">
   284 if ( ! empty( $_GET['posted'] ) ) {
   287 if ( ! empty( $_GET['posted'] ) ) {
   285 	$message                = __( 'Media file updated.' );
   288 	$message                = __( 'Media file updated.' );
   286 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] );
   289 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] );
   287 }
   290 }
   288 
   291 
   289 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
   292 if ( ! empty( $_GET['attached'] ) && absint( $_GET['attached'] ) ) {
       
   293 	$attached = absint( $_GET['attached'] );
   290 	if ( 1 == $attached ) {
   294 	if ( 1 == $attached ) {
   291 		$message = __( 'Media file attached.' );
   295 		$message = __( 'Media file attached.' );
   292 	} else {
   296 	} else {
   293 		/* translators: %s: number of media files */
   297 		/* translators: %s: Number of media files. */
   294 		$message = _n( '%s media file attached.', '%s media files attached.', $attached );
   298 		$message = _n( '%s media file attached.', '%s media files attached.', $attached );
   295 	}
   299 	}
   296 	$message                = sprintf( $message, number_format_i18n( $attached ) );
   300 	$message                = sprintf( $message, number_format_i18n( $attached ) );
   297 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
   301 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
   298 }
   302 }
   299 
   303 
   300 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
   304 if ( ! empty( $_GET['detach'] ) && absint( $_GET['detach'] ) ) {
       
   305 	$detached = absint( $_GET['detach'] );
   301 	if ( 1 == $detached ) {
   306 	if ( 1 == $detached ) {
   302 		$message = __( 'Media file detached.' );
   307 		$message = __( 'Media file detached.' );
   303 	} else {
   308 	} else {
   304 		/* translators: %s: number of media files */
   309 		/* translators: %s: Number of media files. */
   305 		$message = _n( '%s media file detached.', '%s media files detached.', $detached );
   310 		$message = _n( '%s media file detached.', '%s media files detached.', $detached );
   306 	}
   311 	}
   307 	$message                = sprintf( $message, number_format_i18n( $detached ) );
   312 	$message                = sprintf( $message, number_format_i18n( $detached ) );
   308 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
   313 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
   309 }
   314 }
   310 
   315 
   311 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
   316 if ( ! empty( $_GET['deleted'] ) && absint( $_GET['deleted'] ) ) {
       
   317 	$deleted = absint( $_GET['deleted'] );
   312 	if ( 1 == $deleted ) {
   318 	if ( 1 == $deleted ) {
   313 		$message = __( 'Media file permanently deleted.' );
   319 		$message = __( 'Media file permanently deleted.' );
   314 	} else {
   320 	} else {
   315 		/* translators: %s: number of media files */
   321 		/* translators: %s: Number of media files. */
   316 		$message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
   322 		$message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
   317 	}
   323 	}
   318 	$message                = sprintf( $message, number_format_i18n( $deleted ) );
   324 	$message                = sprintf( $message, number_format_i18n( $deleted ) );
   319 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
   325 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
   320 }
   326 }
   321 
   327 
   322 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
   328 if ( ! empty( $_GET['trashed'] ) && absint( $_GET['trashed'] ) ) {
       
   329 	$trashed = absint( $_GET['trashed'] );
   323 	if ( 1 == $trashed ) {
   330 	if ( 1 == $trashed ) {
   324 		$message = __( 'Media file moved to the trash.' );
   331 		$message = __( 'Media file moved to the Trash.' );
   325 	} else {
   332 	} else {
   326 		/* translators: %s: number of media files */
   333 		/* translators: %s: Number of media files. */
   327 		$message = _n( '%s media file moved to the trash.', '%s media files moved to the trash.', $trashed );
   334 		$message = _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed );
   328 	}
   335 	}
   329 	$message                = sprintf( $message, number_format_i18n( $trashed ) );
   336 	$message                = sprintf( $message, number_format_i18n( $trashed ) );
   330 	$message               .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
   337 	$message               .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
   331 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] );
   338 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] );
   332 }
   339 }
   333 
   340 
   334 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
   341 if ( ! empty( $_GET['untrashed'] ) && absint( $_GET['untrashed'] ) ) {
       
   342 	$untrashed = absint( $_GET['untrashed'] );
   335 	if ( 1 == $untrashed ) {
   343 	if ( 1 == $untrashed ) {
   336 		$message = __( 'Media file restored from the trash.' );
   344 		$message = __( 'Media file restored from the Trash.' );
   337 	} else {
   345 	} else {
   338 		/* translators: %s: number of media files */
   346 		/* translators: %s: Number of media files. */
   339 		$message = _n( '%s media file restored from the trash.', '%s media files restored from the trash.', $untrashed );
   347 		$message = _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed );
   340 	}
   348 	}
   341 	$message                = sprintf( $message, number_format_i18n( $untrashed ) );
   349 	$message                = sprintf( $message, number_format_i18n( $untrashed ) );
   342 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] );
   350 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] );
   343 }
   351 }
   344 
   352 
   345 $messages[1] = __( 'Media file updated.' );
   353 $messages[1] = __( 'Media file updated.' );
   346 $messages[2] = __( 'Media file permanently deleted.' );
   354 $messages[2] = __( 'Media file permanently deleted.' );
   347 $messages[3] = __( 'Error saving media file.' );
   355 $messages[3] = __( 'Error saving media file.' );
   348 $messages[4] = __( 'Media file moved to the trash.' ) . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
   356 $messages[4] = __( 'Media file moved to the Trash.' ) . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>';
   349 $messages[5] = __( 'Media file restored from the trash.' );
   357 $messages[5] = __( 'Media file restored from the Trash.' );
   350 
   358 
   351 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
   359 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
   352 	$message                = $messages[ $_GET['message'] ];
   360 	$message                = $messages[ $_GET['message'] ];
   353 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
   361 	$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
   354 }
   362 }
   368 <?php find_posts_div(); ?>
   376 <?php find_posts_div(); ?>
   369 </form>
   377 </form>
   370 </div>
   378 </div>
   371 
   379 
   372 <?php
   380 <?php
   373 include( ABSPATH . 'wp-admin/admin-footer.php' );
   381 require_once ABSPATH . 'wp-admin/admin-footer.php';