- Timestamp:
- 12/03/2013 05:05:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php
r26361 r26556 3 3 * Twenty Fourteen Featured Content 4 4 * 5 * This module allows you to define a subset of posts to be displayed in the6 * theme's Featured Content area.5 * This module allows you to define a subset of posts to be displayed 6 * in the theme's Featured Content area. 7 7 * 8 * For maximum compatibility with different methods of posting users will9 * designate a featured post tag to associate posts with. Since this tag now10 * has special meaning beyond that of a normal tags, users will have the11 * ability to hide it from the front-end of their site.8 * For maximum compatibility with different methods of posting users 9 * will designate a featured post tag to associate posts with. Since 10 * this tag now has special meaning beyond that of a normal tags, users 11 * will have the ability to hide it from the front-end of their site. 12 12 */ 13 13 class Featured_Content { 14 14 15 15 /** 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 19 * add_theme_support( 'featured-content' ). 16 * The maximum number of posts a Featured Content area can contain. 17 * 18 * We define a default value here but themes can override 19 * this by defining a "max_posts" entry in the second parameter 20 * passed in the call to add_theme_support( 'featured-content' ). 20 21 * 21 22 * @see Featured_Content::init() 23 * 24 * @since Twenty Fourteen 1.0 25 * 26 * @static 27 * @access public 28 * @var int 22 29 */ 23 30 public static $max_posts = 15; 24 31 25 32 /** 26 * Instantiate 33 * Instantiate. 27 34 * 28 35 * All custom functionality will be hooked into the "init" action. 36 * 37 * @static 38 * @access public 39 * @since Twenty Fourteen 1.0 29 40 */ 30 41 public static function setup() { … … 33 44 34 45 /** 35 * Conditionally hook into WordPress 46 * Conditionally hook into WordPress. 36 47 * 37 48 * Theme must declare that they support this module by adding … … 41 52 * We'll just return early instead. 42 53 * 43 * @uses Featured_Content::$max_posts 54 * @static 55 * @access public 56 * @since Twenty Fourteen 1.0 44 57 */ 45 58 public static function init() { … … 86 99 * Has to run on wp_loaded so that the preview filters of the customizer 87 100 * have a chance to alter the value. 101 * 102 * @static 103 * @access public 104 * @since Twenty Fourteen 1.0 88 105 */ 89 106 public static function wp_loaded() { … … 95 112 96 113 /** 97 * Get featured posts 98 * 99 * @uses Featured_Content::get_featured_post_ids() 100 * 101 * @return array 114 * Get featured posts. 115 * 116 * @static 117 * @access public 118 * @since Twenty Fourteen 1.0 119 * 120 * @return array Array of featured posts. 102 121 */ 103 122 public static function get_featured_posts() { … … 125 144 * Sets the "featured_content_ids" transient. 126 145 * 127 * @return array Array of post IDs 146 * @static 147 * @access public 148 * @since Twenty Fourteen 1.0 149 * 150 * @return array Array of post IDs. 128 151 */ 129 152 public static function get_featured_post_ids() { … … 171 194 172 195 /** 173 * Returns an array with IDs of posts maked as sticky. 174 * 175 * @return array 196 * Return an array with IDs of posts maked as sticky. 197 * 198 * @static 199 * @access public 200 * @since Twenty Fourteen 1.0 201 * 202 * @return array Array of sticky posts. 176 203 */ 177 204 public static function get_sticky_posts() { … … 181 208 182 209 /** 183 * Delete transient210 * Delete featured content ids transient. 184 211 * 185 212 * Hooks in the "save_post" action. 213 * 186 214 * @see Featured_Content::validate_settings(). 215 * 216 * @static 217 * @access public 218 * @since Twenty Fourteen 1.0 187 219 */ 188 220 public static function delete_transient() { … … 191 223 192 224 /** 193 * Exclude featured posts from the home page blog query 194 * 195 * Filter the home page posts, and remove any featured post ID's from it. Hooked 196 * onto the 'pre_get_posts' action, this changes the parameters of the query 197 * before it gets any posts. 198 * 199 * @uses Featured_Content::get_featured_post_ids(); 200 * @param WP_Query $query 201 * @return WP_Query Possibly modified WP_Query 225 * Exclude featured posts from the home page blog query. 226 * 227 * Filter the home page posts, and remove any featured post ID's from it. 228 * Hooked onto the 'pre_get_posts' action, this changes the parameters of 229 * the query before it gets any posts. 230 * 231 * @static 232 * @access public 233 * @since Twenty Fourteen 1.0 234 * 235 * @param WP_Query $query WP_Query object. 236 * @return WP_Query Possibly-modified WP_Query. 202 237 */ 203 238 public static function pre_get_posts( $query ) { … … 234 269 235 270 /** 236 * Reset tag option when the saved tag is deleted 237 * 238 * It's important to mention that the transient needs to be deleted, too.239 * While it may not be obvious by looking at the function alone, the transient240 * is deleted by Featured_Content::validate_settings().271 * Reset tag option when the saved tag is deleted. 272 * 273 * It's important to mention that the transient needs to be deleted, 274 * too. While it may not be obvious by looking at the function alone, 275 * the transient is deleted by Featured_Content::validate_settings(). 241 276 * 242 277 * Hooks in the "delete_post_tag" action. 278 * 243 279 * @see Featured_Content::validate_settings(). 280 * 281 * @static 282 * @access public 283 * @since Twenty Fourteen 1.0 244 284 * 245 285 * @param int $tag_id The term_id of the tag that has been deleted. … … 259 299 260 300 /** 261 * Hide featured tag from displaying when global terms are queried from the front-end 301 * Hide featured tag from displaying when global terms are queried from the front-end. 262 302 * 263 303 * Hooks into the "get_terms" filter. 264 304 * 265 * @param array $terms A list of term objects. This is the return value of get_terms(). 305 * @static 306 * @access public 307 * @since Twenty Fourteen 1.0 308 * 309 * @param array $terms List of term objects. This is the return value of get_terms(). 266 310 * @param array $taxonomies An array of taxonomy slugs. 267 * @return array $terms311 * @return array A filtered array of terms. 268 312 * 269 313 * @uses Featured_Content::get_setting() … … 296 340 297 341 /** 298 * Hide featured tag from display when terms associated with a post object are queried from the front-end 342 * Hide featured tag from display when terms associated with a post object 343 * are queried from the front-end. 299 344 * 300 345 * Hooks into the "get_the_terms" filter. 301 346 * 302 * @param array $terms A list of term objects. This is the return value of get_the_terms(). 303 * @param int $id The ID field for the post object that terms are associated with. 347 * @static 348 * @access public 349 * @since Twenty Fourteen 1.0 350 * 351 * @param array $terms A list of term objects. This is the return value of get_the_terms(). 352 * @param int $id The ID field for the post object that terms are associated with. 304 353 * @param array $taxonomy An array of taxonomy slugs. 305 * @return array $terms354 * @return array Filtered array of terms. 306 355 * 307 356 * @uses Featured_Content::get_setting() … … 334 383 335 384 /** 336 * Register custom setting on the Settings -> Reading screen 337 * 338 * @uses Featured_Content::render_form() 339 * @uses Featured_Content::validate_settings() 385 * Register custom setting on the Settings -> Reading screen. 386 * 387 * @static 388 * @access public 389 * @since Twenty Fourteen 1.0 340 390 * 341 391 * @return void … … 347 397 /** 348 398 * Add settings to the Customizer. 399 * 400 * @static 401 * @access public 402 * @since Twenty Fourteen 1.0 349 403 * 350 404 * @param WP_Customize_Manager $wp_customize Theme Customizer object. … … 387 441 * Enqueue the tag suggestion script. 388 442 * 443 * @static 444 * @access public 389 445 * @since Twenty Fourteen 1.0 390 446 */ … … 394 450 395 451 /** 396 * Get settings 397 * 398 * Get all settings recognized by this module. This function will return 399 * all settings whether or not they have been stored in the database yet. 400 * This ensures that all keys are available at all times. 401 * 402 * In the event that you only require one setting, you may pass its name 403 * as the first parameter to the function and only that value will be returned. 404 * 405 * @uses Featured_Content::sanitize_quantity() 452 * Get featured content settings. 453 * 454 * Get all settings recognized by this module. This function 455 * will return all settings whether or not they have been stored 456 * in the database yet. This ensures that all keys are available 457 * at all times. 458 * 459 * In the event that you only require one setting, you may pass 460 * its name as the first parameter to the function and only that 461 * value will be returned. 462 * 463 * @static 464 * @access public 465 * @since Twenty Fourteen 1.0 406 466 * 407 467 * @param string $key The key of a recognized setting. … … 430 490 431 491 /** 432 * Validate settings433 * 434 * Make sure that all user supplied content is in an 435 * expected format before saving to the database. This436 * function will also delete the transient set in437 * Featured_Content::get_featured_content().438 * 439 * @ uses Featured_Content::self::sanitize_quantity()440 * @ uses Featured_Content::self::delete_transient()441 * 442 * @param array $input 443 * @return array $output492 * Validate featured content settings. 493 * 494 * Make sure that all user supplied content is in an expected 495 * format before saving to the database. This function will also 496 * delete the transient set in Featured_Content::get_featured_content(). 497 * 498 * @static 499 * @access public 500 * @since Twenty Fourteen 1.0 501 * 502 * @param array $input Array of settings input. 503 * @return array Validated settings output. 444 504 */ 445 505 public static function validate_settings( $input ) { … … 470 530 $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0; 471 531 532 // Delete the featured post ids transient. 472 533 self::delete_transient(); 473 534 … … 476 537 477 538 /** 478 * Sanitize quantity 539 * Sanitize quantity of featured posts. 540 * 541 * @static 542 * @access public 543 * @since Twenty Fourteen 1.0 479 544 * 480 545 * @param int $input The value to sanitize. 481 546 * @return int A number between 1 and FeaturedContent::$max_posts. 482 *483 * @uses Featured_Content::$max_posts484 547 */ 485 548 public static function sanitize_quantity( $input ) { … … 494 557 return $quantity; 495 558 } 496 } 559 560 } // Featured_Content 497 561 498 562 Featured_Content::setup();
Note: See TracChangeset
for help on using the changeset viewer.