AnsPress_Uploader::image_upload()
Description #
Ajax callback for ap_image_upload
. Process image_upload
form.
Source #
File: includes/upload.php
public static function image_upload() { $form = anspress()->get_form( 'image_upload' ); // Check if user have permission to upload tem image. if ( ! ap_user_can_upload() ) { ap_send_json( array( 'success' => false, 'snackbar' => array( 'message' => __( 'Sorry! you do not have permission to upload image.', 'anspress-question-answer' ), ), ) ); } // Nonce check. if ( ! $form->is_submitted() ) { ap_send_json( 'something_wrong' ); } $image_for = ap_sanitize_unslash( 'image_for', 'r' ); $values = $form->get_values(); // Check for errors. if ( $form->have_errors() ) { ap_send_json( array( 'success' => false, 'snackbar' => array( 'message' => __( 'Unable to upload image(s). Please check errors.', 'anspress-question-answer' ), ), 'form_errors' => $form->errors, 'fields_errors' => $form->get_fields_errors(), ) ); } $field = $form->find( 'image' ); // Call save. $files = $field->save_cb(); $res = array( 'success' => true, 'action' => 'ap_image_upload', 'image_for' => $image_for, 'snackbar' => [ 'message' => __( 'Successfully uploaded image', 'anspress-question-answer' ) ], 'files' => $files, ); // Send response. if ( is_array( $res ) ) { ap_send_json( $res ); } ap_send_json( 'something_wrong' ); }
Expand full source code Collapse full source code View on GitHub: includes/upload.php:167
Add your comment