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 $message = ''; |
|
17 if ( ! empty( $_GET['posted'] ) ) { |
|
18 $message = __( 'Media file updated.' ); |
|
19 |
|
20 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] ); |
|
21 unset( $_GET['posted'] ); |
|
22 } |
|
23 |
|
24 if ( ! empty( $_GET['attached'] ) && absint( $_GET['attached'] ) ) { |
|
25 $attached = absint( $_GET['attached'] ); |
|
26 |
|
27 if ( 1 === $attached ) { |
|
28 $message = __( 'Media file attached.' ); |
|
29 } else { |
|
30 $message = sprintf( |
|
31 /* translators: %s: Number of media files. */ |
|
32 _n( '%s media file attached.', '%s media files attached.', $attached ), |
|
33 number_format_i18n( $attached ) |
|
34 ); |
|
35 } |
|
36 |
|
37 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] ); |
|
38 unset( $_GET['detach'], $_GET['attached'] ); |
|
39 } |
|
40 |
|
41 if ( ! empty( $_GET['detach'] ) && absint( $_GET['detach'] ) ) { |
|
42 $detached = absint( $_GET['detach'] ); |
|
43 |
|
44 if ( 1 === $detached ) { |
|
45 $message = __( 'Media file detached.' ); |
|
46 } else { |
|
47 $message = sprintf( |
|
48 /* translators: %s: Number of media files. */ |
|
49 _n( '%s media file detached.', '%s media files detached.', $detached ), |
|
50 number_format_i18n( $detached ) |
|
51 ); |
|
52 } |
|
53 |
|
54 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] ); |
|
55 unset( $_GET['detach'], $_GET['attached'] ); |
|
56 } |
|
57 |
|
58 if ( ! empty( $_GET['deleted'] ) && absint( $_GET['deleted'] ) ) { |
|
59 $deleted = absint( $_GET['deleted'] ); |
|
60 |
|
61 if ( 1 === $deleted ) { |
|
62 $message = __( 'Media file permanently deleted.' ); |
|
63 } else { |
|
64 $message = sprintf( |
|
65 /* translators: %s: Number of media files. */ |
|
66 _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted ), |
|
67 number_format_i18n( $deleted ) |
|
68 ); |
|
69 } |
|
70 |
|
71 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] ); |
|
72 unset( $_GET['deleted'] ); |
|
73 } |
|
74 |
|
75 if ( ! empty( $_GET['trashed'] ) && absint( $_GET['trashed'] ) ) { |
|
76 $trashed = absint( $_GET['trashed'] ); |
|
77 |
|
78 if ( 1 === $trashed ) { |
|
79 $message = __( 'Media file moved to the Trash.' ); |
|
80 } else { |
|
81 $message = sprintf( |
|
82 /* translators: %s: Number of media files. */ |
|
83 _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed ), |
|
84 number_format_i18n( $trashed ) |
|
85 ); |
|
86 } |
|
87 |
|
88 $message .= sprintf( |
|
89 ' <a href="%1$s">%2$s</a>', |
|
90 esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ), |
|
91 __( 'Undo' ) |
|
92 ); |
|
93 |
|
94 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] ); |
|
95 unset( $_GET['trashed'] ); |
|
96 } |
|
97 |
|
98 if ( ! empty( $_GET['untrashed'] ) && absint( $_GET['untrashed'] ) ) { |
|
99 $untrashed = absint( $_GET['untrashed'] ); |
|
100 |
|
101 if ( 1 === $untrashed ) { |
|
102 $message = __( 'Media file restored from the Trash.' ); |
|
103 } else { |
|
104 $message = sprintf( |
|
105 /* translators: %s: Number of media files. */ |
|
106 _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed ), |
|
107 number_format_i18n( $untrashed ) |
|
108 ); |
|
109 } |
|
110 |
|
111 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] ); |
|
112 unset( $_GET['untrashed'] ); |
|
113 } |
|
114 |
|
115 $messages[1] = __( 'Media file updated.' ); |
|
116 $messages[2] = __( 'Media file permanently deleted.' ); |
|
117 $messages[3] = __( 'Error saving media file.' ); |
|
118 $messages[4] = __( 'Media file moved to the Trash.' ) . sprintf( |
|
119 ' <a href="%1$s">%2$s</a>', |
|
120 esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ), |
|
121 __( 'Undo' ) |
|
122 ); |
|
123 $messages[5] = __( 'Media file restored from the Trash.' ); |
|
124 |
|
125 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) { |
|
126 $message = $messages[ $_GET['message'] ]; |
|
127 |
|
128 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] ); |
|
129 } |
|
130 |
17 $modes = array( 'grid', 'list' ); |
131 $modes = array( 'grid', 'list' ); |
18 |
132 |
19 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes, true ) ) { |
133 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes, true ) ) { |
20 $mode = $_GET['mode']; |
134 $mode = $_GET['mode']; |
21 update_user_option( get_current_user_id(), 'media_library_mode', $mode ); |
135 update_user_option( get_current_user_id(), 'media_library_mode', $mode ); |
|
136 } else { |
|
137 $mode = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid'; |
22 } |
138 } |
23 |
139 |
24 if ( 'grid' === $mode ) { |
140 if ( 'grid' === $mode ) { |
25 wp_enqueue_media(); |
141 wp_enqueue_media(); |
26 wp_enqueue_script( 'media-grid' ); |
142 wp_enqueue_script( 'media-grid' ); |
27 wp_enqueue_script( 'media' ); |
143 wp_enqueue_script( 'media' ); |
28 |
144 |
29 remove_action( 'admin_head', 'wp_admin_canonical_url' ); |
145 // Remove the error parameter added by deprecation of wp-admin/media.php. |
|
146 add_filter( |
|
147 'removable_query_args', |
|
148 function () { |
|
149 return array( 'error' ); |
|
150 }, |
|
151 10, |
|
152 0 |
|
153 ); |
30 |
154 |
31 $q = $_GET; |
155 $q = $_GET; |
32 // Let JS handle this. |
156 // Let JS handle this. |
33 unset( $q['s'] ); |
157 unset( $q['s'] ); |
34 $vars = wp_edit_attachments_query_vars( $q ); |
158 $vars = wp_edit_attachments_query_vars( $q ); |
86 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
210 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
87 |
211 |
88 <?php |
212 <?php |
89 if ( current_user_can( 'upload_files' ) ) { |
213 if ( current_user_can( 'upload_files' ) ) { |
90 ?> |
214 ?> |
91 <a href="<?php echo esc_url( admin_url( 'media-new.php' ) ); ?>" class="page-title-action aria-button-if-js"><?php echo esc_html_x( 'Add New', 'file' ); ?></a> |
215 <a href="<?php echo esc_url( admin_url( 'media-new.php' ) ); ?>" class="page-title-action aria-button-if-js"><?php echo esc_html__( 'Add New Media File' ); ?></a> |
92 <?php |
216 <?php |
93 } |
217 } |
94 ?> |
218 ?> |
95 |
219 |
96 <hr class="wp-header-end"> |
220 <hr class="wp-header-end"> |
97 |
221 |
98 <div class="error hide-if-js"> |
222 <?php |
99 <p> |
223 if ( ! empty( $message ) ) { |
100 <?php |
224 wp_admin_notice( |
101 printf( |
225 $message, |
102 /* translators: %s: List view URL. */ |
226 array( |
103 __( 'The grid view for the Media Library requires JavaScript. <a href="%s">Switch to the list view</a>.' ), |
227 'id' => 'message', |
104 'upload.php?mode=list' |
228 'additional_classes' => array( 'updated' ), |
|
229 'dismissible' => true, |
|
230 ) |
105 ); |
231 ); |
106 ?> |
232 } |
107 </p> |
233 |
108 </div> |
234 $js_required_message = sprintf( |
|
235 /* translators: %s: List view URL. */ |
|
236 __( 'The grid view for the Media Library requires JavaScript. <a href="%s">Switch to the list view</a>.' ), |
|
237 'upload.php?mode=list' |
|
238 ); |
|
239 wp_admin_notice( |
|
240 $js_required_message, |
|
241 array( |
|
242 'additional_classes' => array( 'error', 'hide-if-js' ), |
|
243 ) |
|
244 ); |
|
245 ?> |
109 </div> |
246 </div> |
110 <?php |
247 <?php |
111 require_once ABSPATH . 'wp-admin/admin-footer.php'; |
248 require_once ABSPATH . 'wp-admin/admin-footer.php'; |
112 exit; |
249 exit; |
113 } |
250 } |
129 } elseif ( isset( $_REQUEST['media'] ) ) { |
266 } elseif ( isset( $_REQUEST['media'] ) ) { |
130 $post_ids = $_REQUEST['media']; |
267 $post_ids = $_REQUEST['media']; |
131 } elseif ( isset( $_REQUEST['ids'] ) ) { |
268 } elseif ( isset( $_REQUEST['ids'] ) ) { |
132 $post_ids = explode( ',', $_REQUEST['ids'] ); |
269 $post_ids = explode( ',', $_REQUEST['ids'] ); |
133 } |
270 } |
|
271 $post_ids = array_map( 'intval', (array) $post_ids ); |
134 |
272 |
135 $location = 'upload.php'; |
273 $location = 'upload.php'; |
136 $referer = wp_get_referer(); |
274 $referer = wp_get_referer(); |
137 if ( $referer ) { |
275 if ( $referer ) { |
138 if ( false !== strpos( $referer, 'upload.php' ) ) { |
276 if ( str_contains( $referer, 'upload.php' ) ) { |
139 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer ); |
277 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer ); |
140 } |
278 } |
141 } |
279 } |
142 |
280 |
143 switch ( $doaction ) { |
281 switch ( $doaction ) { |
237 get_current_screen()->add_help_tab( |
375 get_current_screen()->add_help_tab( |
238 array( |
376 array( |
239 'id' => 'actions-links', |
377 'id' => 'actions-links', |
240 'title' => __( 'Available Actions' ), |
378 'title' => __( 'Available Actions' ), |
241 'content' => |
379 'content' => |
242 '<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>', |
380 '<p>' . __( 'Hovering over a row reveals action links that allow you to manage media items. You can perform the following actions:' ) . '</p>' . |
|
381 '<ul>' . |
|
382 '<li>' . __( '<strong>Edit</strong> takes you to a simple screen to edit that individual file’s metadata. You can also reach that screen by clicking on the media file name or thumbnail.' ) . '</li>' . |
|
383 '<li>' . __( '<strong>Delete Permanently</strong> will delete the file from the media library (as well as from any posts to which it is currently attached).' ) . '</li>' . |
|
384 '<li>' . __( '<strong>View</strong> will take you to a public display page for that file.' ) . '</li>' . |
|
385 '<li>' . __( '<strong>Copy URL</strong> copies the URL for the media file to your clipboard.' ) . '</li>' . |
|
386 '<li>' . __( '<strong>Download file</strong> downloads the original media file to your device.' ) . '</li>' . |
|
387 '</ul>', |
243 ) |
388 ) |
244 ); |
389 ); |
245 get_current_screen()->add_help_tab( |
390 get_current_screen()->add_help_tab( |
246 array( |
391 array( |
247 'id' => 'attaching-files', |
392 'id' => 'attaching-files', |
290 ?> |
435 ?> |
291 |
436 |
292 <hr class="wp-header-end"> |
437 <hr class="wp-header-end"> |
293 |
438 |
294 <?php |
439 <?php |
295 $message = ''; |
|
296 if ( ! empty( $_GET['posted'] ) ) { |
|
297 $message = __( 'Media file updated.' ); |
|
298 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'posted' ), $_SERVER['REQUEST_URI'] ); |
|
299 } |
|
300 |
|
301 if ( ! empty( $_GET['attached'] ) && absint( $_GET['attached'] ) ) { |
|
302 $attached = absint( $_GET['attached'] ); |
|
303 if ( 1 === $attached ) { |
|
304 $message = __( 'Media file attached.' ); |
|
305 } else { |
|
306 /* translators: %s: Number of media files. */ |
|
307 $message = _n( '%s media file attached.', '%s media files attached.', $attached ); |
|
308 } |
|
309 $message = sprintf( $message, number_format_i18n( $attached ) ); |
|
310 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] ); |
|
311 } |
|
312 |
|
313 if ( ! empty( $_GET['detach'] ) && absint( $_GET['detach'] ) ) { |
|
314 $detached = absint( $_GET['detach'] ); |
|
315 if ( 1 === $detached ) { |
|
316 $message = __( 'Media file detached.' ); |
|
317 } else { |
|
318 /* translators: %s: Number of media files. */ |
|
319 $message = _n( '%s media file detached.', '%s media files detached.', $detached ); |
|
320 } |
|
321 $message = sprintf( $message, number_format_i18n( $detached ) ); |
|
322 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] ); |
|
323 } |
|
324 |
|
325 if ( ! empty( $_GET['deleted'] ) && absint( $_GET['deleted'] ) ) { |
|
326 $deleted = absint( $_GET['deleted'] ); |
|
327 if ( 1 === $deleted ) { |
|
328 $message = __( 'Media file permanently deleted.' ); |
|
329 } else { |
|
330 /* translators: %s: Number of media files. */ |
|
331 $message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted ); |
|
332 } |
|
333 $message = sprintf( $message, number_format_i18n( $deleted ) ); |
|
334 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] ); |
|
335 } |
|
336 |
|
337 if ( ! empty( $_GET['trashed'] ) && absint( $_GET['trashed'] ) ) { |
|
338 $trashed = absint( $_GET['trashed'] ); |
|
339 if ( 1 === $trashed ) { |
|
340 $message = __( 'Media file moved to the Trash.' ); |
|
341 } else { |
|
342 /* translators: %s: Number of media files. */ |
|
343 $message = _n( '%s media file moved to the Trash.', '%s media files moved to the Trash.', $trashed ); |
|
344 } |
|
345 $message = sprintf( $message, number_format_i18n( $trashed ) ); |
|
346 $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ) . '">' . __( 'Undo' ) . '</a>'; |
|
347 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'trashed' ), $_SERVER['REQUEST_URI'] ); |
|
348 } |
|
349 |
|
350 if ( ! empty( $_GET['untrashed'] ) && absint( $_GET['untrashed'] ) ) { |
|
351 $untrashed = absint( $_GET['untrashed'] ); |
|
352 if ( 1 === $untrashed ) { |
|
353 $message = __( 'Media file restored from the Trash.' ); |
|
354 } else { |
|
355 /* translators: %s: Number of media files. */ |
|
356 $message = _n( '%s media file restored from the Trash.', '%s media files restored from the Trash.', $untrashed ); |
|
357 } |
|
358 $message = sprintf( $message, number_format_i18n( $untrashed ) ); |
|
359 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'untrashed' ), $_SERVER['REQUEST_URI'] ); |
|
360 } |
|
361 |
|
362 $messages[1] = __( 'Media file updated.' ); |
|
363 $messages[2] = __( 'Media file permanently deleted.' ); |
|
364 $messages[3] = __( 'Error saving media file.' ); |
|
365 $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>'; |
|
366 $messages[5] = __( 'Media file restored from the Trash.' ); |
|
367 |
|
368 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) { |
|
369 $message = $messages[ $_GET['message'] ]; |
|
370 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] ); |
|
371 } |
|
372 |
|
373 if ( ! empty( $message ) ) { |
440 if ( ! empty( $message ) ) { |
374 ?> |
441 wp_admin_notice( |
375 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div> |
442 $message, |
376 <?php } ?> |
443 array( |
|
444 'id' => 'message', |
|
445 'additional_classes' => array( 'updated' ), |
|
446 'dismissible' => true, |
|
447 ) |
|
448 ); |
|
449 } |
|
450 ?> |
377 |
451 |
378 <form id="posts-filter" method="get"> |
452 <form id="posts-filter" method="get"> |
379 |
453 |
380 <?php $wp_list_table->views(); ?> |
454 <?php $wp_list_table->views(); ?> |
381 |
455 |