Ticket #25549: 25549.7.diff
File 25549.7.diff, 9.0 KB (added by , 11 years ago) |
---|
-
wp-content/themes/twentyfourteen/inc/customizer.php
20 20 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 21 21 22 22 // Add custom description to Colors and Background sections. 23 $wp_customize->get_section( 'colors' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' );23 $wp_customize->get_section( 'colors' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' ); 24 24 $wp_customize->get_section( 'background_image' )->description = __( 'Background may only be visible on wide screens.', 'twentyfourteen' ); 25 25 26 26 // Add the custom accent color setting and control. -
wp-content/themes/twentyfourteen/inc/featured-content.php
2 2 /** 3 3 * Twenty Fourteen Featured Content 4 4 * 5 * This module allows you to define a subset of posts to be 6 * displayed in thetheme's Featured Content area.5 * This module allows you to define a subset of posts to be displayed in the 6 * theme's Featured Content area. 7 7 * 8 * For maximum compatibility with different methods of posting 9 * users will designate a featured post tag to associate posts 10 * with. Since this tag now has special meaning beyond that of a 11 * normal tags, users will have the ability to hide it from the 12 * front-end of their site. 8 * For maximum compatibility with different methods of posting users will 9 * designate a featured post tag to associate posts with. Since this tag now 10 * has special meaning beyond that of a normal tags, users will have the 11 * ability to hide it from the front-end of their site. 13 12 */ 14 13 class Featured_Content { 15 14 16 15 /** 17 * The maximum number of posts that a Featured Content 18 * area can contain. We define a default value here but 19 * themes can override this by defining a "max_posts" 20 * entry in the second parameter passed in the call to 16 * The maximum number of posts that a Featured Content area can contain. We 17 * define a default value here but themes can override this by defining a 18 * "max_posts" entry in the second parameter passed in the call to 21 19 * add_theme_support( 'featured-content' ). 22 20 * 23 21 * @see Featured_Content::init() … … 39 37 * Theme must declare that they support this module by adding 40 38 * add_theme_support( 'featured-content' ); during after_setup_theme. 41 39 * 42 * If no theme support is found there is no need to hook into 43 * W ordPress. We'll just return early instead.40 * If no theme support is found there is no need to hook into WordPress. 41 * We'll just return early instead. 44 42 * 45 43 * @uses Featured_Content::$max_posts 46 44 */ … … 52 50 return; 53 51 54 52 /* 55 * An array of named arguments must be passed as 56 * the second parameterof add_theme_support().53 * An array of named arguments must be passed as the second parameter 54 * of add_theme_support(). 57 55 */ 58 56 if ( ! isset( $theme_support[0] ) ) 59 57 return; … … 75 73 add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); 76 74 add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); 77 75 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); 76 add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); 77 } 78 78 79 // Hide "featured" tag from the front-end. 79 /** 80 * Hide "featured" tag from the front-end. 81 * 82 * Has to run on wp_loaded so that the preview filters of the customizer 83 * have a chance to alter the value. 84 */ 85 public static function wp_loaded() { 80 86 if ( self::get_setting( 'hide-tag' ) ) { 81 87 add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 2 ); 82 88 add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 ); … … 116 122 * @return array Array of post IDs 117 123 */ 118 124 public static function get_featured_post_ids() { 119 $settings = self::get_setting();120 121 // Return false if the user has disabled this feature.122 $tag = $settings['tag-id'];123 if ( empty( $tag ) ) {124 $term = get_term_by( 'name', 'featured', 'post_tag' );125 if ( $term )126 $tag = $term->term_id;127 else128 return self::get_sticky_posts();129 }130 131 125 // Return array of cached results if they exist. 132 126 $featured_ids = get_transient( 'featured_content_ids' ); 133 127 if ( ! empty( $featured_ids ) ) 134 128 return array_map( 'absint', (array) $featured_ids ); 135 129 130 $settings = self::get_setting(); 131 132 // Return sticky post ids if no tag name is set. 133 $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); 134 if ( $term ) 135 $tag = $term->term_id; 136 else 137 return self::get_sticky_posts(); 138 136 139 // Query for featured posts. 137 140 $featured = get_posts( array( 138 141 'numberposts' => $settings['quantity'], … … 228 231 * Hooks in the "delete_post_tag" action. 229 232 * @see Featured_Content::validate_settings(). 230 233 * 231 * @param int $tag_id the term_id of the tag that has been deleted.234 * @param int $tag_id The term_id of the tag that has been deleted. 232 235 * @return void 233 236 */ 234 237 public static function delete_post_tag( $tag_id ) { … … 329 332 public static function customize_register( $wp_customize ) { 330 333 $wp_customize->add_section( 'featured_content', array( 331 334 'title' => __( 'Featured Content', 'twentyfourteen' ), 335 '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' ), 332 336 'priority' => 130, 333 337 'theme_supports' => 'featured-content', 334 338 ) ); 335 339 336 340 // Add Featured Content settings. 337 341 $wp_customize->add_setting( 'featured-content[tag-name]', array( 338 'default' => 'featured', 339 'type' => 'option', 342 'default' => 'featured', 343 'type' => 'option', 344 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), 340 345 ) ); 341 346 $wp_customize->add_setting( 'featured-content[hide-tag]', array( 342 'default' => true, 343 'type' => 'option', 347 'default' => true, 348 'type' => 'option', 349 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), 344 350 ) ); 345 $wp_customize->add_setting( 'featured-content[tag-id]', array(346 'default' => 0,347 'type' => 'option',348 ) );349 351 350 352 // Add Featured Content controls. 351 353 $wp_customize->add_control( 'featured-content[tag-name]', array( … … 359 361 'type' => 'checkbox', 360 362 'priority' => 30, 361 363 ) ); 362 $wp_customize->add_control( new Featured_Content_Customize_Hidden_Control( $wp_customize, 'featured-content[tag-id]', array(363 'section' => 'featured_content',364 'priority' => 999,365 ) ) );366 364 } 367 365 368 366 /** … … 375 373 wp_localize_script( 'featured-content-suggest', 'featuredContent', array( 376 374 'ajaxurl' => admin_url( 'admin-ajax.php' ), 377 375 ) ); 376 wp_add_inline_style( 'customize-controls', " 377 .ac_results { 378 z-index: 500000; 379 } 380 " ); 378 381 } 379 382 380 381 383 /** 382 384 * Get settings 383 385 * … … 400 402 'hide-tag' => 1, 401 403 'quantity' => 6, 402 404 'tag-id' => 0, 405 'tag-name' => 'featured', 403 406 ); 404 407 405 408 $options = wp_parse_args( $saved, $defaults ); … … 429 432 public static function validate_settings( $input ) { 430 433 $output = array(); 431 434 432 if ( isset( $input['tag-id'] ) )433 $output['tag-id'] = absint( $input['tag-id'] );434 435 if ( isset( $input['tag-name'] ) ) {436 if ( empty( $input['tag-name'] ) ) {437 $output['tag-id'] = 0;435 if ( empty( $input['tag-name'] ) ) { 436 $output['tag-id'] = 0; 437 } else { 438 $new_tag = wp_create_tag( $input['tag-name'] ); 439 if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) { 440 $output['tag-id'] = $new_tag['term_id']; 438 441 } else { 439 $new_tag = wp_create_tag( $input['tag-name'] ); 440 if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) 441 $tag = get_term( $new_tag['term_id'], 'post_tag' ); 442 if ( isset( $tag->term_id ) ) 443 $output['tag-id'] = $tag->term_id; 444 if ( is_int( $new_tag ) ) 445 $output['tag-id'] = $new_tag; 446 $output['tag-name'] = get_term( $output['tag-id'], 'post_tag' )->name; 442 $term = get_term_by( 'name', $input['tag-name'], 'post_tag' ); 443 $output['tag-id'] = $term ? $term->term_id : 0; 447 444 } 445 $output['tag-name'] = $input['tag-name']; 448 446 } 449 447 450 448 if ( isset( $input['quantity'] ) ) … … 477 475 } 478 476 } 479 477 480 if ( class_exists( 'WP_Customize_Control' ) ) {481 class Featured_Content_Customize_Hidden_Control extends WP_Customize_Control {482 public function render_content() {483 ?>484 <input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>">485 <?php486 }487 }488 }489 490 478 Featured_Content::setup();