Making WordPress.org

Changeset 10213


Ignore:
Timestamp:
08/27/2020 07:46:52 AM (4 years ago)
Author:
tellyworth
Message:

Plugin dir: add an email to alert block developers about test failures.

See #5303.

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  
    8686            } elseif ( $_POST && ! empty( $_POST['block-directory-test'] ) ) {
    8787                self::handle_test();
     88            } elseif ( $_POST && ! empty( $_POST['block-directory-email'] ) ) {
     89                self::handle_send_email();
    8890            }
    8991            ?>
     
    163165    }
    164166
     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
    165180    protected static function plugin_is_in_block_directory( $slug ) {
    166181        $plugin = Plugin_Directory::get_plugin_post( $slug );
     
    194209        }
    195210
    196         if ( current_user_can( 'edit_post', $post->ID ) ) {
     211        if ( current_user_can( 'edit_post', $plugin->ID ) ) {
    197212            echo wp_nonce_field( 'block-directory-test-' . $plugin->ID, 'block-directory-test-nonce' );
    198213            // translators: %s plugin title.
    199214            $disabled = ( wp_cache_get( "plugin-e2e-test-{$plugin->ID}", 'plugin-test' ) ? ' disabled="disabled"' : '' );
    200215            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            }
    201222        }
    202223
     
    305326                if ( !empty( $e2e_result ) ) {
    306327                    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                    }
    307331                    if ( 'true' === $e2e_result ) {
    308332                        echo "<div class='notice notice-info notice-alt'><p>\n";
     
    532556        return wp_mail( $user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' );
    533557    }
     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
     593We noticed a problem when testing a recent commit to your plugin:
     594
     595%2$s
     596
     597This 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
     599Here\'s how to reproduce the problem:
     600
     6011. Start with a fresh install of WordPress stable.
     6022. Make sure it has no plugins or custom themes installed.
     6033. Create a new post with the block editor.
     6044. In the block inserter, search for "slug:%3$s".
     6055. Click the "Add block" button.
     6066. Check the browser console and PHP error logs.
     607
     608If 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
     610Further details of the test are available here:
     611
     612%4$s
     613
     614If 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--
     617The WordPress Plugin Directory Team
     618https://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    }
    534636}
Note: See TracChangeset for help on using the changeset viewer.