Changeset 5198
- Timestamp:
- 03/29/2017 07:11:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-code-import.php
r4223 r5198 2 2 namespace WordPressdotorg\Plugin_Directory\CLI\I18N; 3 3 4 use WordPressdotorg\Plugin_Directory\Readme\Parser; 4 5 use WordPressdotorg\Plugin_Directory\Tools\SVN; 5 6 use WordPressdotorg\Plugin_Directory\Tools\Filesystem; … … 93 94 */ 94 95 private function is_plugin_valid( $export_directory ) { 95 $error = new WP_Error();96 $ esc_export_directory = escapeshellarg( $export_directory);96 $error = new WP_Error(); 97 $readme = new Parser( $this->find_readme_file( $export_directory ) ); 97 98 98 // Check for a plugin text domain declaration and loading, grep recursively, not necessarily in plugin.php.99 $has_textdomain_header = shell_exec( 'grep -r -i --include "*.php" "Text Domain:" ' . $esc_export_directory );100 $has_load_plugin_textdomain = shell_exec( 'grep -r --include "*.php" "\bload_plugin_textdomain\b" ' . $esc_export_directory );99 // Whether plugin files should be checked for valid text domains. 100 if ( empty( $readme->requires ) || version_compare( $readme->requires, '4.6', '<' ) ) { 101 $esc_export_directory = escapeshellarg( $export_directory ); 101 102 102 if ( $has_textdomain_header ) { 103 $has_slug_as_textdomain_header = shell_exec( 'grep -r -i --include "*.php" "Text Domain:[[:blank:]]*' . trim( escapeshellarg( $this->plugin ), '\'' ) . '" ' . $esc_export_directory ); 104 if ( ! $has_slug_as_textdomain_header ) { 105 $error->add( 'wrong_textdomain', 'Wrong text domain in header.' ); 103 // Check for a plugin text domain declaration and loading, grep recursively, not necessarily in plugin.php. 104 $has_textdomain_header = shell_exec( 'grep -r -i --include "*.php" "Text Domain:" ' . $esc_export_directory ); 105 $has_load_plugin_textdomain = shell_exec( 'grep -r --include "*.php" "\bload_plugin_textdomain\b" ' . $esc_export_directory ); 106 107 if ( $has_textdomain_header ) { 108 $has_slug_as_textdomain_header = shell_exec( 'grep -r -i --include "*.php" "Text Domain:[[:blank:]]*' . trim( escapeshellarg( $this->plugin ), '\'' ) . '" ' . $esc_export_directory ); 109 110 if ( ! $has_slug_as_textdomain_header ) { 111 $error->add( 'wrong_textdomain', 'Wrong text domain in header.' ); 112 } 113 } else { 114 $error->add( 'missing_textdomain', 'Missing text domain in header.' ); 106 115 } 107 } else {108 $error->add( 'missing_textdomain', 'Missing text domain in header.' );109 }110 116 111 if ( ! $has_load_plugin_textdomain ) {112 $error->add( 'missing_load_plugin_textdomain', 'Missing load_plugin_textdomain().' );113 }117 if ( ! $has_load_plugin_textdomain ) { 118 $error->add( 'missing_load_plugin_textdomain', 'Missing load_plugin_textdomain().' ); 119 } 114 120 115 if ( $error->get_error_codes() ) { 116 return $error; 121 if ( $error->get_error_codes() ) { 122 return $error; 123 } 124 117 125 } 118 126 119 127 return true; 120 128 } 129 130 /** 131 * Find the plugin readme file. 132 * 133 * Looks for either a readme.txt or readme.md file, prioritizing readme.txt. 134 * 135 * @param string $directory 136 * @return string The plugin readme.txt or readme.md filename. 137 */ 138 private function find_readme_file( $directory ) { 139 $files = Filesystem::list_files( $directory, false /* non-recursive */, '!^readme\.(txt|md)$!i' ); 140 141 // Prioritize readme.txt 142 foreach ( $files as $file ) { 143 if ( '.txt' === strtolower( substr( $file, -4 ) ) ) { 144 return $file; 145 } 146 } 147 148 return reset( $files ); 149 } 121 150 }
Note: See TracChangeset
for help on using the changeset viewer.