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 ) { |
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 |
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’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’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’s name displays a simple screen to edit that individual file’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’s name displays a simple screen to edit that individual file’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( |
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 } |