您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

media-new.php 3.0 KiB

3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. wp_enqueue_script('plupload-handlers');
  16. $post_id = 0;
  17. if ( isset( $_REQUEST['post_id'] ) ) {
  18. $post_id = absint( $_REQUEST['post_id'] );
  19. if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
  20. $post_id = 0;
  21. }
  22. if ( $_POST ) {
  23. if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
  24. check_admin_referer('media-form');
  25. // Upload File button was clicked
  26. $upload_id = media_handle_upload( 'async-upload', $post_id );
  27. if ( is_wp_error( $upload_id ) ) {
  28. wp_die( $upload_id );
  29. }
  30. }
  31. wp_redirect( admin_url( 'upload.php' ) );
  32. exit;
  33. }
  34. $title = __('Upload New Media');
  35. $parent_file = 'upload.php';
  36. get_current_screen()->add_help_tab( array(
  37. 'id' => 'overview',
  38. 'title' => __('Overview'),
  39. 'content' =>
  40. '<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>' .
  41. '<ul>' .
  42. '<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' .
  43. '<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>' .
  44. '<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' .
  45. '</ul>'
  46. ) );
  47. get_current_screen()->set_help_sidebar(
  48. '<p><strong>' . __('For more information:') . '</strong></p>' .
  49. '<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen">Documentation on Uploading Media Files</a>') . '</p>' .
  50. '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
  51. );
  52. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  53. $form_class = 'media-upload-form type-form validate';
  54. if ( get_user_setting('uploader') || isset( $_GET['browser-uploader'] ) )
  55. $form_class .= ' html-uploader';
  56. ?>
  57. <div class="wrap">
  58. <h1><?php echo esc_html( $title ); ?></h1>
  59. <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">
  60. <?php media_upload_form(); ?>
  61. <script type="text/javascript">
  62. var post_id = <?php echo $post_id; ?>, shortform = 3;
  63. </script>
  64. <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
  65. <?php wp_nonce_field('media-form'); ?>
  66. <div id="media-items" class="hide-if-no-js"></div>
  67. </form>
  68. </div>
  69. <?php
  70. include( ABSPATH . 'wp-admin/admin-footer.php' );