wp/wp-admin/async-upload.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-admin/async-upload.php	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-admin/async-upload.php	Tue Jun 09 03:35:32 2015 +0200
@@ -1,12 +1,18 @@
 <?php
 /**
- * Accepts file uploads from swfupload or other asynchronous upload methods.
+ * Server-side file upload handler from wp-plupload, swfupload or other asynchronous upload methods.
  *
  * @package WordPress
  * @subpackage Administration
  */
 
-define('WP_ADMIN', true);
+if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
+	define( 'DOING_AJAX', true );
+}
+
+if ( ! defined( 'WP_ADMIN' ) ) {
+	define( 'WP_ADMIN', true );
+}
 
 if ( defined('ABSPATH') )
 	require_once(ABSPATH . 'wp-load.php');
@@ -26,14 +32,10 @@
 
 require_once( ABSPATH . 'wp-admin/admin.php' );
 
-if ( !current_user_can('upload_files') )
-	wp_die(__('You do not have permission to upload files.'));
-
-header('Content-Type: text/html; charset=' . get_option('blog_charset'));
+header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
 
 if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
-	define( 'DOING_AJAX', true );
-	include ABSPATH . 'wp-admin/includes/ajax-actions.php';
+	include( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
 
 	send_nosniff_header();
 	nocache_headers();
@@ -42,6 +44,10 @@
 	die( '0' );
 }
 
+if ( ! current_user_can( 'upload_files' ) ) {
+	wp_die( __( 'You do not have permission to upload files.' ) );
+}
+
 // just fetch the detail form for that attachment
 if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) {
 	$post = get_post( $id );
@@ -81,7 +87,7 @@
 
 $id = media_handle_upload( 'async-upload', $post_id );
 if ( is_wp_error($id) ) {
-	echo '<div class="error-div">
+	echo '<div class="error-div error">
 	<a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a>
 	<strong>' . sprintf(__('&#8220;%s&#8221; has failed to upload due to an error'), esc_html($_FILES['async-upload']['name']) ) . '</strong><br />' .
 	esc_html($id->get_error_message()) . '</div>';
@@ -89,10 +95,21 @@
 }
 
 if ( $_REQUEST['short'] ) {
-	// short form response - attachment ID only
+	// Short form response - attachment ID only.
 	echo $id;
 } else {
-	// long form response - big chunk o html
+	// Long form response - big chunk o html.
 	$type = $_REQUEST['type'];
-	echo apply_filters("async_upload_{$type}", $id);
+
+	/**
+	 * Filter the returned ID of an uploaded attachment.
+	 *
+	 * The dynamic portion of the hook name, `$type`, refers to the attachment type,
+	 * such as 'image', 'audio', 'video', 'file', etc.
+	 *
+	 * @since 2.5.0
+	 *
+	 * @param int $id Uploaded attachment ID.
+	 */
+	echo apply_filters( "async_upload_{$type}", $id );
 }