Making WordPress.org


Ignore:
Timestamp:
01/16/2024 05:10:27 AM (8 months ago)
Author:
dd32
Message:

Plugin Directory: Submission: When a pending plugin has a new ZIP uploaded, instruct the author to email the team, but also re-open the ticket with a note about the new upload.

See #7384.

File:
1 edited

Legend:

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

    r13109 r13115  
    88use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    99use WordPressdotorg\Plugin_Directory\Admin\Tools\Upload_Token;
     10use WordPressdotorg\Plugin_Directory\Clients\HelpScout;
    1011
    1112/**
     
    467468
    468469        if ( $updating_existing ) {
    469             return sprintf(
     470
     471            // Update HelpScout, if in review.
     472            $this->update_review_email( $plugin_post, $attachment );
     473
     474            $message = sprintf(
    470475                __( 'New version of %s uploaded for review.', 'wporg-plugins' ),
    471476                esc_html( $this->plugin['Name'] )
    472477            );
     478
     479            if ( 'pending' === $plugin_post->post_status ) {
     480                $message .= '<br>' . __( 'Please respond to the review email to let us know, and address any feedback that was given to you.', 'wporg-plugins' );
     481            }
     482
     483            return $message;
    473484        }
    474485
     
    786797     *
    787798     * @param int $post_id Post ID.
    788      * @return int|WP_Error Attachment ID or upload error.
     799     * @return WP_Post|WP_Error Attachment post or upload error.
    789800     */
    790801    public function save_zip_file( $post_id ) {
     
    806817            'post_excerpt' => $this->plugin['Description'],
    807818        );
    808         $attachment_id = media_handle_upload( 'zip_file', $post_id, $post_details );
     819        $attachment = media_handle_upload( 'zip_file', $post_id, $post_details );
    809820
    810821        remove_filter( 'site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) );
    811822        remove_filter( 'default_site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) );
    812823
    813         if ( ! is_wp_error( $attachment_id ) ) {
     824        if ( ! is_wp_error( $attachment ) ) {
     825            $attachment = get_post( $attachment );
     826
    814827            // Save some basic details with the ZIP.
    815             update_post_meta( $attachment_id, 'version', $this->plugin['Version'] );
    816             update_post_meta( $attachment_id, 'submitted_name', $original_name );
     828            update_post_meta( $attachment->ID, 'version', $this->plugin['Version'] );
     829            update_post_meta( $attachment->ID, 'submitted_name', $original_name );
    817830
    818831            // And record this ZIP as having been uploaded.
     
    820833        }
    821834
    822         return $attachment_id;
     835        return $attachment;
    823836    }
    824837
     
    893906    }
    894907
     908    /**
     909     * Locate the HelpScout review email and it's status.
     910     *
     911     * @param WP_Post $post The plugin post.
     912     *
     913     * @return array|false
     914     */
     915    public static function find_review_email( $post ) {
     916        global $wpdb;
     917
     918        if ( 'pending' !== $post->post_status ) {
     919            return false;
     920        }
     921
     922        // Find the latest email for this plugin that looks like a review email.
     923        return $wpdb->get_row( $wpdb->prepare(
     924            "SELECT emails.*
     925                FROM %i emails
     926                    JOIN %i meta ON emails.id = meta.helpscout_id
     927                WHERE meta.meta_key = 'plugins' AND meta.meta_value = %s
     928                    AND emails.subject LIKE %s
     929                ORDER BY `created` DESC
     930                LIMIT 1",
     931            "{$wpdb->base_prefix}helpscout",
     932            "{$wpdb->base_prefix}helpscout_meta",
     933            $post->post_name,
     934            '%Review in Progress:%' // The subject line of the review email.
     935        ) );
     936    }
     937
     938    /**
     939     * Update the HelpScout review email.
     940     *
     941     * @param WP_Post $post       The plugin post.
     942     * @param WP_Post $attachment The uploaded attachment post.
     943     *
     944     * @return bool True if the email was updated, false otherwise.
     945     */
     946    public function update_review_email( $post, $attachment ) {
     947        $review_email = self::find_review_email( $post );
     948        if ( ! $review_email ) {
     949            return false;
     950        }
     951
     952        // Don't update the review email if the plugin author isn't the one who uploaded the ZIP.
     953        if ( $post->post_author != get_current_user_id() ) {
     954            return false;
     955        }
     956
     957        $text = sprintf(
     958            "New ZIP uploaded by %s, version %s.\n%s\n%s",
     959            wp_get_current_user()->user_login,
     960            $attachment->version,
     961            get_edit_post_link( $post ),
     962            wp_get_attachment_url( $attachment->ID )
     963        );
     964
     965        $result = HelpScout::api(
     966            '/v2/conversations/' . $review_email->id . '/notes',
     967            [
     968                'text'   => $text,
     969                'status' => 'active',
     970            ],
     971            'POST',
     972            $http_response_code
     973        );
     974
     975        return ( 201 === $http_response_code );
     976    }
    895977}
Note: See TracChangeset for help on using the changeset viewer.