<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20586] trunk/wp-includes/class-wp-theme.php: Documentation and visibility cleanups in WP_Theme.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20586">20586</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-04-25 16:37:49 +0000 (Wed, 25 Apr 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Documentation and visibility cleanups in WP_Theme.
 * Declare `__toString()` as public.
 * Use parent() and error() internally, rather than the properties.
 * Add and correct inline documentation throughout.
 * Attempt to clarify that display() is superior to get().
see <a href="http://core.trac.wordpress.org/ticket/20546">#20546</a>, see <a href="http://core.trac.wordpress.org/ticket/20103">#20103</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclasswpthemephp">trunk/wp-includes/class-wp-theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclasswpthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-theme.php (20585 => 20586)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-theme.php        2012-04-25 16:04:51 UTC (rev 20585)
+++ trunk/wp-includes/class-wp-theme.php        2012-04-25 16:37:49 UTC (rev 20586)
</span><span class="lines">@@ -290,7 +290,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return string Theme name, ready for display (translated)
</span><span class="cx">          */
</span><del>-        function __toString() {
</del><ins>+        public function __toString() {
</ins><span class="cx">                 return (string) $this-&gt;display('Name');
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -317,7 +317,7 @@
</span><span class="cx">                         case 'version' :
</span><span class="cx">                                 return $this-&gt;get('Version');
</span><span class="cx">                         case 'parent_theme' :
</span><del>-                                return $this-&gt;parent ? $this-&gt;parent-&gt;get('Name') : '';
</del><ins>+                                return $this-&gt;parent() ? $this-&gt;parent()-&gt;get('Name') : '';
</ins><span class="cx">                         case 'template_dir' :
</span><span class="cx">                                 return $this-&gt;get_template_directory();
</span><span class="cx">                         case 'stylesheet_dir' :
</span><span class="lines">@@ -369,20 +369,22 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Method to implement ArrayAccess for keys formerly returned by get_themes()
</del><ins>+         * Method to implement ArrayAccess for keys formerly returned by get_themes().
+         *
+         * Author, Author Name, Author URI, and Description did not previously return
+         * translated data. We are doing so now as it is safe to do. However, as 
+         * Name and Title could have been used as the key for get_themes(), both remain
+         * untranslated for back compatibility. This means that ['Name'] is not ideal,
+         * and care should be taken to use $theme-&gt;display('Name') to get a properly
+         * translated header.
</ins><span class="cx">          */
</span><span class="cx">         public function offsetGet( $offset ) {
</span><span class="cx">                 switch ( $offset ) {
</span><span class="cx">                         case 'Name' :
</span><del>-                        case 'Version' :
-                        case 'Status' :
-                                return $this-&gt;get( $offset );
</del><span class="cx">                         case 'Title' :
</span><ins>+                                // See note above about using translated data. get() is not ideal.
+                                // It is only for backwards compatibility. Use display().
</ins><span class="cx">                                 return $this-&gt;get('Name');
</span><del>-                        // Author, Author Name, Author URI, and Description did not
-                        // previously return translated data. We are doing so now.
-                        // Title and Name could have been used as the key for get_themes(),
-                        // so both to remain untranslated for back compatibility.
</del><span class="cx">                         case 'Author' :
</span><span class="cx">                                 return $this-&gt;display( 'Author');
</span><span class="cx">                         case 'Author Name' :
</span><span class="lines">@@ -391,6 +393,9 @@
</span><span class="cx">                                 return $this-&gt;display('AuthorURI');
</span><span class="cx">                         case 'Description' :
</span><span class="cx">                                 return $this-&gt;display( 'Description');
</span><ins>+                        case 'Version' :
+                        case 'Status' :
+                                return $this-&gt;get( $offset );
</ins><span class="cx">                         case 'Template' :
</span><span class="cx">                                 return $this-&gt;get_template();
</span><span class="cx">                         case 'Stylesheet' :
</span><span class="lines">@@ -418,7 +423,7 @@
</span><span class="cx">                         case 'Theme Root URI' :
</span><span class="cx">                                 return $this-&gt;get_theme_root_uri();
</span><span class="cx">                         case 'Parent Theme' :
</span><del>-                                return $this-&gt;parent ? $this-&gt;parent-&gt;get('Name') : '';
</del><ins>+                                return $this-&gt;parent() ? $this-&gt;parent()-&gt;get('Name') : '';
</ins><span class="cx">                         default :
</span><span class="cx">                                 return null;
</span><span class="cx">                 }
</span><span class="lines">@@ -440,7 +445,7 @@
</span><span class="cx">          * Whether the theme exists.
</span><span class="cx">          *
</span><span class="cx">          * A theme with errors exists. A theme with the error of 'theme_not_found',
</span><del>-         * meaning that the theme directory was not found, does not exist.
</del><ins>+         * meaning that the theme's directory was not found, does not exist.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          * @access public
</span><span class="lines">@@ -448,7 +453,7 @@
</span><span class="cx">          * @return bool Whether the theme exists.
</span><span class="cx">          */
</span><span class="cx">         public function exists() {
</span><del>-                return ! ( is_wp_error( $this-&gt;errors ) &amp;&amp; in_array( 'theme_not_found', $this-&gt;errors-&gt;get_error_codes() ) );
</del><ins>+                return ! ( $this-&gt;errors() &amp;&amp; in_array( 'theme_not_found', $this-&gt;errors()-&gt;get_error_codes() ) );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -509,14 +514,20 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Gets a theme header.
</del><ins>+         * Get a raw, unformatted theme header.
</ins><span class="cx">          *
</span><del>-         * The header is sanitized.
</del><ins>+         * The header is sanitized, but is not translated, and is not marked up for display.
+         * To get a theme header for display, use the display() method.
</ins><span class="cx">          *
</span><ins>+         * Use the get_template() method, not the 'Template' header, for finding the template.
+         * The 'Template' header is only good for what was written in the style.css, while
+         * get_template() takes into account where WordPress actually located the theme and
+         * whether it is actually valid.
+         *
</ins><span class="cx">          * @access public
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          *
</span><del>-         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status.
</del><ins>+         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
</ins><span class="cx">          * @return string String on success, false on failure.
</span><span class="cx">          */
</span><span class="cx">         public function get( $header ) {
</span><span class="lines">@@ -545,12 +556,12 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Gets a theme header ready for display (marked up, translated).
</del><ins>+         * Gets a theme header, formatted and translated for display.
</ins><span class="cx">          *
</span><span class="cx">          * @access public
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          *
</span><del>-         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status.
</del><ins>+         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
</ins><span class="cx">          * @param bool $markup Optional. Whether to mark up the header. Defaults to true.
</span><span class="cx">          * @param bool $translate Optional. Whether to translate the header. Defaults to true.
</span><span class="cx">          * @return string Processed header, false on failure.
</span><span class="lines">@@ -573,7 +584,7 @@
</span><span class="cx">         /**
</span><span class="cx">          * Sanitize a theme header.
</span><span class="cx">          *
</span><del>-         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status.
</del><ins>+         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
</ins><span class="cx">          * @param string $value Value to sanitize.
</span><span class="cx">          */
</span><span class="cx">         private function sanitize_header( $header, $value ) {
</span><span class="lines">@@ -625,7 +636,7 @@
</span><span class="cx">          * @access private
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          *
</span><del>-         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status.
</del><ins>+         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
</ins><span class="cx">          * @param string $value Value to mark up.
</span><span class="cx">          * @param string $translate Whether the header has been translated.
</span><span class="cx">          * @return string Value, marked up.
</span><span class="lines">@@ -672,7 +683,7 @@
</span><span class="cx">          * @access private
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          *
</span><del>-         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status.
</del><ins>+         * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
</ins><span class="cx">          * @param string $value Value to translate.
</span><span class="cx">          * @return string Translated value.
</span><span class="cx">          */
</span><span class="lines">@@ -763,7 +774,7 @@
</span><span class="cx">          * @return string Absolute path of the stylesheet directory.
</span><span class="cx">          */
</span><span class="cx">         public function get_stylesheet_directory() {
</span><del>-                if ( $this-&gt;errors &amp;&amp; in_array( 'theme_root_missing', $this-&gt;errors-&gt;get_error_codes() ) )
</del><ins>+                if ( $this-&gt;errors() &amp;&amp; in_array( 'theme_root_missing', $this-&gt;errors()-&gt;get_error_codes() ) )
</ins><span class="cx">                         return '';
</span><span class="cx"> 
</span><span class="cx">                 return $this-&gt;theme_root . '/' . $this-&gt;stylesheet;
</span><span class="lines">@@ -781,8 +792,8 @@
</span><span class="cx">          * @return string Absolute path of the template directory.
</span><span class="cx">          */
</span><span class="cx">         public function get_template_directory() {
</span><del>-                if ( $this-&gt;parent )
-                        $theme_root = $this-&gt;parent-&gt;theme_root;
</del><ins>+                if ( $this-&gt;parent() )
+                        $theme_root = $this-&gt;parent()-&gt;theme_root;
</ins><span class="cx">                 else
</span><span class="cx">                         $theme_root = $this-&gt;theme_root;
</span><span class="cx"> 
</span><span class="lines">@@ -816,8 +827,8 @@
</span><span class="cx">          * @return string URL to the template directory.
</span><span class="cx">          */
</span><span class="cx">         public function get_template_directory_uri() {
</span><del>-                if ( $this-&gt;parent )
-                        $theme_root_uri = $this-&gt;parent-&gt;get_theme_root_uri();
</del><ins>+                if ( $this-&gt;parent() )
+                        $theme_root_uri = $this-&gt;parent()-&gt;get_theme_root_uri();
</ins><span class="cx">                 else
</span><span class="cx">                         $theme_root_uri = $this-&gt;get_theme_root_uri();
</span><span class="cx"> 
</span><span class="lines">@@ -864,7 +875,7 @@
</span><span class="cx">          * The main screenshot is called screenshot.png. gif and jpg extensions are also allowed.
</span><span class="cx">          *
</span><span class="cx">          * Screenshots for a theme must be in the stylesheet directory. (In the case of a child
</span><del>-         * theme, a parent theme's screenshots are inherited.)
</del><ins>+         * theme, a parent theme's screenshots are not inherited.)
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          * @access public
</span><span class="lines">@@ -1030,7 +1041,7 @@
</span><span class="cx">          * @access private
</span><span class="cx">          *
</span><span class="cx">          * @param string $path Absolute path to search.
</span><del>-         * @param array|string $extensions Array of extensions to find, or string of a single extension
</del><ins>+         * @param mixed  Array of extensions to find, string of a single extension, or null for all extensions.
</ins><span class="cx">          * @param int $depth How deep to search for files. Optional, defaults to a flat scan (0 depth). -1 depth is infinite.
</span><span class="cx">          * @param string $relative_path The basename of the absolute path. Used to control the returned path
</span><span class="cx">          *         for the found files, particularly when this function recurses to lower depths.
</span></span></pre>
</div>
</div>

</body>
</html>