WordPress.org

Make WordPress Core

Ticket #22515: 22515.diff

File 22515.diff, 3.4 KB (added by Otto42, 17 months ago)

move parent detection code up in the constructor

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

     
    238238                                return; 
    239239                        } 
    240240                } 
     241                 
     242                // Set the parent, if we're a child theme. 
     243                if ( $this->template != $this->stylesheet ) { 
     244                        // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. 
     245                        if ( is_a( $_child, 'WP_Theme' ) && $_child->template == $this->stylesheet ) { 
     246                                $_child->parent = null; 
     247                                $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) ); 
     248                                $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) ); 
     249                                // The two themes actually reference each other with the Template header. 
     250                                if ( $_child->stylesheet == $this->template ) { 
     251                                        $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $this->template ) ); 
     252                                        $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); 
     253                                } 
     254                                 
     255                                return; 
     256                        } 
     257                        // Set the parent. Pass the current instance so we can do the crazy checks above and assess errors. 
     258                        $this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this ); 
     259                }                
    241260 
    242261                // If we got our data from cache, we can assume that 'template' is pointing to the right place. 
    243262                if ( ! is_array( $cache ) && $this->template != $this->stylesheet && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) ) { 
     
    258277                        } 
    259278                } 
    260279 
    261                 // Set the parent, if we're a child theme. 
    262                 if ( $this->template != $this->stylesheet ) { 
    263                         // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. 
    264                         if ( is_a( $_child, 'WP_Theme' ) && $_child->template == $this->stylesheet ) { 
    265                                 $_child->parent = null; 
    266                                 $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) ); 
    267                                 $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) ); 
    268                                 // The two themes actually reference each other with the Template header. 
    269                                 if ( $_child->stylesheet == $this->template ) { 
    270                                         $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $this->template ) ); 
    271                                         $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); 
    272                                 } 
    273                                 return; 
    274                         } 
    275                         // Set the parent. Pass the current instance so we can do the crazy checks above and assess errors. 
    276                         $this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this ); 
    277                 } 
    278  
    279280                // We're good. If we didn't retrieve from cache, set it. 
    280281                if ( ! is_array( $cache ) ) { 
    281282                        $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template );