media-new.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Manage media uploaded file.
  4. *
  5. * There are many filters in here for media. Plugins can extend functionality
  6. * by hooking into the filters.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. /** Load WordPress Administration Bootstrap */
  12. require_once __DIR__ . '/admin.php';
  13. if ( ! current_user_can( 'upload_files' ) ) {
  14. wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
  15. }
  16. wp_enqueue_script( 'plupload-handlers' );
  17. $post_id = 0;
  18. if ( isset( $_REQUEST['post_id'] ) ) {
  19. $post_id = absint( $_REQUEST['post_id'] );
  20. if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
  21. $post_id = 0;
  22. }
  23. }
  24. if ( $_POST ) {
  25. if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) {
  26. check_admin_referer( 'media-form' );
  27. // Upload File button was clicked.
  28. $upload_id = media_handle_upload( 'async-upload', $post_id );
  29. if ( is_wp_error( $upload_id ) ) {
  30. wp_die( $upload_id );
  31. }
  32. }
  33. wp_redirect( admin_url( 'upload.php' ) );
  34. exit;
  35. }
  36. // Used in the HTML title tag.
  37. $title = __( 'Upload New Media' );
  38. $parent_file = 'upload.php';
  39. get_current_screen()->add_help_tab(
  40. array(
  41. 'id' => 'overview',
  42. 'title' => __( 'Overview' ),
  43. 'content' =>
  44. '<p>' . __( 'You can upload media files here without creating a post first. This allows you to upload files to use with posts and pages later and/or to get a web link for a particular file that you can share. There are three options for uploading files:' ) . '</p>' .
  45. '<ul>' .
  46. '<li>' . __( '<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.' ) . '</li>' .
  47. '<li>' . __( 'Clicking <strong>Select Files</strong> opens a navigation window showing you files in your operating system. Selecting <strong>Open</strong> after clicking on the file you want activates a progress bar on the uploader screen.' ) . '</li>' .
  48. '<li>' . __( 'Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.' ) . '</li>' .
  49. '</ul>',
  50. )
  51. );
  52. get_current_screen()->set_help_sidebar(
  53. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  54. '<p>' . __( '<a href="https://wordpress.org/support/article/media-add-new-screen/">Documentation on Uploading Media Files</a>' ) . '</p>' .
  55. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  56. );
  57. require_once ABSPATH . 'wp-admin/admin-header.php';
  58. $form_class = 'media-upload-form type-form validate';
  59. if ( get_user_setting( 'uploader' ) || isset( $_GET['browser-uploader'] ) ) {
  60. $form_class .= ' html-uploader';
  61. }
  62. ?>
  63. <div class="wrap">
  64. <h1><?php echo esc_html( $title ); ?></h1>
  65. <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( admin_url( 'media-new.php' ) ); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form">
  66. <?php media_upload_form(); ?>
  67. <script type="text/javascript">
  68. var post_id = <?php echo absint( $post_id ); ?>, shortform = 3;
  69. </script>
  70. <input type="hidden" name="post_id" id="post_id" value="<?php echo absint( $post_id ); ?>" />
  71. <?php wp_nonce_field( 'media-form' ); ?>
  72. <div id="media-items" class="hide-if-no-js"></div>
  73. </form>
  74. </div>
  75. <?php
  76. require_once ABSPATH . 'wp-admin/admin-footer.php';