From 9d4099ab2c6fe33d2c3e64763e574b479f6dd9e5 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 17 Jul 2008 22:51:26 +0000 Subject: [PATCH] Plugin metadata localization and get_plugin_dta() optimization from santosj. fixes #5651 #3089 git-svn-id: https://develop.svn.wordpress.org/trunk@8367 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/plugin.php | 132 ++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 2822dac218..a733ede8cf 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -1,7 +1,117 @@ + * /* + * Plugin Name: Name of Plugin + * Plugin URI: Link to plugin information + * Description: Plugin Description + * Author: Plugin author's name + * Author URI: Link to the author's web site + * Version: Must be set in the plugin for WordPress 2.3+ + * Text Domain: Optional. Unique identifier, should be same as the one used in + * plugin_text_domain() + * Domain Path: Optional. Only useful if the translations are located in a folder + * above the plugin's base path. For example, if .mo files are located in + * the locale folder then Domain Path will be "/locale/" and must have the + * first slash. Defaults to the base folder the plugin is located in. + * * / # Remove the space to close comment + * + * + * Plugin data returned array contains the following: + * 'Name' - Name of the plugin, must be unique. + * 'Title' - Title of the plugin and the link to the plugin's web site. + * 'Description' - Description of what the plugin does and/or notes + * from the author. + * 'Author' - The author's name and web site link. + * 'Version' - The plugin version number. + * + * @param string $plugin_file Path to the plugin file + * @return array See above for description. + */ function get_plugin_data( $plugin_file ) { - $plugin_data = implode( '', file( $plugin_file )); + $plugin_data = plugin_get_contents( $plugin_file ); preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $plugin_name ); preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $plugin_uri ); preg_match( '|Description:(.*)$|mi', $plugin_data, $description ); @@ -13,6 +123,26 @@ function get_plugin_data( $plugin_file ) { else $version = ''; + if( preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain ) ) { + if( preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path ) ) + $domain_path = trim( $domain_path[1] ); + + $text_domain = trim( $text_domain[1] ); + + if( !empty( $text_domain ) ) { + if( !empty( $domain_path ) ) + load_plugin_textdomain($text_domain, dirname($plugin_file). $domain_path); + else + load_plugin_textdomain($text_domain, dirname($plugin_file)); + } + + $description[1] = translate(trim($description[1]), $text_domain); + $plugin_name[1] = translate(trim($plugin_name[1]), $text_domain); + $plugin_uri[1] = translate(trim($plugin_uri[1]), $text_domain); + $author_name[1] = translate(trim($author_name[1]), $text_domain); + $author_uri[1] = translate(trim($author_uri[1]), $text_domain); + } + $description = wptexturize( trim( $description[1] )); $name = $plugin_name[1];