<!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>[26079] trunk/src/wp-content/themes/twentyfourteen: Twenty Fourteen: improve Featured Content experience in the Customizer.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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/26079">26079</a></dd>
<dt>Author</dt> <dd>lancewillett</dd>
<dt>Date</dt> <dd>2013-11-10 23:37:36 +0000 (Sun, 10 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Twenty Fourteen: improve Featured Content experience in the Customizer. Better preview and cache clearing, props obenland and rachelbaker. Fixes <a href="http://core.trac.wordpress.org/ticket/25549">#25549</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpcontentthemestwentyfourteeninccustomizerphp">trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php</a></li>
<li><a href="#trunksrcwpcontentthemestwentyfourteenincfeaturedcontentphp">trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php</a></li>
<li><a href="#trunksrcwpcontentthemestwentyfourteenstylecss">trunk/src/wp-content/themes/twentyfourteen/style.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpcontentthemestwentyfourteeninccustomizerphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php (26078 => 26079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php    2013-11-10 18:32:01 UTC (rev 26078)
+++ trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php       2013-11-10 23:37:36 UTC (rev 26079)
</span><span class="lines">@@ -20,7 +20,7 @@
</span><span class="cx">  $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
</span><span class="cx"> 
</span><span class="cx">  // Add custom description to Colors and Background sections.
</span><del>-       $wp_customize->get_section( 'colors' )->description     = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
</del><ins>+        $wp_customize->get_section( 'colors' )->description           = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
</ins><span class="cx">   $wp_customize->get_section( 'background_image' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );
</span><span class="cx"> 
</span><span class="cx">  // Add the custom accent color setting and control.
</span></span></pre></div>
<a id="trunksrcwpcontentthemestwentyfourteenincfeaturedcontentphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php (26078 => 26079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php      2013-11-10 18:32:01 UTC (rev 26078)
+++ trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php 2013-11-10 23:37:36 UTC (rev 26079)
</span><span class="lines">@@ -2,22 +2,20 @@
</span><span class="cx"> /**
</span><span class="cx">  * Twenty Fourteen Featured Content
</span><span class="cx">  *
</span><del>- * This module allows you to define a subset of posts to be
- * displayed in the theme's Featured Content area.
</del><ins>+ * This module allows you to define a subset of posts to be displayed in the
+ * theme's Featured Content area.
</ins><span class="cx">  *
</span><del>- * For maximum compatibility with different methods of posting
- * users will designate a featured post tag to associate posts
- * with. Since this tag now has special meaning beyond that of a
- * normal tags, users will have the ability to hide it from the
- * front-end of their site.
</del><ins>+ * For maximum compatibility with different methods of posting users will
+ * designate a featured post tag to associate posts with. Since this tag now
+ * has special meaning beyond that of a normal tags, users will have the
+ * ability to hide it from the front-end of their site.
</ins><span class="cx">  */
</span><span class="cx"> class Featured_Content {
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-        * The maximum number of posts that a Featured Content
-        * area can contain. We define a default value here but
-        * themes can override this by defining a "max_posts"
-        * entry in the second parameter passed in the call to
</del><ins>+         * The maximum number of posts that a Featured Content area can contain. We
+        * define a default value here but themes can override this by defining a
+        * "max_posts" entry in the second parameter passed in the call to
</ins><span class="cx">    * add_theme_support( 'featured-content' ).
</span><span class="cx">   *
</span><span class="cx">   * @see Featured_Content::init()
</span><span class="lines">@@ -39,8 +37,8 @@
</span><span class="cx">   * Theme must declare that they support this module by adding
</span><span class="cx">   * add_theme_support( 'featured-content' ); during after_setup_theme.
</span><span class="cx">   *
</span><del>-        * If no theme support is found there is no need to hook into
-        * WordPress. We'll just return early instead.
</del><ins>+         * If no theme support is found there is no need to hook into WordPress.
+        * We'll just return early instead.
</ins><span class="cx">    *
</span><span class="cx">   * @uses Featured_Content::$max_posts
</span><span class="cx">   */
</span><span class="lines">@@ -52,8 +50,8 @@
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><span class="cx">          /*
</span><del>-                * An array of named arguments must be passed as
-                * the second parameter of add_theme_support().
</del><ins>+                 * An array of named arguments must be passed as the second parameter
+                * of add_theme_support().
</ins><span class="cx">            */
</span><span class="cx">          if ( ! isset( $theme_support[0] ) )
</span><span class="cx">                  return;
</span><span class="lines">@@ -75,8 +73,16 @@
</span><span class="cx">          add_action( 'delete_post_tag',                    array( __CLASS__, 'delete_post_tag'    )    );
</span><span class="cx">          add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts'    )    );
</span><span class="cx">          add_action( 'pre_get_posts',                      array( __CLASS__, 'pre_get_posts'      )    );
</span><ins>+               add_action( 'wp_loaded',                          array( __CLASS__, 'wp_loaded'          )    );
+       }
</ins><span class="cx"> 
</span><del>-               // Hide "featured" tag from the front-end.
</del><ins>+        /**
+        * Hide "featured" tag from the front-end.
+        *
+        * Has to run on wp_loaded so that the preview filters of the customizer
+        * have a chance to alter the value.
+        */
+       public static function wp_loaded() {
</ins><span class="cx">           if ( self::get_setting( 'hide-tag' ) ) {
</span><span class="cx">                  add_filter( 'get_terms',     array( __CLASS__, 'hide_featured_term'     ), 10, 2 );
</span><span class="cx">                  add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 );
</span><span class="lines">@@ -116,23 +122,20 @@
</span><span class="cx">   * @return array Array of post IDs
</span><span class="cx">   */
</span><span class="cx">  public static function get_featured_post_ids() {
</span><del>-               $settings = self::get_setting();
-
-               // Return false if the user has disabled this feature.
-               $tag = $settings['tag-id'];
-               if ( empty( $tag ) ) {
-                       $term = get_term_by( 'name', 'featured', 'post_tag' );
-                       if ( $term )
-                               $tag = $term->term_id;
-                       else
-                               return self::get_sticky_posts();
-               }
-
</del><span class="cx">           // Return array of cached results if they exist.
</span><span class="cx">          $featured_ids = get_transient( 'featured_content_ids' );
</span><span class="cx">          if ( ! empty( $featured_ids ) )
</span><span class="cx">                  return array_map( 'absint', (array) $featured_ids );
</span><span class="cx"> 
</span><ins>+               $settings = self::get_setting();
+
+               // Return sticky post ids if no tag name is set.
+               $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
+               if ( $term )
+                       $tag = $term->term_id;
+               else
+                       return self::get_sticky_posts();
+
</ins><span class="cx">           // Query for featured posts.
</span><span class="cx">          $featured = get_posts( array(
</span><span class="cx">                  'numberposts' => $settings['quantity'],
</span><span class="lines">@@ -228,7 +231,7 @@
</span><span class="cx">   * Hooks in the "delete_post_tag" action.
</span><span class="cx">   * @see Featured_Content::validate_settings().
</span><span class="cx">   *
</span><del>-        * @param int $tag_id the term_id of the tag that has been deleted.
</del><ins>+         * @param int $tag_id The term_id of the tag that has been deleted.
</ins><span class="cx">    * @return void
</span><span class="cx">   */
</span><span class="cx">  public static function delete_post_tag( $tag_id ) {
</span><span class="lines">@@ -329,23 +332,22 @@
</span><span class="cx">  public static function customize_register( $wp_customize ) {
</span><span class="cx">          $wp_customize->add_section( 'featured_content', array(
</span><span class="cx">                  'title'          => __( 'Featured Content', 'twentyfourteen' ),
</span><ins>+                       'description'    => __( 'Easily feature all posts with the "featured" tag or a tag of your choice; if no posts match the tag, "sticky" posts will be displayed instead.', 'twentyfourteen' ),
</ins><span class="cx">                   'priority'       => 130,
</span><span class="cx">                  'theme_supports' => 'featured-content',
</span><span class="cx">          ) );
</span><span class="cx"> 
</span><span class="cx">          // Add Featured Content settings.
</span><span class="cx">          $wp_customize->add_setting( 'featured-content[tag-name]', array(
</span><del>-                       'default' => 'featured',
-                       'type'    => 'option',
</del><ins>+                        'default'              => 'featured',
+                       'type'                 => 'option',
+                       'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
</ins><span class="cx">           ) );
</span><span class="cx">          $wp_customize->add_setting( 'featured-content[hide-tag]', array(
</span><del>-                       'default' => true,
-                       'type'    => 'option',
</del><ins>+                        'default'              => true,
+                       'type'                 => 'option',
+                       'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
</ins><span class="cx">           ) );
</span><del>-               $wp_customize->add_setting( 'featured-content[tag-id]', array(
-                       'default' => 0,
-                       'type'    => 'option',
-               ) );
</del><span class="cx"> 
</span><span class="cx">          // Add Featured Content controls.
</span><span class="cx">          $wp_customize->add_control( 'featured-content[tag-name]', array(
</span><span class="lines">@@ -359,10 +361,6 @@
</span><span class="cx">                  'type'     => 'checkbox',
</span><span class="cx">                  'priority' => 30,
</span><span class="cx">          ) );
</span><del>-               $wp_customize->add_control( new Featured_Content_Customize_Hidden_Control( $wp_customize, 'featured-content[tag-id]', array(
-                       'section'  => 'featured_content',
-                       'priority' => 999,
-               ) ) );
</del><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -375,9 +373,13 @@
</span><span class="cx">          wp_localize_script( 'featured-content-suggest', 'featuredContent', array(
</span><span class="cx">                  'ajaxurl' => admin_url( 'admin-ajax.php' ),
</span><span class="cx">          ) );
</span><ins>+               wp_add_inline_style( 'customize-controls', "
+                       .ac_results {
+                               z-index: 500000;
+                       }
+               " );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-
</del><span class="cx">   /**
</span><span class="cx">   * Get settings
</span><span class="cx">   *
</span><span class="lines">@@ -400,6 +402,7 @@
</span><span class="cx">                  'hide-tag' => 1,
</span><span class="cx">                  'quantity' => 6,
</span><span class="cx">                  'tag-id'   => 0,
</span><ins>+                       'tag-name' => 'featured',
</ins><span class="cx">           );
</span><span class="cx"> 
</span><span class="cx">          $options = wp_parse_args( $saved, $defaults );
</span><span class="lines">@@ -429,22 +432,17 @@
</span><span class="cx">  public static function validate_settings( $input ) {
</span><span class="cx">          $output = array();
</span><span class="cx"> 
</span><del>-               if ( isset( $input['tag-id'] ) )
-                       $output['tag-id'] = absint( $input['tag-id'] );
-
-               if ( isset( $input['tag-name'] ) ) {
-                       if ( empty( $input['tag-name'] ) ) {
-                               $output['tag-id'] = 0;
</del><ins>+                if ( empty( $input['tag-name'] ) ) {
+                       $output['tag-id'] = 0;
+               } else {
+                       $new_tag = wp_create_tag( $input['tag-name'] );
+                       if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) {
+                               $output['tag-id'] = $new_tag['term_id'];
</ins><span class="cx">                   } else {
</span><del>-                               $new_tag = wp_create_tag( $input['tag-name'] );
-                               if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) )
-                                       $tag = get_term( $new_tag['term_id'], 'post_tag' );
-                               if ( isset( $tag->term_id ) )
-                                       $output['tag-id'] = $tag->term_id;
-                               if ( is_int( $new_tag ) )
-                                       $output['tag-id'] = $new_tag;
-                               $output['tag-name'] = get_term( $output['tag-id'], 'post_tag' )->name;
</del><ins>+                                $term = get_term_by( 'name', $input['tag-name'], 'post_tag' );
+                               $output['tag-id'] = $term ? $term->term_id : 0;
</ins><span class="cx">                   }
</span><ins>+                       $output['tag-name'] = $input['tag-name'];
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          if ( isset( $input['quantity'] ) )
</span><span class="lines">@@ -477,14 +475,4 @@
</span><span class="cx">  }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-if ( class_exists( 'WP_Customize_Control' ) ) {
-       class Featured_Content_Customize_Hidden_Control extends WP_Customize_Control {
-               public function render_content() {
-                       ?>
-                       <input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>">
-                       <?php
-               }
-       }
-}
-
</del><span class="cx"> Featured_Content::setup();
</span></span></pre></div>
<a id="trunksrcwpcontentthemestwentyfourteenstylecss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-content/themes/twentyfourteen/style.css (26078 => 26079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-content/themes/twentyfourteen/style.css     2013-11-10 18:32:01 UTC (rev 26078)
+++ trunk/src/wp-content/themes/twentyfourteen/style.css        2013-11-10 23:37:36 UTC (rev 26079)
</span><span class="lines">@@ -2860,8 +2860,8 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> /* Does the same thing as <meta name="viewport" content="width=device-width">,
</span><del>- * but in the future W3C standard way. -ms- prefix is required for IE10+ to 
- * render responsive styling in Windows 8 "snapped" views; IE10+ does not honor 
</del><ins>+ * but in the future W3C standard way. -ms- prefix is required for IE10+ to
+ * render responsive styling in Windows 8 "snapped" views; IE10+ does not honor
</ins><span class="cx">  * the meta tag. See http://core.trac.wordpress.org/ticket/25888.
</span><span class="cx">  */
</span><span class="cx"> @-ms-viewport {
</span></span></pre>
</div>
</div>

</body>
</html>