]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-theme.php
WordPress 4.4.1
[autoinstalls/wordpress.git] / wp-includes / class-wp-theme.php
index ad70a4bf9e38f789819e2ac40b933c1401df1d9b..cf497f130f432e4c92f849090dd31fe23897ec97 100644 (file)
@@ -4,10 +4,21 @@
  *
  * @package WordPress
  * @subpackage Theme
+ * @since 3.4.0
  */
-
 final class WP_Theme implements ArrayAccess {
 
+       /**
+        * Whether the theme has been marked as updateable.
+        *
+        * @since 4.4.0
+        * @access public
+        * @var bool
+        *
+        * @see WP_MS_Themes_List_Table
+        */
+       public $update = false;
+
        /**
         * Headers for style.css files.
         *
@@ -45,6 +56,7 @@ final class WP_Theme implements ArrayAccess {
                'twentythirteen' => 'Twenty Thirteen',
                'twentyfourteen' => 'Twenty Fourteen',
                'twentyfifteen'  => 'Twenty Fifteen',
+               'twentysixteen'  => 'Twenty Sixteen',
        );
 
        /**
@@ -228,7 +240,7 @@ final class WP_Theme implements ArrayAccess {
                } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {
                        $this->headers['Name'] = $this->stylesheet;
                        if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) )
-                               $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), $this->stylesheet ) );
+                               $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) );
                        else
                                $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
                        $this->template = $this->stylesheet;
@@ -275,7 +287,7 @@ final class WP_Theme implements ArrayAccess {
                                $theme_root_template = $directories[ $this->template ]['theme_root'];
                        } else {
                                // Parent theme is missing.
-                               $this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), $this->template ) );
+                               $this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) );
                                $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
                                $this->parent = new WP_Theme( $this->template, $this->theme_root, $this );
                                return;
@@ -287,11 +299,11 @@ final class WP_Theme implements ArrayAccess {
                        // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out.
                        if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) {
                                $_child->parent = null;
-                               $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) );
+                               $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) );
                                $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) );
                                // The two themes actually reference each other with the Template header.
                                if ( $_child->stylesheet == $this->template ) {
-                                       $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $this->template ) );
+                                       $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) );
                                        $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
                                }
                                return;
@@ -1010,18 +1022,15 @@ final class WP_Theme implements ArrayAccess {
                /**
                 * Filter list of page templates for a theme.
                 *
-                * This filter does not currently allow for page templates to be added.
-                *
                 * @since 3.9.0
+                * @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
                 *
                 * @param array        $page_templates Array of page templates. Keys are filenames,
                 *                                     values are translated names.
                 * @param WP_Theme     $this           The theme object.
                 * @param WP_Post|null $post           The post being edited, provided for context, or null.
                 */
-               $return = apply_filters( 'theme_page_templates', $page_templates, $this, $post );
-
-               return array_intersect_assoc( $return, $page_templates );
+               return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post );
        }
 
        /**
@@ -1142,6 +1151,23 @@ final class WP_Theme implements ArrayAccess {
                return false;
        }
 
+       /**
+        * Determines the latest WordPress default theme that is installed.
+        *
+        * This hits the filesystem.
+        *
+        * @return WP_Theme|false Object, or false if no theme is installed, which would be bad.
+        */
+       public static function get_core_default_theme() {
+               foreach ( array_reverse( self::$default_themes ) as $slug => $name ) {
+                       $theme = wp_get_theme( $slug );
+                       if ( $theme->exists() ) {
+                               return $theme;
+                       }
+               }
+               return false;
+       }
+
        /**
         * Returns array of stylesheet names of themes allowed on the site or network.
         *