Ticket #5995: 5995.add_to_db.patch
File 5995.add_to_db.patch, 1.9 KB (added by , 2 years ago) |
---|
-
theme-directory/class-wporg-themes-upload.php
76 76 public $theme; 77 77 78 78 /** 79 * The uploaded theme.json. 80 * 81 * @var WP_Theme_JSON 82 */ 83 public $theme_json = null; 84 85 /** 79 86 * The theme slug being uploaded. 80 87 * 81 88 * @var string … … 370 377 // We have a stylesheet, let's set up the theme, theme post, and author. 371 378 $this->theme = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) ); 372 379 380 // Get Theme.json data if it exists 381 $this->theme_json = $this->get_theme_json( $theme_files ); 382 373 383 // We need a screen shot. People love screen shots. 374 384 if ( ! $this->has_screenshot( $theme_files ) ) { 375 385 $style_errors->add( … … 1299 1309 '_screenshot' => $this->theme->screenshot, 1300 1310 ); 1301 1311 1312 if( ! empty( $this->theme_json ) && $this->theme_json->get_patterns() ) { 1313 $post_meta[ '_patterns' ] = $this->theme_json->get_patterns(); 1314 } 1315 1302 1316 // Store readme.txt data if present. 1303 1317 foreach ( $this->readme as $field => $data ) { 1304 1318 $post_meta[ "_{$field}" ] = $data; … … 1865 1879 1866 1880 $send->send( '#themereview-firehose' ); 1867 1881 } 1882 1883 /** 1884 * Returns WP_THEME_JSON information if it exists. 1885 * 1886 * @return WP_Theme_JSON|null 1887 */ 1888 public function get_theme_json( $theme_files ) { 1889 $theme_json = preg_grep( '/theme.json/i', $theme_files ); 1890 usort( $theme_json, array( $this, 'sort_by_string_length' ) ); 1891 1892 if ( ! $theme_json ) { 1893 return null; 1894 } 1895 1896 $file_path = (string) array_pop( $theme_json ); 1897 1898 $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) ); 1899 1900 if( ! is_array( $decoded_file ) ) { 1901 return null; 1902 } 1903 1904 return new WP_Theme_JSON( $decoded_file, 'default' ); 1905 } 1868 1906 }