3 * Media Library administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
12 if ( !current_user_can('upload_files') )
13 wp_die( __( 'You do not have permission to upload files.' ) );
15 $mode = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
16 $modes = array( 'grid', 'list' );
18 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes ) ) {
19 $mode = $_GET['mode'];
20 update_user_option( get_current_user_id(), 'media_library_mode', $mode );
23 if ( 'grid' === $mode ) {
25 wp_enqueue_script( 'media-grid' );
26 wp_enqueue_script( 'media' );
28 remove_action( 'admin_head', 'wp_admin_canonical_url' );
33 $vars = wp_edit_attachments_query_vars( $q );
34 $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
35 foreach ( $vars as $key => $value ) {
36 if ( ! $value || in_array( $key, $ignore ) ) {
37 unset( $vars[ $key ] );
41 wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
42 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
43 'queryVars' => (object) $vars
46 get_current_screen()->add_help_tab( array(
48 'title' => __( 'Overview' ),
50 '<p>' . __( 'All the files you’ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
51 '<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>' .
52 '<p>' . __( 'To delete media items, click the Bulk Select button at the top of the screen. Select any items you wish to delete, then click the Delete Selected button. Clicking the Cancel Selection button takes you back to viewing your media.' ) . '</p>'
55 get_current_screen()->add_help_tab( array(
56 'id' => 'attachment-details',
57 'title' => __( 'Attachment Details' ),
59 '<p>' . __( 'Clicking an item will display an Attachment Details dialog, which allows you to preview media and make quick edits. Any changes you make to the attachment details will be automatically saved.' ) . '</p>' .
60 '<p>' . __( 'Use the arrow buttons at the top of the dialog, or the left and right arrow keys on your keyboard, to navigate between media items quickly.' ) . '</p>' .
61 '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
64 get_current_screen()->set_help_sidebar(
65 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
66 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
67 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
70 $title = __('Media Library');
71 $parent_file = 'upload.php';
73 require_once( ABSPATH . 'wp-admin/admin-header.php' );
75 <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query() ?>">
78 echo esc_html( $title );
79 if ( current_user_can( 'upload_files' ) ) { ?>
80 <a href="media-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
84 <div class="error hide-if-js">
85 <p><?php _e( 'The grid view for the Media Library requires JavaScript. <a href="upload.php?mode=list">Switch to the list view</a>.' ); ?></p>
89 include( ABSPATH . 'wp-admin/admin-footer.php' );
93 $wp_list_table = _get_list_table('WP_Media_List_Table');
94 $pagenum = $wp_list_table->get_pagenum();
96 // Handle bulk actions
97 $doaction = $wp_list_table->current_action();
100 check_admin_referer('bulk-media');
102 if ( 'delete_all' == $doaction ) {
103 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
104 $doaction = 'delete';
105 } elseif ( isset( $_REQUEST['media'] ) ) {
106 $post_ids = $_REQUEST['media'];
107 } elseif ( isset( $_REQUEST['ids'] ) ) {
108 $post_ids = explode( ',', $_REQUEST['ids'] );
111 $location = 'upload.php';
112 if ( $referer = wp_get_referer() ) {
113 if ( false !== strpos( $referer, 'upload.php' ) )
114 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
117 switch ( $doaction ) {
119 wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
123 wp_media_attach_action( $_REQUEST['found_post_id'] );
127 if ( !isset( $post_ids ) )
129 foreach ( (array) $post_ids as $post_id ) {
130 if ( !current_user_can( 'delete_post', $post_id ) )
131 wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
133 if ( !wp_trash_post( $post_id ) )
134 wp_die( __( 'Error in moving to Trash.' ) );
136 $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
139 if ( !isset( $post_ids ) )
141 foreach ( (array) $post_ids as $post_id ) {
142 if ( !current_user_can( 'delete_post', $post_id ) )
143 wp_die( __( 'You are not allowed to move this item out of the Trash.' ) );
145 if ( !wp_untrash_post( $post_id ) )
146 wp_die( __( 'Error in restoring from Trash.' ) );
148 $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
151 if ( !isset( $post_ids ) )
153 foreach ( (array) $post_ids as $post_id_del ) {
154 if ( !current_user_can( 'delete_post', $post_id_del ) )
155 wp_die( __( 'You are not allowed to delete this item.' ) );
157 if ( !wp_delete_attachment( $post_id_del ) )
158 wp_die( __( 'Error in deleting.' ) );
160 $location = add_query_arg( 'deleted', count( $post_ids ), $location );
164 wp_redirect( $location );
166 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
167 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
171 $wp_list_table->prepare_items();
173 $title = __('Media Library');
174 $parent_file = 'upload.php';
176 wp_enqueue_script( 'media' );
178 add_screen_option( 'per_page' );
180 get_current_screen()->add_help_tab( array(
182 'title' => __('Overview'),
184 '<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>' .
185 '<p>' . __( 'You can narrow the list by file type/status using the text link filters at the top of the screen. You also can refine the list by date using the dropdown menu above the media table.' ) . '</p>' .
186 '<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>'
188 get_current_screen()->add_help_tab( array(
189 'id' => 'actions-links',
190 'title' => __('Available Actions'),
192 '<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>'
194 get_current_screen()->add_help_tab( array(
195 'id' => 'attaching-files',
196 'title' => __('Attaching Files'),
198 '<p>' . __( 'If a media file has not been attached to any post, you will see that in the Attached To column, and can click on Attach File to launch a small popup that will allow you to search for a post and attach the file.' ) . '</p>'
201 get_current_screen()->set_help_sidebar(
202 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
203 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
204 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
207 get_current_screen()->set_screen_reader_content( array(
208 'heading_views' => __( 'Filter media items list' ),
209 'heading_pagination' => __( 'Media items list navigation' ),
210 'heading_list' => __( 'Media items list' ),
213 require_once( ABSPATH . 'wp-admin/admin-header.php' );
219 echo esc_html( $title );
220 if ( current_user_can( 'upload_files' ) ) { ?>
221 <a href="media-new.php" class="page-title-action"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
223 if ( ! empty( $_REQUEST['s'] ) )
224 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', get_search_query() ); ?>
229 if ( ! empty( $_GET['posted'] ) ) {
230 $message = __( 'Media attachment updated.' );
231 $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
234 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
235 $message = sprintf( _n( 'Reattached %d attachment.', 'Reattached %d attachments.', $attached ), $attached );
236 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
239 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
240 $message = sprintf( _n( 'Detached %d attachment.', 'Detached %d attachments.', $detached ), $detached );
241 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
244 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
245 if ( 1 == $deleted ) {
246 $message = __( 'Media attachment permanently deleted.' );
248 $message = _n( '%d media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted );
250 $message = sprintf( $message, number_format_i18n( $deleted ) );
251 $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
254 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
255 if ( 1 == $trashed ) {
256 $message = __( 'Media attachment moved to the trash.' );
258 $message = _n( '%d media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed );
260 $message = sprintf( $message, number_format_i18n( $trashed ) );
261 $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
262 $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
265 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
266 if ( 1 == $untrashed ) {
267 $message = __( 'Media attachment restored from the trash.' );
269 $message = _n( '%d media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed );
271 $message = sprintf( $message, number_format_i18n( $untrashed ) );
272 $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
275 $messages[1] = __( 'Media attachment updated.' );
276 $messages[2] = __( 'Media attachment permanently deleted.' );
277 $messages[3] = __( 'Error saving media attachment.' );
278 $messages[4] = __( 'Media attachment 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>';
279 $messages[5] = __( 'Media attachment restored from the trash.' );
281 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
282 $message = $messages[ $_GET['message'] ];
283 $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
286 if ( !empty($message) ) { ?>
287 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
290 <form id="posts-filter" method="get">
292 <?php $wp_list_table->views(); ?>
294 <?php $wp_list_table->display(); ?>
296 <div id="ajax-response"></div>
297 <?php find_posts_div(); ?>
302 include( ABSPATH . 'wp-admin/admin-footer.php' );