Making WordPress.org

Changeset 9994


Ignore:
Timestamp:
07/02/2020 07:27:51 AM (6 years ago)
Author:
tellyworth
Message:

Block plugin validator tool.

See also r9993.

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

Legend:

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

    r9911 r9994  
    576576                add_shortcode( 'wporg-plugins-reviews', array( __NAMESPACE__ . '\Shortcodes\Reviews', 'display' ) );
    577577                add_shortcode( 'readme-validator', array( __NAMESPACE__ . '\Shortcodes\Readme_Validator', 'display' ) );
     578                add_shortcode( 'block-validator', array( __NAMESPACE__ . '\Shortcodes\Block_Validator', 'display' ) );
    578579        }
    579580
    … …  
    591592                        'wporg-plugins-reviews',
    592593                        'readme-validator',
     594                        'block-validator',
    593595                );
    594596
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php

    r9993 r9994  
    141141
    142142                // Generate a unique tmp file directory name, but don't create it.
    143                 $path = Filesystem::temp_directory( '/tmp/blockplugin' );
     143                $path = Filesystem::temp_directory( 'blockplugin' );
    144144
    145145                $export = SVN::export( $svn_url, $path, array( 'ignore-externals', 'force' ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r9982 r9994  
    55use WordPressdotorg\Plugin_Directory\Jobs\API_Update_Updater;
    66use WordPressdotorg\Plugin_Directory\Jobs\Tide_Sync;
     7use WordPressdotorg\Plugin_Directory\Block_JSON;
    78use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    89use WordPressdotorg\Plugin_Directory\Readme\Parser;
    … …  
    568569         * @return string The plugin readme.txt or readme.md filename.
    569570         */
    570         protected function find_readme_file( $directory ) {
    571                 $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' );
     571        static function find_readme_file( $directory ) {
     572                $files = Filesystem::list_files( $directory, false /* non-recursive */, '!(?:^|/)readme\.(txt|md)$!i' );
    572573
    573574                // prioritize readme.txt
    … …  
    588589         * @return object The plugin headers.
    589590         */
    590         protected function find_plugin_headers( $directory ) {
     591        static function find_plugin_headers( $directory ) {
    591592                $files = Filesystem::list_files( $directory, false, '!\.php$!i' );
    592593
    … …  
    626627         * @return array An array of objects representing blocks, corresponding to the block.json format where possible.
    627628         */
    628         protected function find_blocks_in_file( $filename ) {
     629        static function find_blocks_in_file( $filename ) {
    629630
    630631                $ext = strtolower( pathinfo($filename, PATHINFO_EXTENSION) );
    … …  
    659660                }
    660661                if ( 'block.json' === basename( $filename ) ) {
    661                         // A block.json file has everything we want.
    662                         $blockinfo = json_decode( file_get_contents( $filename ) );
    663                         if ( isset( $blockinfo->name ) && isset( $blockinfo->title ) ) {
    664                                 $blocks[] = $blockinfo;
     662                        // A block.json file should have everything we want.
     663                        $validator = new Block_JSON\Validator();
     664                        $block     = Block_JSON\Parser::parse( array( 'file' => $filename ) );
     665                        $result    = $validator->validate( $block );
     666                        if ( ! is_wp_error( $block ) && is_wp_error( $result ) ) {
     667                                // Only certain properties must be valid for our purposes here.
     668                                $required_valid_props = array(
     669                                        'block.json',
     670                                        'block.json:editorScript',
     671                                        'block.json:editorStyle',
     672                                        'block.json:name',
     673                                        'block.json:script',
     674                                        'block.json:style',
     675                                );
     676                                $invalid_props = array_intersect( $required_valid_props, $result->get_error_data( 'error' ) );
     677                                if ( empty( $invalid_props ) ) {
     678                                        $blocks[] = $block;
     679                                }
     680                        } elseif ( true === $result ) {
     681                                $blocks[] = $block;
    665682                        }
    666683                }
    … …  
    677694         * @return array
    678695         */
    679         protected function extract_file_paths_from_block_json( $parsed_json, $block_json_path = '' ) {
     696        static function extract_file_paths_from_block_json( $parsed_json, $block_json_path = '' ) {
    680697                $files = array();
    681698
Note: See TracChangeset for help on using the changeset viewer.