Changeset 13115 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php
- Timestamp:
- 01/16/2024 05:10:27 AM (8 months ago)
- 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 8 8 use WordPressdotorg\Plugin_Directory\Tools\Filesystem; 9 9 use WordPressdotorg\Plugin_Directory\Admin\Tools\Upload_Token; 10 use WordPressdotorg\Plugin_Directory\Clients\HelpScout; 10 11 11 12 /** … … 467 468 468 469 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( 470 475 __( 'New version of %s uploaded for review.', 'wporg-plugins' ), 471 476 esc_html( $this->plugin['Name'] ) 472 477 ); 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; 473 484 } 474 485 … … 786 797 * 787 798 * @param int $post_id Post ID. 788 * @return int|WP_Error Attachment IDor upload error.799 * @return WP_Post|WP_Error Attachment post or upload error. 789 800 */ 790 801 public function save_zip_file( $post_id ) { … … 806 817 'post_excerpt' => $this->plugin['Description'], 807 818 ); 808 $attachment _id= media_handle_upload( 'zip_file', $post_id, $post_details );819 $attachment = media_handle_upload( 'zip_file', $post_id, $post_details ); 809 820 810 821 remove_filter( 'site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) ); 811 822 remove_filter( 'default_site_option_upload_filetypes', array( $this, 'whitelist_zip_files' ) ); 812 823 813 if ( ! is_wp_error( $attachment_id ) ) { 824 if ( ! is_wp_error( $attachment ) ) { 825 $attachment = get_post( $attachment ); 826 814 827 // 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 ); 817 830 818 831 // And record this ZIP as having been uploaded. … … 820 833 } 821 834 822 return $attachment _id;835 return $attachment; 823 836 } 824 837 … … 893 906 } 894 907 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 } 895 977 }
Note: See TracChangeset
for help on using the changeset viewer.