Changeset 9994 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
- Timestamp:
- 07/02/2020 07:27:51 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r9982 r9994 5 5 use WordPressdotorg\Plugin_Directory\Jobs\API_Update_Updater; 6 6 use WordPressdotorg\Plugin_Directory\Jobs\Tide_Sync; 7 use WordPressdotorg\Plugin_Directory\Block_JSON; 7 8 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 8 9 use WordPressdotorg\Plugin_Directory\Readme\Parser; … … 568 569 * @return string The plugin readme.txt or readme.md filename. 569 570 */ 570 protectedfunction 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' ); 572 573 573 574 // prioritize readme.txt … … 588 589 * @return object The plugin headers. 589 590 */ 590 protectedfunction find_plugin_headers( $directory ) {591 static function find_plugin_headers( $directory ) { 591 592 $files = Filesystem::list_files( $directory, false, '!\.php$!i' ); 592 593 … … 626 627 * @return array An array of objects representing blocks, corresponding to the block.json format where possible. 627 628 */ 628 protectedfunction find_blocks_in_file( $filename ) {629 static function find_blocks_in_file( $filename ) { 629 630 630 631 $ext = strtolower( pathinfo($filename, PATHINFO_EXTENSION) ); … … 659 660 } 660 661 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; 665 682 } 666 683 } … … 677 694 * @return array 678 695 */ 679 protectedfunction 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 = '' ) { 680 697 $files = array(); 681 698
Note: See TracChangeset
for help on using the changeset viewer.