Making WordPress.org

Ticket #5995: 5995.add_to_db.patch

File 5995.add_to_db.patch, 1.9 KB (added by dufresnesteven, 2 years ago)

This patch adds a meta value, _patterns, if theme.json is detected and "get_patterns" returns patterns.

  • theme-directory/class-wporg-themes-upload.php

     
    7676        public $theme;
    7777
    7878        /**
     79         * The uploaded theme.json.
     80         *
     81         * @var WP_Theme_JSON
     82         */
     83        public $theme_json = null;
     84
     85        /**
    7986         * The theme slug being uploaded.
    8087         *
    8188         * @var string
     
    370377                // We have a stylesheet, let's set up the theme, theme post, and author.
    371378                $this->theme = new WP_Theme( basename( dirname( $style_css ) ), dirname( dirname( $style_css ) ) );
    372379
     380                // Get Theme.json data if it exists
     381                $this->theme_json = $this->get_theme_json( $theme_files );
     382
    373383                // We need a screen shot. People love screen shots.
    374384                if ( ! $this->has_screenshot( $theme_files ) ) {
    375385                        $style_errors->add(
     
    12991309                        '_screenshot'   => $this->theme->screenshot,
    13001310                );
    13011311
     1312                if( ! empty( $this->theme_json ) && $this->theme_json->get_patterns() ) {
     1313                        $post_meta[ '_patterns' ] = $this->theme_json->get_patterns();
     1314                }
     1315
    13021316                // Store readme.txt data if present.
    13031317                foreach ( $this->readme as $field => $data ) {
    13041318                        $post_meta[ "_{$field}" ] = $data;
     
    18651879
    18661880                $send->send( '#themereview-firehose' );
    18671881        }
     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        }
    18681906}