media-new.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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( dirname( __FILE__ ) . '/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. $title = __( 'Upload New Media' );
  37. $parent_file = 'upload.php';
  38. get_current_screen()->add_help_tab(
  39. array(
  40. 'id' => 'overview',
  41. 'title' => __( 'Overview' ),
  42. 'content' =>
  43. '<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>' .
  44. '<ul>' .
  45. '<li>' . __( '<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.' ) . '</li>' .
  46. '<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>' .
  47. '<li>' . __( 'Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.' ) . '</li>' .
  48. '</ul>',
  49. )
  50. );
  51. get_current_screen()->set_help_sidebar(
  52. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  53. '<p>' . __( '<a href="https://wordpress.org/support/article/media-add-new-screen/">Documentation on Uploading Media Files</a>' ) . '</p>' .
  54. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  55. );
  56. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  57. $form_class = 'media-upload-form type-form validate';
  58. if ( get_user_setting( 'uploader' ) || isset( $_GET['browser-uploader'] ) ) {
  59. $form_class .= ' html-uploader';
  60. }
  61. ?>
  62. <div class="wrap">
  63. <h1><?php echo esc_html( $title ); ?></h1>
  64. <form enctype="multipart/form-data" method="post" action="<?php echo admin_url( 'media-new.php' ); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form">
  65. <?php media_upload_form(); ?>
  66. <script type="text/javascript">
  67. var post_id = <?php echo $post_id; ?>, shortform = 3;
  68. </script>
  69. <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
  70. <?php wp_nonce_field( 'media-form' ); ?>
  71. <div id="media-items" class="hide-if-no-js"></div>
  72. </form>
  73. </div>
  74. <?php
  75. include( ABSPATH . 'wp-admin/admin-footer.php' );