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

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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