media-upload.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if ( ! isset( $_GET['inline'] ) )
  12. define( 'IFRAME_REQUEST' , true );
  13. /** Load WordPress Administration Bootstrap */
  14. require_once( dirname( __FILE__ ) . '/admin.php' );
  15. if ( ! current_user_can( 'upload_files' ) ) {
  16. wp_die( __( 'Sorry, you are not allowed to upload files.' ), 403 );
  17. }
  18. wp_enqueue_script('plupload-handlers');
  19. wp_enqueue_script('image-edit');
  20. wp_enqueue_script('set-post-thumbnail' );
  21. wp_enqueue_style('imgareaselect');
  22. wp_enqueue_script( 'media-gallery' );
  23. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
  24. // IDs should be integers
  25. $ID = isset($ID) ? (int) $ID : 0;
  26. $post_id = isset($post_id)? (int) $post_id : 0;
  27. // Require an ID for the edit screen.
  28. if ( isset( $action ) && $action == 'edit' && !$ID ) {
  29. wp_die(
  30. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
  31. '<p>' . __( 'Invalid item ID.' ) . '</p>',
  32. 403
  33. );
  34. }
  35. if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) ) {
  36. wp_die(
  37. '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
  38. '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
  39. 403
  40. );
  41. }
  42. // Upload type: image, video, file, ..?
  43. if ( isset($_GET['type']) ) {
  44. $type = strval($_GET['type']);
  45. } else {
  46. /**
  47. * Filters the default media upload type in the legacy (pre-3.5.0) media popup.
  48. *
  49. * @since 2.5.0
  50. *
  51. * @param string $type The default media upload type. Possible values include
  52. * 'image', 'audio', 'video', 'file', etc. Default 'file'.
  53. */
  54. $type = apply_filters( 'media_upload_default_type', 'file' );
  55. }
  56. // Tab: gallery, library, or type-specific.
  57. if ( isset($_GET['tab']) ) {
  58. $tab = strval($_GET['tab']);
  59. } else {
  60. /**
  61. * Filters the default tab in the legacy (pre-3.5.0) media popup.
  62. *
  63. * @since 2.5.0
  64. *
  65. * @param string $type The default media popup tab. Default 'type' (From Computer).
  66. */
  67. $tab = apply_filters( 'media_upload_default_tab', 'type' );
  68. }
  69. $body_id = 'media-upload';
  70. // Let the action code decide how to handle the request.
  71. if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) ) {
  72. /**
  73. * Fires inside specific upload-type views in the legacy (pre-3.5.0)
  74. * media popup based on the current tab.
  75. *
  76. * The dynamic portion of the hook name, `$type`, refers to the specific
  77. * media upload type. Possible values include 'image', 'audio', 'video',
  78. * 'file', etc.
  79. *
  80. * The hook only fires if the current `$tab` is 'type' (From Computer),
  81. * 'type_url' (From URL), or, if the tab does not exist (i.e., has not
  82. * been registered via the {@see 'media_upload_tabs'} filter.
  83. *
  84. * @since 2.5.0
  85. */
  86. do_action( "media_upload_{$type}" );
  87. } else {
  88. /**
  89. * Fires inside limited and specific upload-tab views in the legacy
  90. * (pre-3.5.0) media popup.
  91. *
  92. * The dynamic portion of the hook name, `$tab`, refers to the specific
  93. * media upload tab. Possible values include 'library' (Media Library),
  94. * or any custom tab registered via the {@see 'media_upload_tabs'} filter.
  95. *
  96. * @since 2.5.0
  97. */
  98. do_action( "media_upload_{$tab}" );
  99. }