AnsPress_Uploader::upload_modal()

Description #

Ajax callback for image upload form.

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: includes/upload.php

	public static function upload_modal() {
		// Check nonce.
		if ( ! ap_verify_nonce( 'ap_upload_image' ) ) {
			ap_send_json( 'something_wrong' );
		}

		// 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' ),
					),
				)
			);
		}

		$image_for = ap_sanitize_unslash( 'image_for', 'r' );

		ob_start();
		anspress()->get_form( 'image_upload' )->generate(
			array(
				'hidden_fields' => array(
					array(
						'name'  => 'action',
						'value' => 'ap_image_upload',
					),
					array(
						'name'  => 'image_for',
						'value' => $image_for,
					),
				),
			)
		);
		$html = ob_get_clean();

		ap_send_json(
			array(
				'success' => true,
				'action'  => 'ap_upload_modal',
				'html'    => $html,
				'title'   => __( 'Select image file to upload', 'anspress-question-answer' ),
			)
		);
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment