Changeset 8789 for sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php
- Timestamp:
- 05/14/2019 06:58:26 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php
r6940 r8789 64 64 65 65 /** 66 * The theme readme.txt data. 67 * 68 * @var array 69 */ 70 protected $readme; 71 72 /** 66 73 * Trac ticket information. 67 74 * … … 76 83 */ 77 84 protected $trac; 85 86 /** 87 * The list of headers to extract from readme.txt. 88 * 89 * @var array 90 */ 91 protected $readme_header_fields = array( 92 'tested' => 'tested up to', 93 'requires' => 'requires at least', 94 'requires_php' => 'requires php', 95 'readme_tags' => 'tags', 96 'contributors' => 'contributors', 97 'license' => 'license', 98 'license_uri' => 'license uri', 99 ); 78 100 79 101 /** … … 108 130 ); 109 131 } 132 133 // Do we have a readme.txt? Fetch extra data from there too. 134 $this->readme = $this->get_readme_data( $theme_files ); 110 135 111 136 // We have a stylesheet, let's set up the theme, theme post, and author. … … 371 396 372 397 return (string) array_pop( $stylesheets ); 398 } 399 400 /** 401 * Find the first readme.txt file, and extract it's headers. 402 * 403 * @param array $theme_files The theme files. 404 * @return array Array of headers if present. 405 */ 406 public function get_readme_data( $theme_files ) { 407 $readmes = preg_grep( '/readme.txt/i', $theme_files ); 408 usort( $readmes, array( $this, 'sort_by_string_length' ) ); 409 410 if ( ! $readmes ) { 411 return array(); 412 } 413 414 $readme_txt = (string) array_pop( $readmes ); 415 416 // WARNING: This function call will be changed in the future to a readme parser. 417 $data = get_file_data( $readme_txt, $this->readme_header_fields ); 418 $data = array_filter( $data, 'strlen' ); 419 420 // Sanitize Contributors down to a user_nicename 421 if ( isset( $data['contributors'] ) ) { 422 $data['contributors'] = explode( ',', $data['contributors'] ); 423 $data['contributors'] = array_map( 'trim', $data['contributors'] ); 424 foreach ( $data['contributors'] as $i => $name ) { 425 $user = get_user_by( 'login', $name ) ?: get_user_by( 'slug', $name ); 426 427 if ( $user ) { 428 $data['contributors'][ $i ] = $user->user_nicename; 429 } else { 430 unset( $data['contributors'][ $i ] ); 431 } 432 } 433 434 if ( ! $data['contributors'] ) { 435 unset( $data['contributors'] ); 436 } 437 } 438 439 return $data; 373 440 } 374 441 … … 724 791 725 792 // Finally, add post meta. 726 $post_meta 793 $post_meta = array( 727 794 '_theme_url' => $this->theme->get( 'ThemeURI' ), 728 795 '_author_url' => $this->theme->get( 'AuthorURI' ), … … 731 798 '_screenshot' => $this->theme->screenshot, 732 799 ); 800 801 // Store readme.txt data if present. 802 foreach ( $this->readme as $field => $data ) { 803 $post_meta[ "_{$field}" ] = $data; 804 } 733 805 734 806 foreach ( $post_meta as $meta_key => $meta_value ) {
Note: See TracChangeset
for help on using the changeset viewer.