Deprecated

This function has been deprecated. This function was replaced by new form class instead.

ap_post_upload_form( boolean|integer $post_id = false )

Description #

Upload form.

Parameters #

  • $post_id
    boolean | integer (Optional) Post ID. Default value: false

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: includes/deprecated.php

function ap_post_upload_form( $post_id = false ) {
	_deprecated_function( __FUNCTION__, '4.1.0', 'AnsPress\Form\Upload' );

	if ( ! ap_user_can_upload() ) {
		return;
	}

	if ( false === $post_id ) {
		$media = get_posts(
			[
				'post_type'   => 'attachment',
				'title'       => '_ap_temp_media',
				'post_author' => get_current_user_id(),
			]
		);
	} else {
		$media = get_attached_media( '', $post_id );
	}

	$label = sprintf( __( 'Insert images and attach media by %1$sselecting them%2$s', 'anspress-question-answer' ), '<a id="pickfiles" href="javascript:;">', '</a>' );
	$html  = '<div id="ap-upload" class="ap-upload"><div class="ap-upload-anchor">' . $label . '</div>';

	$uploads = [];
	foreach ( (array) $media as $m ) {
		$uploads[] = [
			'id'       => $m->ID,
			'fileName' => basename( $m->guid ),
			'fileSize' => size_format( filesize( get_attached_file( $m->ID ) ), 2 ),
			'isImage'  => wp_attachment_is_image( $m->ID ),
			'nonce'    => wp_create_nonce( 'delete-attachment-' . $m->ID ),
			'url'      => $m->guid,
		];
	}

	$html .= '<script type="application/json" id="ap-uploads-data">' . wp_json_encode( $uploads ) . '</script>';
	$html .= '</div>';
	return $html;
}

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