Making WordPress.org

Changeset 10111


Ignore:
Timestamp:
08/03/2020 05:12:17 PM (4 years ago)
Author:
ryelle
Message:

Plugin Directory: Add a total size check for block plugins

This will trigger a warning if the total size of the plugin exceeds 1MB. A larger plugin will cause a longer wait when inserting into the editor, which degrades the user experience.

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

    r10110 r10111  
    826826
    827827    /**
     828     * File size check for downloads.
     829     */
     830    function check_total_size() {
     831        $files = Filesystem::list_files( $this->path_to_plugin, true );
     832        $total_size = 0;
     833        foreach ( $files as $file ) {
     834            $total_size += filesize( $file );
     835        }
     836        if ( $total_size > 1 * MB_IN_BYTES ) {
     837            $this->record_result(
     838                __FUNCTION__,
     839                'warning',
     840                // translators: %s is the file size.
     841                sprintf( __( 'Plugin size is %s.', 'wporg-plugins' ), size_format( $total_size ) ),
     842                $total_size
     843            );
     844        }
     845    }
     846
     847    /**
    828848     * Check that the plugin uses `wp_set_script_translations`.
    829849     */
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php

    r10110 r10111  
    324324                    'https://developer.wordpress.org/block-editor/developers/internationalization/'
    325325                );
     326            case 'check_total_size':
     327                return __( 'Larger plugins will take longer to install. This is more noticeable in the Block Directory, where the user expects blocks to be added immediately. Try reducing your file size by optimizing images & SVGs, only including the assets you need (images, fonts, etc), and using core-provided JavaScript libraries.', 'wporg-plugins' );
    326328            // This is a special case, since multiple values may be collapsed.
    327329            case 'check_block_json_is_valid':
Note: See TracChangeset for help on using the changeset viewer.