Make WordPress Core


Ignore:
Timestamp:
10/15/2009 09:07:00 PM (14 years ago)
Author:
westi
Message:

Allow for plugins to enhance the number of metadata fields captured from plugin and theme headers. See #8964 props strider72.

File:
1 edited

Legend:

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

    r12043 r12044  
    171171 */
    172172function get_theme_data( $theme_file ) {
     173    $default_headers = array(
     174        'Name' => 'Theme Name',
     175        'URI' => 'Theme URI',
     176        'Description' => 'Description',
     177        'Author' => 'Author',
     178        'AuthorURI' => 'Author URI',
     179        'Version' => 'Version',
     180        'Template' => 'Template',
     181        'Status' => 'Status',
     182        'Tags' => 'Tags'
     183        );
     184
    173185    $themes_allowed_tags = array(
    174186        'a' => array(
     
    186198    );
    187199
    188     $theme_data = implode( '', file( $theme_file ) );
    189     $theme_data = str_replace ( '\r', '\n', $theme_data );
    190     if ( preg_match( '|Theme Name:(.*)$|mi', $theme_data, $theme_name ) )
    191         $name = $theme = wp_kses( _cleanup_header_comment($theme_name[1]), $themes_allowed_tags );
     200    $theme_data = get_file_data( $theme_file, $default_headers, 'theme' );
     201
     202    $theme_data['Name'] = $theme_data['Title'] = wp_kses( $theme_data['Name'], $themes_allowed_tags );
     203
     204    $theme_data['URI'] = esc_url( $theme_data['URI'] );
     205
     206    $theme_data['Description'] = wptexturize( wp_kses( $theme_data['Description'], $themes_allowed_tags ) );
     207
     208    $theme_data['AuthorURI'] = esc_url( $theme_data['AuthorURI'] );
     209
     210    $theme_data['Template'] = wp_kses( $theme_data['Template'], $themes_allowed_tags );
     211
     212    $theme_data['Version'] = wp_kses( $theme_data['Version'], $themes_allowed_tags );
     213
     214    if ( $theme_data['Status'] == '' )
     215        $theme_data['Status'] = 'publish';
    192216    else
    193         $name = $theme = '';
    194 
    195     if ( preg_match( '|Theme URI:(.*)$|mi', $theme_data, $theme_uri ) )
    196         $theme_uri = esc_url( _cleanup_header_comment($theme_uri[1]) );
     217        $theme_data['Status'] = wp_kses( $theme_data['Status'], $themes_allowed_tags );
     218
     219    if ( $theme_data['Tags'] == '' )
     220        $theme_data['Tags'] = array();
    197221    else
    198         $theme_uri = '';
    199 
    200     if ( preg_match( '|Description:(.*)$|mi', $theme_data, $description ) )
    201         $description = wptexturize( wp_kses( _cleanup_header_comment($description[1]), $themes_allowed_tags ) );
    202     else
    203         $description = '';
    204 
    205     if ( preg_match( '|Author URI:(.*)$|mi', $theme_data, $author_uri ) )
    206         $author_uri = esc_url( _cleanup_header_comment($author_uri[1]) );
    207     else
    208         $author_uri = '';
    209 
    210     if ( preg_match( '|Template:(.*)$|mi', $theme_data, $template ) )
    211         $template = wp_kses( _cleanup_header_comment($template[1]), $themes_allowed_tags );
    212     else
    213         $template = '';
    214 
    215     if ( preg_match( '|Version:(.*)|i', $theme_data, $version ) )
    216         $version = wp_kses( _cleanup_header_comment($version[1]), $themes_allowed_tags );
    217     else
    218         $version = '';
    219 
    220     if ( preg_match('|Status:(.*)|i', $theme_data, $status) )
    221         $status = wp_kses( _cleanup_header_comment($status[1]), $themes_allowed_tags );
    222     else
    223         $status = 'publish';
    224 
    225     if ( preg_match('|Tags:(.*)|i', $theme_data, $tags) )
    226         $tags = array_map( 'trim', explode( ',', wp_kses( _cleanup_header_comment($tags[1]), array() ) ) );
    227     else
    228         $tags = array();
    229 
    230     if ( preg_match( '|Author:(.*)$|mi', $theme_data, $author_name ) ) {
    231         if ( empty( $author_uri ) ) {
    232             $author = wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags );
     222        $theme_data['Tags'] = array_map( 'trim', explode( ',', wp_kses( $theme_data['Tags'], array() ) ) );
     223
     224    if ( $theme_data['Author'] == '' ) {
     225        $theme_data['Author'] = __('Anonymous');
     226    } else {
     227        if ( empty( $theme_data['AuthorURI'] ) ) {
     228            $theme_data['Author'] = wp_kses( $theme_data['Author'], $themes_allowed_tags );
    233229        } else {
    234             $author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $author_uri, __( 'Visit author homepage' ), wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags ) );
     230            $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], __( 'Visit author homepage' ), wp_kses( $theme_data['Author'], $themes_allowed_tags ) );
    235231        }
    236     } else {
    237         $author = __('Anonymous');
    238232    }
    239233
    240     return array( 'Name' => $name, 'Title' => $theme, 'URI' => $theme_uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status, 'Tags' => $tags );
     234    return $theme_data;
    241235}
    242236
Note: See TracChangeset for help on using the changeset viewer.