Changeset 10971
- Timestamp:
- 05/13/2021 07:20:04 PM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r10726 r10971 297 297 /** 298 298 * Action that fires after a plugin is imported. 299 * 299 * 300 300 * @param WP_Post $plugin The plugin updated. 301 301 * @param string $stable_tag The new stable tag for the plugin. … … 680 680 * @return string The plugin readme.txt or readme.md filename. 681 681 */ 682 static function find_readme_file( $directory ) {682 public static function find_readme_file( $directory ) { 683 683 $files = Filesystem::list_files( $directory, false /* non-recursive */, '!(?:^|/)readme\.(txt|md)$!i' ); 684 684 … … 700 700 * @return object The plugin headers. 701 701 */ 702 static function find_plugin_headers( $directory ) {702 public static function find_plugin_headers( $directory ) { 703 703 $files = Filesystem::list_files( $directory, false, '!\.php$!i' ); 704 704 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-code-import.php
r7893 r10971 3 3 4 4 use Exception; 5 use WordPressdotorg\Plugin_Directory\CLI\Import; 5 6 use WordPressdotorg\Plugin_Directory\Readme\Parser; 6 7 use WordPressdotorg\Plugin_Directory\Tools\Filesystem; … … 86 87 */ 87 88 private function is_plugin_valid( $export_directory ) { 88 $readme = new Parser( $this->find_readme_file( $export_directory ) ); 89 $readme = new Parser( Import::find_readme_file( $export_directory ) ); 90 $requires = $readme->requires; 89 91 90 // Whether plugin files should be checked for valid text domains. 91 if ( empty( $readme->requires ) || version_compare( $readme->requires, '4.6', '<' ) ) { 92 // Prefer requires field from the plugin headers if set. 93 $headers = Import::find_plugin_headers( $export_directory ); 94 if ( $headers->RequiresWP && preg_match( '!^[\d.]{3,}$!', $headers->RequiresWP ) ) { 95 $requires = $headers->RequiresWP; 96 } 97 98 // Whether plugin files should be checked for valid text domain setup. 99 if ( empty( $requires ) || version_compare( $requires, '4.6', '<' ) ) { 92 100 $error = new WP_Error(); 93 101 $esc_export_directory = escapeshellarg( $export_directory ); … … 101 109 102 110 if ( ! $has_slug_as_textdomain_header ) { 103 $error->add( 'wrong_textdomain', ' Wrong text domain in header.' );111 $error->add( 'wrong_textdomain', 'Requires WordPress ' . ( $requires ?: 'n/a' ) . '; wrong text domain in header, expected `' . $this->plugin . '`.' ); 104 112 } 105 113 } else { 106 $error->add( 'missing_textdomain', ' Missing text domain in header.' );114 $error->add( 'missing_textdomain', 'Requires WordPress ' . ( $requires ?: 'n/a' ) . '; missing text domain in header.' ); 107 115 } 108 116 109 117 if ( ! $has_load_plugin_textdomain ) { 110 $error->add( 'missing_load_plugin_textdomain', ' Missing load_plugin_textdomain().' );118 $error->add( 'missing_load_plugin_textdomain', 'Requires WordPress ' . ( $requires ?: 'n/a' ) . '; missing load_plugin_textdomain() call.' ); 111 119 } 112 120 … … 118 126 return true; 119 127 } 120 121 /**122 * Find the plugin readme file.123 *124 * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.125 *126 * @param string $directory127 * @return string The plugin readme.txt or readme.md filename.128 */129 private function find_readme_file( $directory ) {130 $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' );131 132 // Prioritize readme.txt133 foreach ( $files as $file ) {134 if ( '.txt' === strtolower( substr( $file, -4 ) ) ) {135 return $file;136 }137 }138 139 return reset( $files );140 }141 128 }
Note: See TracChangeset
for help on using the changeset viewer.