AnsPress_Uploader::image_submission()
Description #
Upload an attachment to server.
Source #
File: includes/upload.php
public static function image_submission() {
$post_id = ap_sanitize_unslash( 'post_id', 'r' );
if ( ! check_ajax_referer( 'media-upload', false, false ) || ! ap_user_can_upload( ) || empty( $_FILES['async-upload'] ) ) {
ap_ajax_json( [
'success' => false,
'snackbar' => [
'message' => __( 'You are not allowed to upload attachments.', 'anspress-question-answer' ),
],
] );
}
if ( ! empty( $post_id ) && ! ap_user_can_edit_post( $post_id ) ) {
ap_ajax_json( [ 'success' => false ] );
} else {
$post_id = null;
}
$attachment_id = ap_upload_user_file( $_FILES['async-upload'], true, $post_id );
if ( is_wp_error( $attachment_id ) ) {
ap_ajax_json( [
'success' => false,
'snackbar' => [
'message' => $attachment_id->get_error_message(),
],
] );
}
ap_ajax_json( array(
'success' => true,
'attachment_url' => wp_get_attachment_url( $attachment_id ),
'attachment_id' => $attachment_id,
'is_image' => wp_attachment_is_image( $attachment_id ),
'delete_nonce' => wp_create_nonce( 'delete-attachment-' . $attachment_id ),
) );
}
Expand full source code Collapse full source code View on GitHub: includes/upload.php:21
Add your comment