Making WordPress.org

Changeset 10038


Ignore:
Timestamp:
07/08/2020 10:00:30 PM (4 years ago)
Author:
ryelle
Message:

Plugin Directory: Clean up block validation form & result messages.

See #5303

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php

    r10037 r10038  
    308308            'type' => $type,
    309309            'message' => $message,
    310             'data' => $data );
     310            'data' => $data,
     311        );
    311312    }
    312313
     
    319320     */
    320321    function check_readme_exists() {
    321         if ( empty( $this->readme_path ) || !file_exists( $this->readme_path ) ) {
    322             $this->record_result( __FUNCTION__,
     322        if ( empty( $this->readme_path ) || ! file_exists( $this->readme_path ) ) {
     323            $this->record_result(
     324                __FUNCTION__,
    323325                'error',
    324326                __( 'Missing readme.txt file.', 'wporg-plugins' ),
     
    333335    function check_license() {
    334336        if ( empty( $this->readme->license ) && empty( $this->headers->License ) ) {
    335             $this->record_result( __FUNCTION__,
     337            $this->record_result(
     338                __FUNCTION__,
    336339                'warning',
    337340                __( 'No plugin license was found.', 'wporg-plugins' )
    338341            );
    339         } elseif ( !empty( $this->readme->license ) ) {
    340             $this->record_result( __FUNCTION__,
     342        } elseif ( ! empty( $this->readme->license ) ) {
     343            $this->record_result(
     344                __FUNCTION__,
    341345                'info',
     346                // translators: %s is the license.
    342347                sprintf( __( 'Found a license in readme.txt: %s.', 'wporg-plugins' ), $this->readme->license ),
    343348                $this->readme->license
    344349            );
    345         } elseif ( !empty( $this->headers->License ) ) {
    346             $this->record_result( __FUNCTION__,
     350        } elseif ( ! empty( $this->headers->License ) ) {
     351            $this->record_result(
     352                __FUNCTION__,
    347353                'info',
     354                // translators: %s is the license.
    348355                sprintf( __( 'Found a license in plugin headers: %s.', 'wporg-plugins' ), $this->headers->License ),
    349356                $this->headers->License
     
    357364    function check_plugin_headers() {
    358365        if ( empty( $this->headers ) ) {
    359             $this->record_result( __FUNCTION__,
     366            $this->record_result(
     367                __FUNCTION__,
    360368                'error',
    361369                __( 'Missing plugin headers. Is this a WordPress plugin?', 'wporg-plugins' )
     
    369377    function check_block_tag() {
    370378        if ( empty( $this->readme->tags ) || ! in_array( 'block', array_map( 'strtolower', $this->readme->tags ) ) ) {
    371             $this->record_result( __FUNCTION__,
     379            $this->record_result(
     380                __FUNCTION__,
    372381                'warning',
    373                 __( 'No block tag found in readme.txt.', 'wporg-plugins' ),
     382                __( 'No "block" tag found in readme.txt.', 'wporg-plugins' ),
    374383                $this->readme->tags
    375384            );
    376385        } else {
    377             $this->record_result( __FUNCTION__,
     386            $this->record_result(
     387                __FUNCTION__,
    378388                'info',
    379                 __( 'Found a block tag in readme.txt.', 'wporg-plugins' ),
     389                __( 'Found the "block" tag in readme.txt.', 'wporg-plugins' ),
    380390                $this->readme->tags
    381391            );
     
    416426            }
    417427        }
    418 
    419428    }
    420429
     
    424433    function check_for_blocks() {
    425434        if ( 0 === count( $this->blocks ) ) {
    426             $this->record_result( __FUNCTION__,
     435            $this->record_result(
     436                __FUNCTION__,
    427437                'error',
    428438                __( 'No blocks found in plugin.', 'wporg-plugins' )
    429439            );
    430440        } else {
    431             $this->record_result( __FUNCTION__,
    432                 ( count( $this->blocks ) < 5 ? 'info' : 'warning' ), // 5+ blocks suggests it's probably not a block plugin
    433                 sprintf( _n( 'Found %d block.', 'Found %d blocks.', count( $this->blocks ), 'wporg-plugins' ), count( $this->blocks ) ),
     441            $this->record_result(
     442                __FUNCTION__,
     443                'info',
     444                sprintf(
     445                    // translators: %d number of blocks.
     446                    _n( 'Found %d block.', 'Found %d blocks.', count( $this->blocks ), 'wporg-plugins' ),
     447                    count( $this->blocks )
     448                ),
    434449                array_keys( $this->blocks )
    435450            );
     
    442457    function check_for_block_json() {
    443458        foreach ( $this->blocks as $block_name => $block_info ) {
    444             if ( !empty( $this->block_json_files[ $block_name ] ) ) {
    445                 $this->record_result( __FUNCTION__,
     459            if ( ! empty( $this->block_json_files[ $block_name ] ) ) {
     460                $this->record_result(
     461                    __FUNCTION__,
    446462                    'info',
    447                     sprintf( __( 'block.json file exists for block %s.', 'wporg-plugins' ), $block_name ),
     463                    // translators: %s is the block name.
     464                    sprintf( __( 'Found a block.json file for block %s.', 'wporg-plugins' ), '<code>' . $block_name . '</code>' ),
    448465                    $this->block_json_files[ $block_name ]
    449466                );
     
    452469
    453470        if ( empty( $this->block_json_files ) ) {
    454             $this->record_result( __FUNCTION__,
     471            $this->record_result(
     472                __FUNCTION__,
    455473                'warning',
    456474                __( 'No block.json files were found.', 'wporg-plugins' )
     
    466484
    467485        foreach ( $this->blocks as $block_name => $block_info ) {
    468             if ( !empty( $block_scripts[ $block_name ] ) ) {
    469                 $this->record_result( __FUNCTION__,
     486            if ( ! empty( $block_scripts[ $block_name ] ) ) {
     487                $this->record_result(
     488                    __FUNCTION__,
    470489                    'info',
    471                     sprintf( __( 'Scripts found for block %s.', 'wporg-plugins' ), $block_name ),
     490                    // translators: %s is the block name.
     491                    sprintf( __( 'Scripts found for block %s.', 'wporg-plugins' ), '<code>' . $block_name . '</code>' ),
    472492                    $block_scripts[ $block_name ]
    473493                );
    474494            } else {
    475                 $this->record_result( __FUNCTION__,
     495                $this->record_result(
     496                    __FUNCTION__,
    476497                    'warning',
    477                     sprintf( __( 'No scripts found for block %s.', 'wporg-plugins' ), $block_name ),
     498                    // translators: %s is the block name.
     499                    sprintf( __( 'No scripts found for block %s.', 'wporg-plugins' ), '<code>' . $block_name . '</code>' ),
    478500                    $block_name
    479501                );
     
    489511            foreach ( $scripts as $script ) {
    490512                if ( file_exists( $this->path_to_plugin . $script ) ) {
    491                     $this->record_result( __FUNCTION__,
     513                    $this->record_result(
     514                        __FUNCTION__,
    492515                        'info',
    493                         sprintf( __( 'Script file exists for block %s.', 'wporg-plugins' ), $block_name ),
     516                        // translators: %s is the block name.
     517                        sprintf( __( 'Script file exists for block %s.', 'wporg-plugins' ), '<code>' . $block_name . '</code>' ),
    494518                        $script
    495519                    );
    496520                } else {
    497                     $this->record_result( __FUNCTION__,
     521                    $this->record_result(
     522                        __FUNCTION__,
    498523                        'warning',
    499                         sprintf( __( 'Missing script file for block %s.', 'wporg-plugins' ), $block_name ),
     524                        // translators: %s is the block name.
     525                        sprintf( __( 'Missing script file for block %s.', 'wporg-plugins' ), '<code>' . $block_name . '</code>' ),
    500526                        $script
    501527                    );
     
    520546
    521547        if ( empty( $block_files ) ) {
    522             $this->record_result( __FUNCTION__,
     548            $this->record_result(
     549                __FUNCTION__,
    523550                'error',
    524551                sprintf( __( '<code>registerBlockType()</code> must be called in a JavaScript file.', 'wporg-plugins' ) )
     
    534561            if ( is_wp_error( $result ) ) {
    535562                if ( $message = $result->get_error_message( 'json_parse_error' ) ) {
    536                     $this->record_result( __FUNCTION__,
     563                    $this->record_result(
     564                        __FUNCTION__,
    537565                        'error',
    538                         sprintf( __( 'Error attempting to parse json in %s: %s', 'wporg-plugins' ), $this->relative_filename( $block_json_file ), $message ),
     566                        sprintf(
     567                            // translators: %1$s is the file name, %2$s is the json error message.
     568                            __( 'Error attempting to parse json in %1$s: %2$s', 'wporg-plugins' ),
     569                            '<code>' . $this->relative_filename( $block_json_file ) . '</code>',
     570                            $message
     571                        ),
    539572                        $this->relative_filename( $block_json_file )
    540573                    );
     
    550583        foreach ( $this->block_json_validation as $block_json_file => $result ) {
    551584            if ( true === $result ) {
    552                 $this->record_result( __FUNCTION__,
     585                $this->record_result(
     586                    __FUNCTION__,
    553587                    'info',
    554                     sprintf( __( 'JSON file %s is valid.', 'wporg-plugins' ), $this->relative_filename( $block_json_file ) ),
     588                    // translators: %s is the file name.
     589                    sprintf( __( 'JSON file %s is valid.', 'wporg-plugins' ), '<code>' . $this->relative_filename( $block_json_file ) . '</code>' ),
    555590                    $this->relative_filename( $block_json_file )
    556591                );
     
    564599                        continue; // Already handled in check_block_json_is_valid_json
    565600                    } else {
    566                         $this->record_result( __FUNCTION__,
     601                        $this->record_result(
     602                            __FUNCTION__,
    567603                            ( 'error' === $code ? 'warning' : $code ), // TODO: be smarter about mapping these
    568                             $this->relative_filename( $block_json_file ) . ': ' . $message,
     604                            '<code>' . $this->relative_filename( $block_json_file ) . '</code>: ' . $message,
    569605                            array(
    570606                                $this->relative_filename( $block_json_file ),
    571                                 $result->get_error_data( $code )
     607                                $result->get_error_data( $code ),
    572608                            )
    573609                        );
     
    590626
    591627        if ( 1 === $count ) {
    592             $this->record_result( __FUNCTION__,
     628            $this->record_result(
     629                __FUNCTION__,
    593630                'info',
    594                 sprintf( __( 'PHP asset file found: %s.', 'wporg-plugins' ), $this->relative_filename( $file ) ),
     631                // translators: %s is the name of asset file.
     632                sprintf(
     633                    __( 'PHP asset file found: %s.', 'wporg-plugins' ),
     634                    '<code>' . $this->relative_filename( $file ) . '</code>'
     635                ),
    595636                $this->relative_filename( $file )
    596637            );
    597638        } elseif ( $count > 1 ) {
    598             $this->record_result( __FUNCTION__,
     639            $this->record_result(
     640                __FUNCTION__,
    599641                'warning',
     642                // translators: %s is the number of asset files.
    600643                sprintf( __( 'Found %s PHP asset files.', 'wporg-plugins' ), $count ),
    601644                array_map( null, array( $this->relative_filename( $file ) ), $this->asset_php_files )
     
    614657        }
    615658        if ( $total_size > 50 * KB_IN_BYTES ) {
    616             $this->record_result( __FUNCTION__,
    617                 'error',
     659            $this->record_result(
     660                __FUNCTION__,
     661                'error',
     662                // translators: %s is the size of PHP code.
    618663                sprintf( __( 'Found %s of PHP code. Please submit PHP plugins to the plugin directory.', 'wporg-plugins' ), size_format( $total_size ) ),
    619664                $total_size
    620665            );
    621666        } elseif ( $total_size > 10 * KB_IN_BYTES ) {
    622             $this->record_result( __FUNCTION__,
     667            $this->record_result(
     668                __FUNCTION__,
    623669                'warning',
     670                // translators: %s is the size of PHP code.
    624671                sprintf( __( 'Found %s of PHP code. This might not be a block plugin.', 'wporg-plugins' ), size_format( $total_size ) ),
    625672                $total_size
    626673            );
    627674        } else {
    628             $this->record_result( __FUNCTION__,
     675            $this->record_result(
     676                __FUNCTION__,
    629677                'info',
     678                // translators: %s is the size of PHP code.
    630679                sprintf( __( 'Found %s of PHP code. Thanks for keeping it minimal!', 'wporg-plugins' ), size_format( $total_size ) ),
    631680                $total_size
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php

    r10036 r10038  
    1515
    1616        if ( is_user_logged_in() ) :
    17         ?>
    18         <div class="wrap">
    19             <form method="post" action=".">
    20                 <p>
    21                     <label for="plugin_url"><?php _e( 'Plugin repo URL', 'wporg-plugins' ); ?></label>
    22                 </p>
    23                 <p>
    24                     <input type="text" id="plugin_url" name="plugin_url" size="70" placeholder="https://plugins.svn.wordpress.org/" value="<?php echo esc_attr( $plugin_url ); ?>" />
    25                     <input type="submit" class="button button-secondary" value="<?php esc_attr_e( 'Validate!', 'wporg-plugins' ); ?>" />
     17            ?>
     18
     19        <div class="wrap block-validator">
     20            <form method="post" action="." class="block-validator__plugin-form">
     21                <label for="plugin_url"><?php _e( 'Plugin repo URL', 'wporg-plugins' ); ?></label>
     22                <div class="block-validator__plugin-input-container">
     23                    <input type="text" class="block-validator__plugin-input" id="plugin_url" name="plugin_url" placeholder="https://plugins.svn.wordpress.org/" value="<?php echo esc_attr( $plugin_url ); ?>" />
     24                    <input type="submit" class="button button-secondary block-validator__plugin-submit" value="<?php esc_attr_e( 'Validate!', 'wporg-plugins' ); ?>" />
    2625                    <?php wp_nonce_field( 'validate-block-plugin', 'block-nonce' ); ?>
    27                 </p>
     26                </div>
    2827            </form>
    2928
    3029            <?php
    31             if ( $_POST && !empty( $_POST['plugin_url'] ) && wp_verify_nonce( $_POST['block-nonce'], 'validate-block-plugin' ) ) {
     30            if ( $_POST && ! empty( $_POST['plugin_url'] ) && wp_verify_nonce( $_POST['block-nonce'], 'validate-block-plugin' ) ) {
    3231                self::validate_block( $_POST['plugin_url'] );
    33             } elseif ( $_POST && !empty( $_POST['block-directory-edit'] ) ) {
     32            } elseif ( $_POST && ! empty( $_POST['block-directory-edit'] ) ) {
    3433                $post = get_post( intval( $_POST['plugin-id'] ) );
    3534                if ( $post && wp_verify_nonce( $_POST['block-directory-nonce'], 'block-directory-edit-' . $post->ID ) ) {
     
    4948            ?>
    5049        </div>
    51         <?php else: ?>
    52         <div class="wrap">
     50        <?php else : ?>
     51        <div class="wrap block-validator">
    5352            <p><?php _e( 'Please log in to use the validator.', 'wporg-plugins' ); ?></p>
    5453        </div>
     
    123122            $output .= "<div class='notice notice-success notice-alt'>\n";
    124123            if ( $checker->slug && self::plugin_is_in_block_directory( $checker->slug ) ) {
    125                 $output .= __( 'No problems were found. This plugin is already in the Block Directory.', 'wporg-plugins' );
     124                $output .= '<p>' . __( 'No problems were found. This plugin is already in the Block Directory.', 'wporg-plugins' ) . '</p>';
    126125            } else {
    127                 $output .= __( 'No problems were found. Your plugin has passed the first step towards being included in the Block Directory.', 'wporg-plugins' );
     126                $output .= '<p>' . __( 'No problems were found. Your plugin has passed the first step towards being included in the Block Directory.', 'wporg-plugins' ) . '</p>';
    128127            }
    129128            $output .= "</div>\n";
     
    131130            $output .= '<h3>' . __( 'Problems were encountered', 'wporg-plugins' ) . '</h3>';
    132131            $output .= "<div class='notice notice-error notice-alt'>\n";
    133             $output .= __( 'Some problems were found. They need to be addressed before your plugin will work in the Block Directory.', 'wporg-plugins' );
     132            $output .= '<p>' . __( 'Some problems were found. They need to be addressed before your plugin will work in the Block Directory.', 'wporg-plugins' ) . '</p>';
    134133            $output .= "</div>\n";
    135134        }
Note: See TracChangeset for help on using the changeset viewer.