Ticket #22856: 22856.4.diff

File 22856.4.diff, 1.5 KB (added by dd32, 5 months ago)

Make WP_Theme recognise an empty theme directory is not a valid theme existance

  • wp-includes/class-wp-theme.php

     
    206206                        $this->headers['Name'] = $this->stylesheet; 
    207207                        if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) 
    208208                                $this->errors = new WP_Error( 'theme_not_found', __( 'The theme directory does not exist.' ) ); 
     209                        elseif ( ! glob( $this->theme_root . '/' . $this->stylesheet . '/*' ) ) 
     210                                $this->errors = new WP_Error( 'theme_no_files', __( 'The theme directory does not contain a theme.' ) ); 
    209211                        else 
    210212                                $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); 
    211213                        $this->template = $this->stylesheet; 
     
    441443         * Whether the theme exists. 
    442444         * 
    443445         * A theme with errors exists. A theme with the error of 'theme_not_found', 
    444          * meaning that the theme's directory was not found, does not exist. 
     446         * or 'theme_no_files' meaning that the theme's directory was not found, or 
     447         * doesn't contain any files, does not exist. 
    445448         * 
    446449         * @since 3.4.0 
    447450         * @access public 
     
    449452         * @return bool Whether the theme exists. 
    450453         */ 
    451454        public function exists() { 
    452                 return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes() ) ); 
     455                return ! ( $this->errors() && array_intersect( array( 'theme_not_found', 'theme_no_files' ), $this->errors()->get_error_codes() ) ); 
    453456        } 
    454457 
    455458        /**