Changeset 10213
- Timestamp:
- 08/27/2020 07:46:52 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php
r10204 r10213 86 86 } elseif ( $_POST && ! empty( $_POST['block-directory-test'] ) ) { 87 87 self::handle_test(); 88 } elseif ( $_POST && ! empty( $_POST['block-directory-email'] ) ) { 89 self::handle_send_email(); 88 90 } 89 91 ?> … … 163 165 } 164 166 167 protected static function handle_send_email() { 168 $post = get_post( intval( $_POST['plugin-id'] ) ); 169 if ( $post && 'error' === $_POST['block-directory-email'] && wp_verify_nonce( $_POST['block-directory-email-nonce'], 'block-directory-email-' . $post->ID ) ) { 170 if ( current_user_can( 'edit_post', $post->ID ) ) { 171 if ( self::maybe_send_email_block_error( $post ) ) { 172 echo '<div class="notice notice-success notice-alt"><p>' . __( 'Email sent.', 'wporg-plugins' ) . '</p></div>'; 173 } 174 } 175 } 176 177 return self::validate_block( $post->post_name ); 178 } 179 165 180 protected static function plugin_is_in_block_directory( $slug ) { 166 181 $plugin = Plugin_Directory::get_plugin_post( $slug ); … … 194 209 } 195 210 196 if ( current_user_can( 'edit_post', $p ost->ID ) ) {211 if ( current_user_can( 'edit_post', $plugin->ID ) ) { 197 212 echo wp_nonce_field( 'block-directory-test-' . $plugin->ID, 'block-directory-test-nonce' ); 198 213 // translators: %s plugin title. 199 214 $disabled = ( wp_cache_get( "plugin-e2e-test-{$plugin->ID}", 'plugin-test' ) ? ' disabled="disabled"' : '' ); 200 215 echo '<button class="button button-secondary button-large" type="submit" name="block-directory-test" value="test"' . $disabled . '>' . sprintf( __( 'Test %s', 'wporg-plugins' ), $plugin->post_title ) . '</button>'; 216 217 if ( 'false' === get_post_meta( $plugin->ID, 'e2e_success', true ) ) { 218 $user = get_user_by( 'ID', $plugin->post_author ); 219 echo wp_nonce_field( 'block-directory-email-' . $plugin->ID, 'block-directory-email-nonce' ); 220 echo '<button class="button button-secondary button-large" type="submit" name="block-directory-email" value="error">' . sprintf( __( 'Email Test Error to %s', 'wporg-plugins' ), $user->user_email ) . '</button>'; 221 } 201 222 } 202 223 … … 305 326 if ( !empty( $e2e_result ) ) { 306 327 echo '<h4>' . __( 'Test Results', 'wporg-plugins' ) . '</h4>'; 328 if ( $github_url = get_post_meta( $plugin->ID, 'e2e_lastRunURL', true ) ) { 329 echo '<a href="' .esc_url( $github_url ) . '">Test details</a>'; 330 } 307 331 if ( 'true' === $e2e_result ) { 308 332 echo "<div class='notice notice-info notice-alt'><p>\n"; … … 532 556 return wp_mail( $user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' ); 533 557 } 558 559 /** 560 * Sends an email to the plugin author alerting them to a test failure. 561 */ 562 protected static function maybe_send_email_block_error( $post ) { 563 $plugin_author = get_user_by( 'id', $post->post_author ); 564 if ( empty( $plugin_author ) ) { 565 return false; 566 } 567 568 $error = get_post_meta( $post->ID, 'e2e_error', true ); 569 $github_url = get_post_meta( $post->ID, 'e2e_lastRunURL', true ); 570 if ( !$error || !$github_url ) { 571 return false; 572 } 573 574 // Don't send duplicate emails about the same error 575 if ( get_post_meta( $post->ID, 'email_sent_about_error', true ) === $error ) { 576 return false; 577 } 578 579 /* translators: %s: plugin name */ 580 $email_subject = sprintf( 581 __( '[WordPress Plugin Directory] Error in your block plugin - %s', 'wporg-plugins' ), 582 $post->post_name 583 ); 584 585 /* 586 Please leave the blank lines in place. 587 */ 588 $email_content = sprintf( 589 // translators: 1: plugin name, 2: error message, 3: plugin slug, 4: github link. 590 __( 591 'Thanks for submitting your plugin %1$s to the block directory! 592 593 We noticed a problem when testing a recent commit to your plugin: 594 595 %2$s 596 597 This error was generated by an automated end-to-end test that attempts to insert the block %3%s into a post in the same way a user would. The test failure probably means that the block plugin will not work for users. 598 599 Here\'s how to reproduce the problem: 600 601 1. Start with a fresh install of WordPress stable. 602 2. Make sure it has no plugins or custom themes installed. 603 3. Create a new post with the block editor. 604 4. In the block inserter, search for "slug:%3$s". 605 5. Click the "Add block" button. 606 6. Check the browser console and PHP error logs. 607 608 If you are able to reproduce the error, you can resolve the problem by committing a bugfix and updating the stable tag. This will automatically trigger a new test. 609 610 Further details of the test are available here: 611 612 %4$s 613 614 If you are unable to reproduce the issue and you think there might be a problem with our testing, please open an issue in that GitHub repository. 615 616 -- 617 The WordPress Plugin Directory Team 618 https://make.wordpress.org/plugins', 'wporg-plugins' 619 ), 620 $post->post_title, 621 $error, 622 $post->post_name, 623 $github_url 624 ); 625 626 $user_email = $plugin_author->user_email; 627 628 $result = wp_mail( $user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' ); 629 630 if ( $result ) { 631 update_post_meta( $post->ID, 'email_sent_about_error', $error ); 632 } 633 634 return $result; 635 } 534 636 }
Note: See TracChangeset
for help on using the changeset viewer.