Make WordPress Core


Ignore:
Timestamp:
03/02/2012 09:07:31 PM (14 years ago)
Author:
nacin
Message:

Use array_combine() in get_file_data() and avoid variable variables when an array is just fine. fixes #20126.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r20063 r20088  
    33733373    fclose( $fp );
    33743374
    3375     if ( $context != '' ) {
    3376         $extra_headers = apply_filters( "extra_{$context}_headers", array() );
    3377 
    3378         $extra_headers = array_flip( $extra_headers );
    3379         foreach( $extra_headers as $key=>$value ) {
    3380             $extra_headers[$key] = $key;
    3381         }
     3375    if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
     3376        $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
    33823377        $all_headers = array_merge( $extra_headers, (array) $default_headers );
    33833378    } else {
     
    33863381
    33873382    foreach ( $all_headers as $field => $regex ) {
    3388         preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
    3389         if ( !empty( ${$field} ) )
    3390             ${$field} = _cleanup_header_comment( ${$field}[1] );
     3383        if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] )
     3384            $all_headers[ $field ] = _cleanup_header_comment( $match[1] );
    33913385        else
    3392             ${$field} = '';
    3393     }
    3394 
    3395     $file_data = compact( array_keys( $all_headers ) );
    3396 
    3397     return $file_data;
     3386            $all_headers[ $field ] = '';
     3387    }
     3388
     3389    return $all_headers;
    33983390}
    33993391
Note: See TracChangeset for help on using the changeset viewer.