WordPress.org

Make WordPress Core

Ticket #10814: 10814.diff

File 10814.diff, 2.6 KB (added by mdawaffe, 9 years ago)

better get_plugin_data() readability and patch for GUIDs

  • wp-admin/includes/plugin.php

     
    4343 *              'PluginURI' - Plugin web site address.
    4444 *              'TextDomain' - Plugin's text domain for localization.
    4545 *              'DomainPath' - Plugin's relative directory path to .mo files.
     46 *              'GUID' - Plugin's globally unique identifier
    4647 *
    4748 * Some users have issues with opening large files and manipulating the contents
    4849 * for want is usually the first 1kiB or 2kiB. This function stops pulling in
     
    7071        $fp = fopen($plugin_file, 'r');
    7172
    7273        // Pull only the first 8kiB of the file in.
    73         $plugin_data = fread( $fp, 8192 );
     74        $plugin_head = fread( $fp, 8192 );
    7475
    7576        // PHP will close file handle, but we are good citizens.
    7677        fclose($fp);
    7778
    78         preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name );
    79         preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri );
    80         preg_match( '|Version:(.*)|i', $plugin_data, $version );
    81         preg_match( '|Description:(.*)$|mi', $plugin_data, $description );
    82         preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name );
    83         preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );
    84         preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain );
    85         preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path );
     79        $data_keys = array(
     80                'Name' => 'Plugin Name', // |Plugin Name:(.*)$|mi
     81                'PluginURI' => 'Plugin URI',
     82                'Description' => 'Description',
     83                'Author' => 'Author',
     84                'AuthorURI' => 'Author URI',
     85                'Version' => 'Version',
     86                'TextDomain' => 'Text Domain',
     87                'DomainPath' => 'DomainPath',
     88                'GUID' => 'GUID',
     89        );
    8690
    87         foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) {
    88                 if ( !empty( ${$field} ) )
    89                         ${$field} = _cleanup_header_comment(${$field}[1]);
     91        $plugin_data = array();
     92        foreach ( $data_keys as $field => $preg ) {
     93                preg_match( "|$preg:(.*)\$|mi", $plugin_head, $match );
     94                if ( empty( $field ) )
     95                        $plugin_data[$field] = '';
    9096                else
    91                         ${$field} = '';
     97                        $plugin_data[$field] = _cleanup_header_comment( $match[1] );
    9298        }
    9399
    94         $plugin_data = array(
    95                                 'Name' => $name, 'Title' => $name, 'PluginURI' => $uri, 'Description' => $description,
    96                                 'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version,
    97                                 'TextDomain' => $text_domain, 'DomainPath' => $domain_path
    98                                 );
     100        $plugin_data['Title'] = $plugin_data['Name'];
     101
    99102        if ( $markup || $translate )
    100103                $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate);
    101104