Edit File by line
/home/barbar84/www/wp-admin
File: async-upload.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side file upload handler from wp-plupload or other asynchronous upload methods.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
[8] Fix | Delete
define( 'DOING_AJAX', true );
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
if ( ! defined( 'WP_ADMIN' ) ) {
[12] Fix | Delete
define( 'WP_ADMIN', true );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
if ( defined( 'ABSPATH' ) ) {
[16] Fix | Delete
require_once ABSPATH . 'wp-load.php';
[17] Fix | Delete
} else {
[18] Fix | Delete
require_once dirname( __DIR__ ) . '/wp-load.php';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
require_once ABSPATH . 'wp-admin/admin.php';
[22] Fix | Delete
[23] Fix | Delete
header( 'Content-Type: text/plain; charset=' . get_option( 'blog_charset' ) );
[24] Fix | Delete
[25] Fix | Delete
if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
[26] Fix | Delete
require ABSPATH . 'wp-admin/includes/ajax-actions.php';
[27] Fix | Delete
[28] Fix | Delete
send_nosniff_header();
[29] Fix | Delete
nocache_headers();
[30] Fix | Delete
[31] Fix | Delete
wp_ajax_upload_attachment();
[32] Fix | Delete
die( '0' );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
if ( ! current_user_can( 'upload_files' ) ) {
[36] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
// Just fetch the detail form for that attachment.
[40] Fix | Delete
if ( isset( $_REQUEST['attachment_id'] ) && (int) $_REQUEST['attachment_id'] && $_REQUEST['fetch'] ) {
[41] Fix | Delete
$id = (int) $_REQUEST['attachment_id'];
[42] Fix | Delete
$post = get_post( $id );
[43] Fix | Delete
if ( 'attachment' !== $post->post_type ) {
[44] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
switch ( $_REQUEST['fetch'] ) {
[48] Fix | Delete
case 3:
[49] Fix | Delete
$thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true );
[50] Fix | Delete
if ( $thumb_url ) {
[51] Fix | Delete
echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
[52] Fix | Delete
}
[53] Fix | Delete
if ( current_user_can( 'edit_post', $id ) ) {
[54] Fix | Delete
echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
[55] Fix | Delete
} else {
[56] Fix | Delete
echo '<span class="edit-attachment">' . _x( 'Success', 'media item' ) . '</span>';
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
// Title shouldn't ever be empty, but use filename just in case.
[60] Fix | Delete
$file = get_attached_file( $post->ID );
[61] Fix | Delete
$title = $post->post_title ? $post->post_title : wp_basename( $file );
[62] Fix | Delete
echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
[63] Fix | Delete
break;
[64] Fix | Delete
case 2:
[65] Fix | Delete
add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 );
[66] Fix | Delete
echo get_media_item(
[67] Fix | Delete
$id,
[68] Fix | Delete
array(
[69] Fix | Delete
'send' => false,
[70] Fix | Delete
'delete' => true,
[71] Fix | Delete
)
[72] Fix | Delete
);
[73] Fix | Delete
break;
[74] Fix | Delete
default:
[75] Fix | Delete
add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
[76] Fix | Delete
echo get_media_item( $id );
[77] Fix | Delete
break;
[78] Fix | Delete
}
[79] Fix | Delete
exit;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
check_admin_referer( 'media-form' );
[83] Fix | Delete
[84] Fix | Delete
$post_id = 0;
[85] Fix | Delete
if ( isset( $_REQUEST['post_id'] ) ) {
[86] Fix | Delete
$post_id = absint( $_REQUEST['post_id'] );
[87] Fix | Delete
if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
[88] Fix | Delete
$post_id = 0;
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
$id = media_handle_upload( 'async-upload', $post_id );
[93] Fix | Delete
if ( is_wp_error( $id ) ) {
[94] Fix | Delete
printf(
[95] Fix | Delete
'<div class="error-div error">%s <strong>%s</strong><br />%s</div>',
[96] Fix | Delete
sprintf(
[97] Fix | Delete
'<button type="button" class="dismiss button-link" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">%s</button>',
[98] Fix | Delete
__( 'Dismiss' )
[99] Fix | Delete
),
[100] Fix | Delete
sprintf(
[101] Fix | Delete
/* translators: %s: Name of the file that failed to upload. */
[102] Fix | Delete
__( '&#8220;%s&#8221; has failed to upload.' ),
[103] Fix | Delete
esc_html( $_FILES['async-upload']['name'] )
[104] Fix | Delete
),
[105] Fix | Delete
esc_html( $id->get_error_message() )
[106] Fix | Delete
);
[107] Fix | Delete
exit;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
if ( $_REQUEST['short'] ) {
[111] Fix | Delete
// Short form response - attachment ID only.
[112] Fix | Delete
echo $id;
[113] Fix | Delete
} else {
[114] Fix | Delete
// Long form response - big chunk of HTML.
[115] Fix | Delete
$type = $_REQUEST['type'];
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Filters the returned ID of an uploaded attachment.
[119] Fix | Delete
*
[120] Fix | Delete
* The dynamic portion of the hook name, `$type`, refers to the attachment type,
[121] Fix | Delete
* such as 'image', 'audio', 'video', 'file', etc.
[122] Fix | Delete
*
[123] Fix | Delete
* @since 2.5.0
[124] Fix | Delete
*
[125] Fix | Delete
* @param int $id Uploaded attachment ID.
[126] Fix | Delete
*/
[127] Fix | Delete
echo apply_filters( "async_upload_{$type}", $id );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function