|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use WordPressdotorg\Plugin_Directory\Readme\Parser; |
4 | 3 | use WP_CLI\ParsePluginNameInput; |
5 | 4 | use WP_CLI\Utils; |
6 | 5 | use WP_CLI\WpOrgApi; |
7 | 6 |
|
| 7 | +use function WP_CLI\Utils\normalize_path; |
| 8 | + |
8 | 9 | /** |
9 | 10 | * Manages plugins, including installs, activations, and updates. |
10 | 11 | * |
@@ -747,12 +748,30 @@ protected function get_item_list() { |
747 | 748 | ]; |
748 | 749 |
|
749 | 750 | if ( $this->check_headers['tested_up_to'] ) { |
750 | | - // Include information from the plugin readme.txt headers. |
751 | | - $plugin_readme = WP_PLUGIN_DIR . '/' . $name . '/readme.txt'; |
| 751 | + $plugin_readme = normalize_path( WP_PLUGIN_DIR . '/' . $name . '/readme.txt' ); |
| 752 | + |
| 753 | + if ( file_exists( $plugin_readme ) && is_readable( $plugin_readme ) ) { |
| 754 | + $readme_obj = new SplFileObject( $plugin_readme ); |
| 755 | + $readme_obj->setFlags( SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY ); |
| 756 | + $readme_line = 0; |
| 757 | + |
| 758 | + // Reading the whole file can exhaust the memory, so only read the first 100 lines of the file, |
| 759 | + // as the "Tested up to" header should be near the top. |
| 760 | + while ( $readme_line < 100 && ! $readme_obj->eof() ) { |
| 761 | + $line = $readme_obj->fgets(); |
| 762 | + |
| 763 | + // Similar to WP.org, it matches for both "Tested up to" and "Tested" header in the readme file. |
| 764 | + preg_match( '/^tested(:| up to:) (.*)$/i', strtolower( $line ), $matches ); |
| 765 | + |
| 766 | + if ( isset( $matches[2] ) && ! empty( $matches[2] ) ) { |
| 767 | + $items[ $file ]['tested_up_to'] = $matches[2]; |
| 768 | + break; |
| 769 | + } |
| 770 | + |
| 771 | + ++$readme_line; |
| 772 | + } |
752 | 773 |
|
753 | | - if ( file_exists( $plugin_readme ) ) { |
754 | | - $readme_parser = new Parser( $plugin_readme ); |
755 | | - $items[ $file ]['tested_up_to'] = $readme_parser->tested ? $readme_parser->tested : ''; |
| 774 | + $file_obj = null; |
756 | 775 | } |
757 | 776 | } |
758 | 777 |
|
|
0 commit comments