Making WordPress.org


Ignore:
Timestamp:
04/19/2024 02:56:22 AM (10 months ago)
Author:
dd32
Message:

Plugin Directory: Upload: Allow specifying a comment during the ZIP upload.

See #7598, #6853.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r13574 r13575  
    7979
    8080        $zip_file         = $_FILES['zip_file']['tmp_name'];
     81        $upload_comment   = trim( wp_unslash( $_POST['comment'] ) );
    8182        $has_upload_token = $this->has_valid_upload_token();
    8283        $this->plugin_dir = Filesystem::unzip( $zip_file );
     
    492493        }
    493494
    494         $attachment = $this->save_zip_file( $plugin_post->ID );
     495        $attachment = $this->save_zip_file( $plugin_post->ID, $upload_comment );
    495496        if ( is_wp_error( $attachment ) ) {
    496497            return $attachment;
     498        }
     499
     500        // Store the uploaded comment as a plugin audit log.
     501        if ( $upload_comment ) {
     502            Tools::audit_log(
     503                sprintf(
     504                    "Upload Comment for <a href='%s'>%s</a>\n%s",
     505                    wp_get_attachment_url( $attachment->ID ),
     506                    esc_html( $attachment->submitted_name ),
     507                    esc_html( $upload_comment )
     508                ),
     509                $plugin_post->ID,
     510            );
    497511        }
    498512
     
    655669     * @return WP_Post|WP_Error Attachment post or upload error.
    656670     */
    657     public function save_zip_file( $post_id ) {
     671    public function save_zip_file( $post_id, $upload_comment ) {
    658672        $zip_hash = sha1_file( $_FILES['zip_file']['tmp_name'] );
    659673        if ( in_array( $zip_hash, get_post_meta( $post_id, 'uploaded_zip_hash' ) ?: [], true ) ) {
     
    669683
    670684        // Store the plugin details against the media as well.
    671         $post_details  = array(
     685        $post_details = array(
    672686            'post_title'   => sprintf( '%s Version %s', $this->plugin['Name'], $this->plugin['Version'] ),
    673687            'post_excerpt' => $this->plugin['Description'],
     688            'post_content' => esc_html( $upload_comment )
    674689        );
    675690        $attachment = media_handle_upload( 'zip_file', $post_id, $post_details );
     
    765780
    766781        $text = sprintf(
    767             "New ZIP uploaded by %s, version %s.\n%s\n%s",
     782            "New ZIP uploaded by %s, version %s.\nComment: %s\n%s",
    768783            wp_get_current_user()->user_login,
    769784            $attachment->version,
    770             get_edit_post_link( $post ),
     785            $attachment->post_content,
    771786            wp_get_attachment_url( $attachment->ID )
    772787        );
Note: See TracChangeset for help on using the changeset viewer.