2008-01-09 03:14:29 -05:00
|
|
|
<?php
|
2008-08-14 02:30:38 -04:00
|
|
|
/**
|
|
|
|
* Manage media uploaded file.
|
|
|
|
*
|
|
|
|
* There are many filters in here for media. Plugins can extend functionality
|
|
|
|
* by hooking into the filters.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
2010-12-01 14:28:24 -05:00
|
|
|
if ( ! isset( $_GET['inline'] ) )
|
|
|
|
define( 'IFRAME_REQUEST' , true );
|
2010-10-18 13:58:36 -04:00
|
|
|
|
2008-08-14 02:30:38 -04:00
|
|
|
/** Load WordPress Administration Bootstrap */
|
2013-09-24 20:18:11 -04:00
|
|
|
require_once( dirname( __FILE__ ) . '/admin.php' );
|
2008-09-27 04:17:55 -04:00
|
|
|
|
|
|
|
if (!current_user_can('upload_files'))
|
|
|
|
wp_die(__('You do not have permission to upload files.'));
|
|
|
|
|
2011-07-29 04:59:35 -04:00
|
|
|
wp_enqueue_script('plupload-handlers');
|
2009-09-10 18:07:33 -04:00
|
|
|
wp_enqueue_script('image-edit');
|
2009-10-07 18:18:09 -04:00
|
|
|
wp_enqueue_script('set-post-thumbnail' );
|
2009-09-10 18:07:33 -04:00
|
|
|
wp_enqueue_style('imgareaselect');
|
2012-04-04 20:20:28 -04:00
|
|
|
wp_enqueue_script( 'media-gallery' );
|
2008-01-09 03:14:29 -05:00
|
|
|
|
|
|
|
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
|
|
|
|
|
|
|
|
// IDs should be integers
|
2008-08-14 02:30:38 -04:00
|
|
|
$ID = isset($ID) ? (int) $ID : 0;
|
2008-02-22 12:43:56 -05:00
|
|
|
$post_id = isset($post_id)? (int) $post_id : 0;
|
2008-01-09 03:14:29 -05:00
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
// Require an ID for the edit screen.
|
2008-02-22 12:43:56 -05:00
|
|
|
if ( isset($action) && $action == 'edit' && !$ID )
|
2014-11-16 01:16:22 -05:00
|
|
|
wp_die( __( 'Cheatin’ uh?' ), 403 );
|
2008-01-09 03:14:29 -05:00
|
|
|
|
2012-06-10 13:37:49 -04:00
|
|
|
if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) )
|
2014-11-16 01:16:22 -05:00
|
|
|
wp_die( __( 'Cheatin’ uh?' ), 403 );
|
2008-01-09 03:14:29 -05:00
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
// Upload type: image, video, file, ..?
|
2014-01-07 23:00:11 -05:00
|
|
|
if ( isset($_GET['type']) ) {
|
2008-09-27 04:17:55 -04:00
|
|
|
$type = strval($_GET['type']);
|
2014-01-07 23:00:11 -05:00
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Filter the default media upload type in the legacy (pre-3.5.0) media popup.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param string $type The default media upload type. Possible values include
|
|
|
|
* 'image', 'audio', 'video', 'file', etc. Default 'file'.
|
|
|
|
*/
|
|
|
|
$type = apply_filters( 'media_upload_default_type', 'file' );
|
|
|
|
}
|
2008-12-09 13:03:31 -05:00
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
// Tab: gallery, library, or type-specific.
|
2014-01-06 00:48:12 -05:00
|
|
|
if ( isset($_GET['tab']) ) {
|
2008-09-27 04:17:55 -04:00
|
|
|
$tab = strval($_GET['tab']);
|
2014-01-06 00:48:12 -05:00
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Filter the default tab in the legacy (pre-3.5.0) media popup.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
2014-01-07 23:00:11 -05:00
|
|
|
* @param string $type The default media popup tab. Default 'type' (From Computer).
|
2014-01-06 00:48:12 -05:00
|
|
|
*/
|
|
|
|
$tab = apply_filters( 'media_upload_default_tab', 'type' );
|
|
|
|
}
|
2008-12-09 13:03:31 -05:00
|
|
|
|
2008-09-27 04:17:55 -04:00
|
|
|
$body_id = 'media-upload';
|
2008-12-09 13:03:31 -05:00
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
// Let the action code decide how to handle the request.
|
2014-01-07 23:00:11 -05:00
|
|
|
if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) ) {
|
|
|
|
/**
|
|
|
|
* Fires inside specific upload-type views in the legacy (pre-3.5.0)
|
|
|
|
* media popup based on the current tab.
|
|
|
|
*
|
2014-11-30 06:42:24 -05:00
|
|
|
* The dynamic portion of the hook name, `$type`, refers to the specific
|
2014-01-07 23:00:11 -05:00
|
|
|
* media upload type. Possible values include 'image', 'audio', 'video',
|
|
|
|
* 'file', etc.
|
|
|
|
*
|
2014-11-30 06:42:24 -05:00
|
|
|
* The hook only fires if the current `$tab` is 'type' (From Computer),
|
2014-01-07 23:00:11 -05:00
|
|
|
* 'type_url' (From URL), or, if the tab does not exist (i.e., has not
|
2014-11-30 06:42:24 -05:00
|
|
|
* been registered via the {@see 'media_upload_tabs'} filter.
|
2014-01-07 23:00:11 -05:00
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*/
|
|
|
|
do_action( "media_upload_$type" );
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Fires inside limited and specific upload-tab views in the legacy
|
|
|
|
* (pre-3.5.0) media popup.
|
|
|
|
*
|
2014-11-30 06:42:24 -05:00
|
|
|
* The dynamic portion of the hook name, `$tab`, refers to the specific
|
2014-01-07 23:00:11 -05:00
|
|
|
* media upload tab. Possible values include 'library' (Media Library),
|
2014-11-30 06:42:24 -05:00
|
|
|
* or any custom tab registered via the {@see 'media_upload_tabs'} filter.
|
2014-01-07 23:00:11 -05:00
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*/
|
|
|
|
do_action( "media_upload_$tab" );
|
|
|
|
}
|