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' );
27 wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
28 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
31 get_current_screen()->add_help_tab( array(
33 'title' => __( 'Overview' ),
35 '<p>' . __( 'All the files you’ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
36 '<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>' .
37 '<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>'
40 get_current_screen()->add_help_tab( array(
41 'id' => 'attachment-details',
42 'title' => __( 'Attachment Details' ),
44 '<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>' .
45 '<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>' .
46 '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
49 get_current_screen()->set_help_sidebar(
50 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
51 '<p>' . __( '<a href="http://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
52 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
55 $title = __('Media Library');
56 $parent_file = 'upload.php';
58 require_once( ABSPATH . 'wp-admin/admin-header.php' );
60 <div class="wrap" id="wp-media-grid">
63 echo esc_html( $title );
64 if ( current_user_can( 'upload_files' ) ) { ?>
65 <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
69 <div class="error hide-if-js">
70 <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>
74 include( ABSPATH . 'wp-admin/admin-footer.php' );
78 $wp_list_table = _get_list_table('WP_Media_List_Table');
79 $pagenum = $wp_list_table->get_pagenum();
81 // Handle bulk actions
82 $doaction = $wp_list_table->current_action();
85 check_admin_referer('bulk-media');
87 if ( 'delete_all' == $doaction ) {
88 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
90 } elseif ( isset( $_REQUEST['media'] ) ) {
91 $post_ids = $_REQUEST['media'];
92 } elseif ( isset( $_REQUEST['ids'] ) ) {
93 $post_ids = explode( ',', $_REQUEST['ids'] );
96 $location = 'upload.php';
97 if ( $referer = wp_get_referer() ) {
98 if ( false !== strpos( $referer, 'upload.php' ) )
99 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
102 switch ( $doaction ) {
104 $parent_id = (int) $_REQUEST['found_post_id'];
108 $parent = get_post( $parent_id );
109 if ( !current_user_can( 'edit_post', $parent_id ) )
110 wp_die( __( 'You are not allowed to edit this post.' ) );
113 foreach ( (array) $_REQUEST['media'] as $att_id ) {
114 $att_id = (int) $att_id;
116 if ( !current_user_can( 'edit_post', $att_id ) )
122 if ( ! empty( $attach ) ) {
123 $attach_string = implode( ',', $attach );
124 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach_string )", $parent_id ) );
125 foreach ( $attach as $att_id ) {
126 clean_attachment_cache( $att_id );
130 if ( isset( $attached ) ) {
131 $location = 'upload.php';
132 if ( $referer = wp_get_referer() ) {
133 if ( false !== strpos( $referer, 'upload.php' ) )
134 $location = $referer;
137 $location = add_query_arg( array( 'attached' => $attached ) , $location );
138 wp_redirect( $location );
143 if ( !isset( $post_ids ) )
145 foreach ( (array) $post_ids as $post_id ) {
146 if ( !current_user_can( 'delete_post', $post_id ) )
147 wp_die( __( 'You are not allowed to move this post to the trash.' ) );
149 if ( !wp_trash_post( $post_id ) )
150 wp_die( __( 'Error in moving to trash.' ) );
152 $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
155 if ( !isset( $post_ids ) )
157 foreach ( (array) $post_ids as $post_id ) {
158 if ( !current_user_can( 'delete_post', $post_id ) )
159 wp_die( __( 'You are not allowed to move this post out of the trash.' ) );
161 if ( !wp_untrash_post( $post_id ) )
162 wp_die( __( 'Error in restoring from trash.' ) );
164 $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
167 if ( !isset( $post_ids ) )
169 foreach ( (array) $post_ids as $post_id_del ) {
170 if ( !current_user_can( 'delete_post', $post_id_del ) )
171 wp_die( __( 'You are not allowed to delete this post.' ) );
173 if ( !wp_delete_attachment( $post_id_del ) )
174 wp_die( __( 'Error in deleting.' ) );
176 $location = add_query_arg( 'deleted', count( $post_ids ), $location );
180 wp_redirect( $location );
182 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
183 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
187 $wp_list_table->prepare_items();
189 $title = __('Media Library');
190 $parent_file = 'upload.php';
192 wp_enqueue_script( 'media' );
194 add_screen_option( 'per_page', array('label' => _x( 'Media items', 'items per page (screen options)' )) );
196 get_current_screen()->add_help_tab( array(
198 'title' => __('Overview'),
200 '<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>' .
201 '<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>' .
202 '<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>'
204 get_current_screen()->add_help_tab( array(
205 'id' => 'actions-links',
206 'title' => __('Available Actions'),
208 '<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>'
210 get_current_screen()->add_help_tab( array(
211 'id' => 'attaching-files',
212 'title' => __('Attaching Files'),
214 '<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>'
217 get_current_screen()->set_help_sidebar(
218 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
219 '<p>' . __( '<a href="http://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
220 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
223 require_once( ABSPATH . 'wp-admin/admin-header.php' );
229 echo esc_html( $title );
230 if ( current_user_can( 'upload_files' ) ) { ?>
231 <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
233 if ( ! empty( $_REQUEST['s'] ) )
234 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', get_search_query() ); ?>
239 if ( ! empty( $_GET['posted'] ) ) {
240 $message = __('Media attachment updated.');
241 $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
244 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
245 $message = sprintf( _n('Reattached %d attachment.', 'Reattached %d attachments.', $attached), $attached );
246 $_SERVER['REQUEST_URI'] = remove_query_arg(array('attached'), $_SERVER['REQUEST_URI']);
249 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
250 $message = sprintf( _n( 'Media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted ), number_format_i18n( $_GET['deleted'] ) );
251 $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
254 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
255 $message = sprintf( _n( 'Media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed ), number_format_i18n( $_GET['trashed'] ) );
256 $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
257 $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
260 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
261 $message = sprintf( _n( 'Media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed ), number_format_i18n( $_GET['untrashed'] ) );
262 $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
265 $messages[1] = __('Media attachment updated.');
266 $messages[2] = __('Media permanently deleted.');
267 $messages[3] = __('Error saving media attachment.');
268 $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>';
269 $messages[5] = __('Media restored from the trash.');
271 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
272 $message = $messages[ $_GET['message'] ];
273 $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
276 if ( !empty($message) ) { ?>
277 <div id="message" class="updated"><p><?php echo $message; ?></p></div>
280 <form id="posts-filter" action="" method="get">
282 <?php $wp_list_table->views(); ?>
284 <?php $wp_list_table->display(); ?>
286 <div id="ajax-response"></div>
287 <?php find_posts_div(); ?>
292 include( ABSPATH . 'wp-admin/admin-footer.php' );