[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Media Library administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once __DIR__ . '/admin.php'; 11 12 if ( ! current_user_can( 'upload_files' ) ) { 13 wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); 14 } 15 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 131 $modes = array( 'grid', 'list' ); 132 133 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes, true ) ) { 134 $mode = $_GET['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'; 138 } 139 140 if ( 'grid' === $mode ) { 141 wp_enqueue_media(); 142 wp_enqueue_script( 'media-grid' ); 143 wp_enqueue_script( 'media' ); 144 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 ); 154 155 $q = $_GET; 156 // Let JS handle this. 157 unset( $q['s'] ); 158 $vars = wp_edit_attachments_query_vars( $q ); 159 $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' ); 160 foreach ( $vars as $key => $value ) { 161 if ( ! $value || in_array( $key, $ignore, true ) ) { 162 unset( $vars[ $key ] ); 163 } 164 } 165 166 wp_localize_script( 167 'media-grid', 168 '_wpMediaGridSettings', 169 array( 170 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ), 171 'queryVars' => (object) $vars, 172 ) 173 ); 174 175 get_current_screen()->add_help_tab( 176 array( 177 'id' => 'overview', 178 'title' => __( 'Overview' ), 179 'content' => 180 '<p>' . __( 'All the files you’ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' . 181 '<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>' . 182 '<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>', 183 ) 184 ); 185 186 get_current_screen()->add_help_tab( 187 array( 188 'id' => 'attachment-details', 189 'title' => __( 'Attachment Details' ), 190 'content' => 191 '<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>' . 192 '<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>' . 193 '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>', 194 ) 195 ); 196 197 get_current_screen()->set_help_sidebar( 198 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 199 '<p>' . __( '<a href="https://wordpress.org/documentation/article/media-library-screen/">Documentation on Media Library</a>' ) . '</p>' . 200 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' 201 ); 202 203 // Used in the HTML title tag. 204 $title = __( 'Media Library' ); 205 $parent_file = 'upload.php'; 206 207 require_once ABSPATH . 'wp-admin/admin-header.php'; 208 ?> 209 <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query(); ?>"> 210 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> 211 212 <?php 213 if ( current_user_can( 'upload_files' ) ) { 214 ?> 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> 216 <?php 217 } 218 ?> 219 220 <hr class="wp-header-end"> 221 222 <?php 223 if ( ! empty( $message ) ) { 224 wp_admin_notice( 225 $message, 226 array( 227 'id' => 'message', 228 'additional_classes' => array( 'updated' ), 229 'dismissible' => true, 230 ) 231 ); 232 } 233 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 ?> 246 </div> 247 <?php 248 require_once ABSPATH . 'wp-admin/admin-footer.php'; 249 exit; 250 } 251 252 $wp_list_table = _get_list_table( 'WP_Media_List_Table' ); 253 $pagenum = $wp_list_table->get_pagenum(); 254 255 // Handle bulk actions. 256 $doaction = $wp_list_table->current_action(); 257 258 if ( $doaction ) { 259 check_admin_referer( 'bulk-media' ); 260 261 $post_ids = array(); 262 263 if ( 'delete_all' === $doaction ) { 264 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" ); 265 $doaction = 'delete'; 266 } elseif ( isset( $_REQUEST['media'] ) ) { 267 $post_ids = $_REQUEST['media']; 268 } elseif ( isset( $_REQUEST['ids'] ) ) { 269 $post_ids = explode( ',', $_REQUEST['ids'] ); 270 } 271 $post_ids = array_map( 'intval', (array) $post_ids ); 272 273 $location = 'upload.php'; 274 $referer = wp_get_referer(); 275 if ( $referer ) { 276 if ( str_contains( $referer, 'upload.php' ) ) { 277 $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer ); 278 } 279 } 280 281 switch ( $doaction ) { 282 case 'detach': 283 wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' ); 284 break; 285 286 case 'attach': 287 wp_media_attach_action( $_REQUEST['found_post_id'] ); 288 break; 289 290 case 'trash': 291 if ( empty( $post_ids ) ) { 292 break; 293 } 294 foreach ( $post_ids as $post_id ) { 295 if ( ! current_user_can( 'delete_post', $post_id ) ) { 296 wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) ); 297 } 298 299 if ( ! wp_trash_post( $post_id ) ) { 300 wp_die( __( 'Error in moving the item to Trash.' ) ); 301 } 302 } 303 $location = add_query_arg( 304 array( 305 'trashed' => count( $post_ids ), 306 'ids' => implode( ',', $post_ids ), 307 ), 308 $location 309 ); 310 break; 311 case 'untrash': 312 if ( empty( $post_ids ) ) { 313 break; 314 } 315 foreach ( $post_ids as $post_id ) { 316 if ( ! current_user_can( 'delete_post', $post_id ) ) { 317 wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) ); 318 } 319 320 if ( ! wp_untrash_post( $post_id ) ) { 321 wp_die( __( 'Error in restoring the item from Trash.' ) ); 322 } 323 } 324 $location = add_query_arg( 'untrashed', count( $post_ids ), $location ); 325 break; 326 case 'delete': 327 if ( empty( $post_ids ) ) { 328 break; 329 } 330 foreach ( $post_ids as $post_id_del ) { 331 if ( ! current_user_can( 'delete_post', $post_id_del ) ) { 332 wp_die( __( 'Sorry, you are not allowed to delete this item.' ) ); 333 } 334 335 if ( ! wp_delete_attachment( $post_id_del ) ) { 336 wp_die( __( 'Error in deleting the attachment.' ) ); 337 } 338 } 339 $location = add_query_arg( 'deleted', count( $post_ids ), $location ); 340 break; 341 default: 342 $screen = get_current_screen()->id; 343 344 /** This action is documented in wp-admin/edit.php */ 345 $location = apply_filters( "handle_bulk_actions-{$screen}", $location, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 346 } 347 348 wp_redirect( $location ); 349 exit; 350 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { 351 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); 352 exit; 353 } 354 355 $wp_list_table->prepare_items(); 356 357 // Used in the HTML title tag. 358 $title = __( 'Media Library' ); 359 $parent_file = 'upload.php'; 360 361 wp_enqueue_script( 'media' ); 362 363 add_screen_option( 'per_page' ); 364 365 get_current_screen()->add_help_tab( 366 array( 367 'id' => 'overview', 368 'title' => __( 'Overview' ), 369 'content' => 370 '<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>' . 371 '<p>' . __( 'You can narrow the list by file type/status or by date using the dropdown menus above the media table.' ) . '</p>' . 372 '<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>', 373 ) 374 ); 375 get_current_screen()->add_help_tab( 376 array( 377 'id' => 'actions-links', 378 'title' => __( 'Available Actions' ), 379 'content' => 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>', 388 ) 389 ); 390 get_current_screen()->add_help_tab( 391 array( 392 'id' => 'attaching-files', 393 'title' => __( 'Attaching Files' ), 394 'content' => 395 '<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>', 396 ) 397 ); 398 399 get_current_screen()->set_help_sidebar( 400 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 401 '<p>' . __( '<a href="https://wordpress.org/documentation/article/media-library-screen/">Documentation on Media Library</a>' ) . '</p>' . 402 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' 403 ); 404 405 get_current_screen()->set_screen_reader_content( 406 array( 407 'heading_views' => __( 'Filter media items list' ), 408 'heading_pagination' => __( 'Media items list navigation' ), 409 'heading_list' => __( 'Media items list' ), 410 ) 411 ); 412 413 require_once ABSPATH . 'wp-admin/admin-header.php'; 414 ?> 415 416 <div class="wrap"> 417 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> 418 419 <?php 420 if ( current_user_can( 'upload_files' ) ) { 421 ?> 422 <a href="<?php echo esc_url( admin_url( 'media-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html__( 'Add New Media File' ); ?></a> 423 <?php 424 } 425 426 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 427 echo '<span class="subtitle">'; 428 printf( 429 /* translators: %s: Search query. */ 430 __( 'Search results for: %s' ), 431 '<strong>' . get_search_query() . '</strong>' 432 ); 433 echo '</span>'; 434 } 435 ?> 436 437 <hr class="wp-header-end"> 438 439 <?php 440 if ( ! empty( $message ) ) { 441 wp_admin_notice( 442 $message, 443 array( 444 'id' => 'message', 445 'additional_classes' => array( 'updated' ), 446 'dismissible' => true, 447 ) 448 ); 449 } 450 ?> 451 452 <form id="posts-filter" method="get"> 453 454 <?php $wp_list_table->views(); ?> 455 456 <?php $wp_list_table->display(); ?> 457 458 <div id="ajax-response"></div> 459 <?php find_posts_div(); ?> 460 </form> 461 </div> 462 463 <?php 464 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |