Making WordPress.org


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

File:
1 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     */
Note: See TracChangeset for help on using the changeset viewer.