Changeset 10101
- Timestamp:
- 07/27/2020 09:09:56 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php
r10090 r10101 38 38 protected $block_json_validation = array(); 39 39 protected $block_assets = array(); 40 protected $block_scripts = array();41 40 protected $php_function_calls = array(); 42 41 … … 265 264 266 265 $this->block_assets = $this->find_block_assets( $this->path_to_plugin ); 267 $this->block_scripts = $this->find_block_scripts( $this->path_to_plugin );268 266 269 267 $this->php_function_calls = $this->find_php_functions( $this->path_to_plugin ); … … 326 324 327 325 return $block_assets; 328 }329 330 public function find_block_scripts( $base_dir ) {331 332 $block_scripts = \array_map(333 function( $block ) {334 $assets = array();335 $props = array( 'editorScript', 'script', 'editorStyle', 'style' );336 337 foreach ( $props as $prop ) {338 if ( isset( $block->$prop ) ) {339 $assets[ $prop ] = $block->$prop;340 }341 }342 343 // If no block.json data was found, try to guess.344 if ( empty( $assets ) ) {345 // If js or css assets were found, assume we can use the first one.346 if ( !empty( $this->block_assets[ 'js' ] ) ) {347 $assets[ 'script' ] = reset( $this->block_assets[ 'js' ] );348 }349 350 if ( !empty( $this->block_assets[ 'css' ] ) ) {351 $assets[ 'style' ] = reset( $this->block_assets[ 'css' ] );352 }353 }354 return $assets;355 },356 $this->blocks357 );358 359 return $block_scripts;360 326 } 361 327 … … 684 650 */ 685 651 function check_for_block_script_files() { 686 $seen_scripts = array(); 687 foreach ( $this->block_scripts as $block_name => $scripts ) { 688 foreach ( $scripts as $kind => $script ) { 689 // No need to warn multiple times for the same value. 690 if ( in_array( $script, $seen_scripts ) ) { 691 continue; 692 } 693 $seen_scripts[] = $script; 694 $file_path = trailingslashit( $this->path_to_plugin ) . str_replace( 'file:', '', $script ); 652 foreach ( $this->block_assets as $kind => $scripts ) { 653 foreach ( $scripts as $script ) { 654 $file_path = trailingslashit( $this->path_to_plugin ) . $script; 695 655 if ( file_exists( $file_path ) ) { 696 656 $this->record_result( … … 704 664 // translators: %s is the file name. 705 665 $message = __( 'Expected %s to be a valid file path.', 'wporg-plugins' ); 706 if ( in_array( $kind, array( 'editorScript', 'script' ) )) {666 if ( 'js' === $kind ) { 707 667 // translators: %s is the file name. 708 668 $message = __( 'Expected %s to be a valid JavaScript file path.', 'wporg-plugins' ); 709 } else if ( in_array( $kind, array( 'editorStyle', 'style' ) )) {669 } else if ( 'css' === $kind ) { 710 670 // translators: %s is the file name. 711 671 $message = __( 'Expected %s to be a valid CSS file path.', 'wporg-plugins' );
Note: See TracChangeset
for help on using the changeset viewer.