Make WordPress Core

Ticket #8964: 8964-3.diff

File 8964-3.diff, 2.7 KB (added by strider72, 16 years ago)

Better security than 8964.diff. Avoids plugins overwriting each other's headers by forcing key and value to be the same. Changes "plugin_headers" hook to "extra_plugin_headers"

  • wp-admin/includes/plugin.php

     
    6767 */
    6868function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {
    6969        // We don't need to write to the file, so just open for reading.
    70         $fp = fopen($plugin_file, 'r');
     70        $fp = fopen( $plugin_file, 'r' );
    7171
    7272        // Pull only the first 8kiB of the file in.
    7373        $plugin_data = fread( $fp, 8192 );
    7474
    7575        // PHP will close file handle, but we are good citizens.
    76         fclose($fp);
     76        fclose( $fp );
    7777
    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 );
     78        $default_headers = array(
     79                'Name' => 'Plugin Name',
     80                'PluginURI' => 'Plugin URI',
     81                'Version' => 'Version',
     82                'Description' => 'Description',
     83                'Author' => 'Author',
     84                'AuthorURI' => 'Author URI',
     85                'TextDomain' => 'Text Domain',
     86                'DomainPath' => 'Domain Path'
     87                );
     88        $extra_headers = apply_filters( 'extra_plugin_headers', array() );
    8689
    87         foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) {
     90        $extra_headers = array_flip( $extra_headers );
     91        foreach( $extra_headers as $key=>$value ) {
     92           $extra_headers[$key] = $key;
     93        }
     94
     95        $all_headers = array_merge($extra_headers, $default_headers);
     96       
     97        foreach ( $all_headers as $field => $regex ) {
     98                preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $plugin_data, ${$field});
    8899                if ( !empty( ${$field} ) )
    89                         ${$field} = _cleanup_header_comment(${$field}[1]);
     100                        ${$field} = _cleanup_header_comment( ${$field}[1] );
    90101                else
    91102                        ${$field} = '';
    92103        }
    93104
    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                                 );
     105        $plugin_data = compact( array_keys( $all_headers ) );
     106       
    99107        if ( $markup || $translate )
    100                 $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate);
     108                $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );
    101109
    102110        return $plugin_data;
    103111}