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' );
31 $vars = wp_edit_attachments_query_vars( $q );
32 $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
33 foreach ( $vars as $key => $value ) {
34 if ( ! $value || in_array( $key, $ignore ) ) {
35 unset( $vars[ $key ] );
39 wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
40 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
41 'queryVars' => (object) $vars
44 get_current_screen()->add_help_tab( array(
46 'title' => __( 'Overview' ),
48 '<p>' . __( 'All the files you’ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
49 '<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>' .
50 '<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>'
53 get_current_screen()->add_help_tab( array(
54 'id' => 'attachment-details',
55 'title' => __( 'Attachment Details' ),
57 '<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>' .
58 '<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>' .
59 '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
62 get_current_screen()->set_help_sidebar(
63 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
64 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
65 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
68 $title = __('Media Library');
69 $parent_file = 'upload.php';
71 require_once( ABSPATH . 'wp-admin/admin-header.php' );
73 <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query() ?>">
76 echo esc_html( $title );
77 if ( current_user_can( 'upload_files' ) ) { ?>
78 <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
82 <div class="error hide-if-js">
83 <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>
87 include( ABSPATH . 'wp-admin/admin-footer.php' );
91 $wp_list_table = _get_list_table('WP_Media_List_Table');
92 $pagenum = $wp_list_table->get_pagenum();
94 // Handle bulk actions
95 $doaction = $wp_list_table->current_action();
98 check_admin_referer('bulk-media');
100 if ( 'delete_all' == $doaction ) {
101 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
102 $doaction = 'delete';
103 } elseif ( isset( $_REQUEST['media'] ) ) {
104 $post_ids = $_REQUEST['media'];
105 } elseif ( isset( $_REQUEST['ids'] ) ) {
106 $post_ids = explode( ',', $_REQUEST['ids'] );
109 $location = 'upload.php';
110 if ( $referer = wp_get_referer() ) {
111 if ( false !== strpos( $referer, 'upload.php' ) )
112 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
115 switch ( $doaction ) {
117 wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
121 wp_media_attach_action( $_REQUEST['found_post_id'] );
125 if ( !isset( $post_ids ) )
127 foreach ( (array) $post_ids as $post_id ) {
128 if ( !current_user_can( 'delete_post', $post_id ) )
129 wp_die( __( 'You are not allowed to move this post to the trash.' ) );
131 if ( !wp_trash_post( $post_id ) )
132 wp_die( __( 'Error in moving to trash.' ) );
134 $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
137 if ( !isset( $post_ids ) )
139 foreach ( (array) $post_ids as $post_id ) {
140 if ( !current_user_can( 'delete_post', $post_id ) )
141 wp_die( __( 'You are not allowed to move this post out of the trash.' ) );
143 if ( !wp_untrash_post( $post_id ) )
144 wp_die( __( 'Error in restoring from trash.' ) );
146 $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
149 if ( !isset( $post_ids ) )
151 foreach ( (array) $post_ids as $post_id_del ) {
152 if ( !current_user_can( 'delete_post', $post_id_del ) )
153 wp_die( __( 'You are not allowed to delete this post.' ) );
155 if ( !wp_delete_attachment( $post_id_del ) )
156 wp_die( __( 'Error in deleting.' ) );
158 $location = add_query_arg( 'deleted', count( $post_ids ), $location );
162 wp_redirect( $location );
164 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
165 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
169 $wp_list_table->prepare_items();
171 $title = __('Media Library');
172 $parent_file = 'upload.php';
174 wp_enqueue_script( 'media' );
176 add_screen_option( 'per_page' );
178 get_current_screen()->add_help_tab( array(
180 'title' => __('Overview'),
182 '<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>' .
183 '<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>' .
184 '<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>'
186 get_current_screen()->add_help_tab( array(
187 'id' => 'actions-links',
188 'title' => __('Available Actions'),
190 '<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>'
192 get_current_screen()->add_help_tab( array(
193 'id' => 'attaching-files',
194 'title' => __('Attaching Files'),
196 '<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>'
199 get_current_screen()->set_help_sidebar(
200 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
201 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
202 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
205 require_once( ABSPATH . 'wp-admin/admin-header.php' );
211 echo esc_html( $title );
212 if ( current_user_can( 'upload_files' ) ) { ?>
213 <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
215 if ( ! empty( $_REQUEST['s'] ) )
216 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', get_search_query() ); ?>
221 if ( ! empty( $_GET['posted'] ) ) {
222 $message = __( 'Media attachment updated.' );
223 $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
226 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
227 $message = sprintf( _n( 'Reattached %d attachment.', 'Reattached %d attachments.', $attached ), $attached );
228 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
231 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
232 $message = sprintf( _n( 'Detached %d attachment.', 'Detached %d attachments.', $detached ), $detached );
233 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
236 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
237 if ( 1 == $deleted ) {
238 $message = __( 'Media attachment permanently deleted.' );
240 $message = _n( '%d media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted );
242 $message = sprintf( $message, number_format_i18n( $deleted ) );
243 $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
246 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
247 if ( 1 == $trashed ) {
248 $message = __( 'Media attachment moved to the trash.' );
250 $message = _n( '%d media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed );
252 $message = sprintf( $message, number_format_i18n( $trashed ) );
253 $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
254 $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
257 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
258 if ( 1 == $untrashed ) {
259 $message = __( 'Media attachment restored from the trash.' );
261 $message = _n( '%d media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed );
263 $message = sprintf( $message, number_format_i18n( $untrashed ) );
264 $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
267 $messages[1] = __('Media attachment updated.');
268 $messages[2] = __('Media permanently deleted.');
269 $messages[3] = __('Error saving media attachment.');
270 $messages[4] = __('Media 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>';
271 $messages[5] = __('Media restored from the trash.');
273 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
274 $message = $messages[ $_GET['message'] ];
275 $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
278 if ( !empty($message) ) { ?>
279 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
282 <form id="posts-filter" method="get">
284 <?php $wp_list_table->views(); ?>
286 <?php $wp_list_table->display(); ?>
288 <div id="ajax-response"></div>
289 <?php find_posts_div(); ?>
294 include( ABSPATH . 'wp-admin/admin-footer.php' );