- Timestamp:
- 11/18/2013 11:11:01 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfourteen/inc/featured-content.php
r26257 r26260 47 47 48 48 // Return early if theme does not support Featured Content. 49 if ( ! $theme_support ) 50 return; 49 if ( ! $theme_support ) { 50 return; 51 } 51 52 52 53 /* … … 54 55 * of add_theme_support(). 55 56 */ 56 if ( ! isset( $theme_support[0] ) ) 57 return; 57 if ( ! isset( $theme_support[0] ) ) { 58 return; 59 } 58 60 59 61 // Return early if "featured_content_filter" has not been defined. 60 if ( ! isset( $theme_support[0]['featured_content_filter'] ) ) 61 return; 62 if ( ! isset( $theme_support[0]['featured_content_filter'] ) ) { 63 return; 64 } 62 65 63 66 $filter = $theme_support[0]['featured_content_filter']; 64 67 65 68 // Theme can override the number of max posts. 66 if ( isset( $theme_support[0]['max_posts'] ) ) 69 if ( isset( $theme_support[0]['max_posts'] ) ) { 67 70 self::$max_posts = absint( $theme_support[0]['max_posts'] ); 71 } 68 72 69 73 add_filter( $filter, array( __CLASS__, 'get_featured_posts' ) ); … … 101 105 102 106 // No need to query if there is are no featured posts. 103 if ( empty( $post_ids ) ) 107 if ( empty( $post_ids ) ) { 104 108 return array(); 109 } 105 110 106 111 $featured_posts = get_posts( array( … … 125 130 // Return array of cached results if they exist. 126 131 $featured_ids = get_transient( 'featured_content_ids' ); 127 if ( ! empty( $featured_ids ) ) 132 if ( ! empty( $featured_ids ) ) { 128 133 return array_map( 'absint', (array) $featured_ids ); 134 } 129 135 130 136 $settings = self::get_setting(); … … 132 138 // Return sticky post ids if no tag name is set. 133 139 $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); 134 if ( $term ) 140 if ( $term ) { 135 141 $tag = $term->term_id; 136 else142 } else { 137 143 return self::get_sticky_posts(); 144 } 138 145 139 146 // Query for featured posts. … … 150 157 151 158 // Return array with sticky posts if no Featured Content exists. 152 if ( ! $featured ) 159 if ( ! $featured ) { 153 160 return self::get_sticky_posts(); 161 } 154 162 155 163 // Ensure correct format before save/return. … … 196 204 197 205 // Bail if not home or not main query. 198 if ( ! $query->is_home() || ! $query->is_main_query() ) 199 return; 206 if ( ! $query->is_home() || ! $query->is_main_query() ) { 207 return; 208 } 200 209 201 210 $page_on_front = get_option( 'page_on_front' ); 202 211 203 212 // Bail if the blog page is not the front page. 204 if ( ! empty( $page_on_front ) ) 205 return; 213 if ( ! empty( $page_on_front ) ) { 214 return; 215 } 206 216 207 217 $featured = self::get_featured_post_ids(); 208 218 209 219 // Bail if no featured posts. 210 if ( ! $featured ) 211 return; 220 if ( ! $featured ) { 221 return; 222 } 212 223 213 224 // We need to respect post ids already in the blacklist. … … 238 249 $settings = self::get_setting(); 239 250 240 if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) 241 return; 251 if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { 252 return; 253 } 242 254 243 255 $settings['tag-id'] = 0; … … 260 272 261 273 // This filter is only appropriate on the front-end. 262 if ( is_admin() ) 263 return $terms; 274 if ( is_admin() ) { 275 return $terms; 276 } 264 277 265 278 // We only want to hide the featured tag. 266 if ( ! in_array( 'post_tag', $taxonomies ) ) 267 return $terms; 279 if ( ! in_array( 'post_tag', $taxonomies ) ) { 280 return $terms; 281 } 268 282 269 283 // Bail if no terms were returned. 270 if ( empty( $terms ) ) 271 return $terms; 284 if ( empty( $terms ) ) { 285 return $terms; 286 } 272 287 273 288 foreach( $terms as $order => $term ) { 274 if ( self::get_setting( 'tag-id' ) == $term->term_id && 'post_tag' == $term->taxonomy ) 289 if ( self::get_setting( 'tag-id' ) == $term->term_id && 'post_tag' == $term->taxonomy ) { 275 290 unset( $terms[ $order ] ); 291 } 276 292 } 277 293 … … 294 310 295 311 // This filter is only appropriate on the front-end. 296 if ( is_admin() ) 297 return $terms; 312 if ( is_admin() ) { 313 return $terms; 314 } 298 315 299 316 // Make sure we are in the correct taxonomy. 300 if ( 'post_tag' != $taxonomy ) 301 return $terms; 317 if ( 'post_tag' != $taxonomy ) { 318 return $terms; 319 } 302 320 303 321 // No terms? Return early! 304 if ( empty( $terms ) ) 305 return $terms; 322 if ( empty( $terms ) ) { 323 return $terms; 324 } 306 325 307 326 foreach( $terms as $order => $term ) { 308 if ( self::get_setting( 'tag-id' ) == $term->term_id ) 327 if ( self::get_setting( 'tag-id' ) == $term->term_id ) { 309 328 unset( $terms[ $term->term_id ] ); 329 } 310 330 } 311 331 … … 402 422 $options['quantity'] = self::sanitize_quantity( $options['quantity'] ); 403 423 404 if ( 'all' != $key ) 424 if ( 'all' != $key ) { 405 425 return isset( $options[ $key ] ) ? $options[ $key ] : false; 426 } 406 427 407 428 return $options; … … 438 459 } 439 460 440 if ( isset( $input['quantity'] ) ) 461 if ( isset( $input['quantity'] ) ) { 441 462 $output['quantity'] = self::sanitize_quantity( $input['quantity'] ); 463 } 442 464 443 465 $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0; … … 459 481 $quantity = absint( $input ); 460 482 461 if ( $quantity > self::$max_posts ) 483 if ( $quantity > self::$max_posts ) { 462 484 $quantity = self::$max_posts; 463 else if ( 1 > $quantity )485 } else if ( 1 > $quantity ) { 464 486 $quantity = 1; 487 } 465 488 466 489 return $quantity;
Note: See TracChangeset
for help on using the changeset viewer.