Ticket #26233: 26233.diff
| File 26233.diff, 12.1 KB (added by , 12 years ago) |
|---|
-
wp-content/themes/twentyfourteen/functions.php
105 105 ) ) ); 106 106 107 107 // Add support for featured content. 108 add_theme_support( ' featured-content', array(108 add_theme_support( 'twentyfourteen-featured-content', array( 109 109 'featured_content_filter' => 'twentyfourteen_get_featured_posts', 110 110 'max_posts' => 6, 111 111 ) ); … … 495 495 /* 496 496 * Add Featured Content functionality. 497 497 * 498 * To overwrite in a plugin, define your own Featured_Content class on or498 * To overwrite in a plugin, define your own Twenty_Fourteen_Featured_Content class on or 499 499 * before the 'setup_theme' hook. 500 500 */ 501 if ( ! class_exists( ' Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {501 if ( ! class_exists( 'Twenty_Fourteen_Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { 502 502 require get_template_directory() . '/inc/featured-content.php'; 503 503 } -
wp-content/themes/twentyfourteen/inc/customizer.php
38 38 add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' ); 39 39 40 40 // Add the featured content section in case it's not already there. 41 $wp_customize->add_section( ' featured_content', array(41 $wp_customize->add_section( 'twentyfourteen_featured_content', array( 42 42 'title' => __( 'Featured Content', 'twentyfourteen' ), 43 43 'description' => sprintf( __( 'Use a <a href="%1$s"> tag</a> to feature your posts. If no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.', 'twentyfourteen' ), admin_url( '/edit.php?tag=featured' ), admin_url( '/edit.php?show_sticky=1' ) ), 44 44 'priority' => 130, … … 51 51 52 52 $wp_customize->add_control( 'featured_content_layout', array( 53 53 'label' => __( 'Layout', 'twentyfourteen' ), 54 'section' => ' featured_content',54 'section' => 'twentyfourteen_featured_content', 55 55 'type' => 'select', 56 56 'choices' => array( 57 57 'grid' => __( 'Grid', 'twentyfourteen' ), -
wp-content/themes/twentyfourteen/inc/featured-content.php
10 10 * has special meaning beyond that of a normal tags, users will have the 11 11 * ability to hide it from the front-end of their site. 12 12 */ 13 class Featured_Content {13 class Twenty_Fourteen_Featured_Content { 14 14 15 15 /** 16 16 * The maximum number of posts that a Featured Content area can contain. We 17 17 * define a default value here but themes can override this by defining a 18 18 * "max_posts" entry in the second parameter passed in the call to 19 * add_theme_support( ' featured-content' ).19 * add_theme_support( 'twentyfourteen-featured-content' ). 20 20 * 21 * @see Featured_Content::init()21 * @see Twenty_Fourteen_Featured_Content::init() 22 22 */ 23 23 public static $max_posts = 15; 24 24 … … 35 35 * Conditionally hook into WordPress 36 36 * 37 37 * Theme must declare that they support this module by adding 38 * add_theme_support( ' featured-content' ); during after_setup_theme.38 * add_theme_support( 'twentyfourteen-featured-content' ); during after_setup_theme. 39 39 * 40 40 * If no theme support is found there is no need to hook into WordPress. 41 41 * We'll just return early instead. 42 42 * 43 * @uses Featured_Content::$max_posts43 * @uses Twenty_Fourteen_Featured_Content::$max_posts 44 44 */ 45 45 public static function init() { 46 $theme_support = get_theme_support( ' featured-content' );46 $theme_support = get_theme_support( 'twentyfourteen-featured-content' ); 47 47 48 48 // Return early if theme does not support Featured Content. 49 49 if ( ! $theme_support ) { … … 96 96 /** 97 97 * Get featured posts 98 98 * 99 * @uses Featured_Content::get_featured_post_ids()99 * @uses Twenty_Fourteen_Featured_Content::get_featured_post_ids() 100 100 * 101 101 * @return array 102 102 */ … … 122 122 * This function will return the an array containing the 123 123 * post IDs of all featured posts. 124 124 * 125 * Sets the " featured_content_ids" transient.125 * Sets the "twentyfourteen_featured_content_ids" transient. 126 126 * 127 127 * @return array Array of post IDs 128 128 */ 129 129 public static function get_featured_post_ids() { 130 130 // Return array of cached results if they exist. 131 $featured_ids = get_transient( ' featured_content_ids' );131 $featured_ids = get_transient( 'twentyfourteen_featured_content_ids' ); 132 132 if ( ! empty( $featured_ids ) ) { 133 133 return array_map( 'absint', (array) $featured_ids ); 134 134 } … … 164 164 $featured_ids = wp_list_pluck( (array) $featured, 'ID' ); 165 165 $featured_ids = array_map( 'absint', $featured_ids ); 166 166 167 set_transient( ' featured_content_ids', $featured_ids );167 set_transient( 'twentyfourteen_featured_content_ids', $featured_ids ); 168 168 169 169 return $featured_ids; 170 170 } … … 183 183 * Delete transient 184 184 * 185 185 * Hooks in the "save_post" action. 186 * @see Featured_Content::validate_settings().186 * @see Twenty_Fourteen_Featured_Content::validate_settings(). 187 187 */ 188 188 public static function delete_transient() { 189 delete_transient( ' featured_content_ids' );189 delete_transient( 'twentyfourteen_featured_content_ids' ); 190 190 } 191 191 192 192 /** … … 196 196 * onto the 'pre_get_posts' action, this changes the parameters of the query 197 197 * before it gets any posts. 198 198 * 199 * @uses Featured_Content::get_featured_post_ids();199 * @uses Twenty_Fourteen_Featured_Content::get_featured_post_ids(); 200 200 * @param WP_Query $query 201 201 * @return WP_Query Possibly modified WP_Query 202 202 */ … … 237 237 * 238 238 * It's important to mention that the transient needs to be deleted, too. 239 239 * While it may not be obvious by looking at the function alone, the transient 240 * is deleted by Featured_Content::validate_settings().240 * is deleted by Twenty_Fourteen_Featured_Content::validate_settings(). 241 241 * 242 242 * Hooks in the "delete_post_tag" action. 243 * @see Featured_Content::validate_settings().243 * @see Twenty_Fourteen_Featured_Content::validate_settings(). 244 244 * 245 245 * @param int $tag_id The term_id of the tag that has been deleted. 246 246 * @return void … … 254 254 255 255 $settings['tag-id'] = 0; 256 256 $settings = self::validate_settings( $settings ); 257 update_option( ' featured-content', $settings );257 update_option( 'twentyfourteen-featured-content', $settings ); 258 258 } 259 259 260 260 /** … … 266 266 * @param array $taxonomies An array of taxonomy slugs. 267 267 * @return array $terms 268 268 * 269 * @uses Featured_Content::get_setting()269 * @uses Twenty_Fourteen_Featured_Content::get_setting() 270 270 */ 271 271 public static function hide_featured_term( $terms, $taxonomies ) { 272 272 … … 304 304 * @param array $taxonomy An array of taxonomy slugs. 305 305 * @return array $terms 306 306 * 307 * @uses Featured_Content::get_setting()307 * @uses Twenty_Fourteen_Featured_Content::get_setting() 308 308 */ 309 309 public static function hide_the_featured_term( $terms, $id, $taxonomy ) { 310 310 … … 335 335 /** 336 336 * Register custom setting on the Settings -> Reading screen 337 337 * 338 * @uses Featured_Content::render_form()339 * @uses Featured_Content::validate_settings()338 * @uses Twenty_Fourteen_Featured_Content::render_form() 339 * @uses Twenty_Fourteen_Featured_Content::validate_settings() 340 340 * 341 341 * @return void 342 342 */ 343 343 public static function register_setting() { 344 register_setting( ' featured-content', 'featured-content', array( __CLASS__, 'validate_settings' ) );344 register_setting( 'twentyfourteen-featured-content', 'twentyfourteen-featured-content', array( __CLASS__, 'validate_settings' ) ); 345 345 } 346 346 347 347 /** … … 350 350 * @param WP_Customize_Manager $wp_customize Theme Customizer object. 351 351 */ 352 352 public static function customize_register( $wp_customize ) { 353 $wp_customize->add_section( ' featured_content', array(353 $wp_customize->add_section( 'twentyfourteen_featured_content', array( 354 354 'title' => __( 'Featured Content', 'twentyfourteen' ), 355 355 'description' => sprintf( __( 'Use the <a href="%1$s">"featured" tag</a> to feature your posts. You can change this to a tag of your choice; if no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.', 'twentyfourteen' ), admin_url( '/edit.php?tag=featured' ), admin_url( '/edit.php?show_sticky=1' ) ), 356 356 'priority' => 130, 357 'theme_supports' => ' featured-content',357 'theme_supports' => 'twentyfourteen-featured-content', 358 358 ) ); 359 359 360 360 // Add Featured Content settings. 361 $wp_customize->add_setting( ' featured-content[tag-name]', array(361 $wp_customize->add_setting( 'twentyfourteen-featured-content[tag-name]', array( 362 362 'default' => 'featured', 363 363 'type' => 'option', 364 364 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), 365 365 ) ); 366 $wp_customize->add_setting( ' featured-content[hide-tag]', array(366 $wp_customize->add_setting( 'twentyfourteen-featured-content[hide-tag]', array( 367 367 'default' => true, 368 368 'type' => 'option', 369 369 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), 370 370 ) ); 371 371 372 372 // Add Featured Content controls. 373 $wp_customize->add_control( ' featured-content[tag-name]', array(373 $wp_customize->add_control( 'twentyfourteen-featured-content[tag-name]', array( 374 374 'label' => __( 'Tag Name', 'twentyfourteen' ), 375 'section' => ' featured_content',375 'section' => 'twentyfourteen_featured_content', 376 376 'priority' => 20, 377 377 ) ); 378 $wp_customize->add_control( ' featured-content[hide-tag]', array(378 $wp_customize->add_control( 'twentyfourteen-featured-content[hide-tag]', array( 379 379 'label' => __( 'Don’t display tag on front end.', 'twentyfourteen' ), 380 'section' => ' featured_content',380 'section' => 'twentyfourteen_featured_content', 381 381 'type' => 'checkbox', 382 382 'priority' => 30, 383 383 ) ); … … 389 389 * @since Twenty Fourteen 1.0 390 390 */ 391 391 public static function enqueue_scripts() { 392 wp_enqueue_script( ' featured-content-suggest', get_template_directory_uri() . '/js/featured-content-admin.js', array( 'jquery', 'suggest' ), '20131022', true );392 wp_enqueue_script( 'twentyfourteen-featured-content-suggest', get_template_directory_uri() . '/js/featured-content-admin.js', array( 'jquery', 'suggest' ), '20131022', true ); 393 393 } 394 394 395 395 /** … … 402 402 * In the event that you only require one setting, you may pass its name 403 403 * as the first parameter to the function and only that value will be returned. 404 404 * 405 * @uses Featured_Content::sanitize_quantity()405 * @uses Twenty_Fourteen_Featured_Content::sanitize_quantity() 406 406 * 407 407 * @param string $key The key of a recognized setting. 408 408 * @return mixed Array of all settings by default. A single value if passed as first parameter. 409 409 */ 410 410 public static function get_setting( $key = 'all' ) { 411 $saved = (array) get_option( ' featured-content' );411 $saved = (array) get_option( 'twentyfourteen-featured-content' ); 412 412 413 413 $defaults = array( 414 414 'hide-tag' => 1, … … 434 434 * Make sure that all user supplied content is in an 435 435 * expected format before saving to the database. This 436 436 * function will also delete the transient set in 437 * Featured_Content::get_featured_content().437 * Twenty_Fourteen_Featured_Content::get_featured_content(). 438 438 * 439 * @uses Featured_Content::self::sanitize_quantity()440 * @uses Featured_Content::self::delete_transient()439 * @uses Twenty_Fourteen_Featured_Content::self::sanitize_quantity() 440 * @uses Twenty_Fourteen_Featured_Content::self::delete_transient() 441 441 * 442 442 * @param array $input 443 443 * @return array $output … … 480 480 * @param int $input The value to sanitize. 481 481 * @return int A number between 1 and FeaturedContent::$max_posts. 482 482 * 483 * @uses Featured_Content::$max_posts483 * @uses Twenty_Fourteen_Featured_Content::$max_posts 484 484 */ 485 485 public static function sanitize_quantity( $input ) { 486 486 $quantity = absint( $input ); … … 495 495 } 496 496 } 497 497 498 Featured_Content::setup(); 498 Twenty_Fourteen_Featured_Content::setup(); 499 No newline at end of file