From 58dc8ab25c3e2f939c557f690ffd10f00e5e690a Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 4 Mar 2014 21:06:48 +0000 Subject: [PATCH] i18n tools: Have makepot search for the main file of the plugin. props Otto42. fixes #25665. git-svn-id: https://develop.svn.wordpress.org/trunk@27399 602fd350-edb4-49c9-b593-d223f7449a82 --- tools/i18n/makepot.php | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/i18n/makepot.php b/tools/i18n/makepot.php index 0345c86d61..9351bc6c91 100644 --- a/tools/i18n/makepot.php +++ b/tools/i18n/makepot.php @@ -433,8 +433,44 @@ class MakePOT { if (is_null($slug)) { $slug = $this->guess_plugin_slug($dir); } - $main_file = $dir.'/'.$slug.'.php'; - $source = $this->get_first_lines($main_file, $this->max_header_lines); + + $plugins_dir = @opendir( $dir ); + $plugin_files = array(); + if ( $plugins_dir ) { + while ( ( $file = readdir( $plugins_dir ) ) !== false ) { + if ( '.' === substr( $file, 0, 1 ) ) { + continue; + } + + if ( '.php' === substr( $file, -4 ) ) { + $plugin_files[] = $file; + } + } + closedir( $plugins_dir ); + } + + if ( empty( $plugin_files ) ) { + return false; + } + + $main_file = ''; + foreach ( $plugin_files as $plugin_file ) { + if ( ! is_readable( "$dir/$plugin_file" ) ) { + continue; + } + + $source = $this->get_first_lines( "$dir/$plugin_file", $this->max_header_lines ); + + // Stop when we find a file with a plugin name header in it. + if ( $this->get_addon_header( 'Plugin Name', $source ) != false ) { + $main_file = "$dir/$plugin_file"; + break; + } + } + + if ( empty( $main_file ) ) { + return false; + } $placeholders['version'] = $this->get_addon_header('Version', $source); $placeholders['author'] = $this->get_addon_header('Author', $source);