Changeset 8639
- Timestamp:
- 04/16/2019 06:34:57 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r8619 r8639 26 26 // Output rel="next", rel="prev" meta tags. 27 27 add_action( 'wp_head', array( $this, 'rel_next_prev' ), 9 ); 28 29 // Output robots headers. 30 add_action( 'wp_head', array( $this, 'robots_noindex_header' )); 28 31 29 32 // Link to create new topics atop topic list. … … 357 360 358 361 /** 362 * Adds noindex robots headers to various pages. 363 */ 364 public function robots_noindex_header() { 365 $robots = false; 366 367 if ( bbp_is_search() ) { 368 // #3955 369 $robots = true; 370 } elseif ( 371 bbp_is_single_view() && 372 in_array( bbp_get_view_id(), array( 'plugin-committer', 'plugin-contributor' ) ) 373 ) { 374 // #4329 375 $robots = true; 376 } elseif ( bbp_is_single_view() ) { 377 if ( ! bbpress()->topic_query->query ) { 378 bbp_view_query(); // Populate bbpress()->topic_query. 379 } 380 381 bbpress()->topic_query->is_tax = false; 382 383 // Empty views 384 if ( ! bbpress()->topic_query->have_posts() ) { 385 $robots = true; 386 } 387 } elseif ( bbp_is_topic_tag() ) { 388 if ( ! bbpress()->topic_query->query ) { 389 bbp_has_topics(); // Populate bbpress()->topic_query. 390 } 391 392 // Check all threads 393 $individually_stale = array_map( 394 function( $topic ) { 395 // Thread is 'thin' and hasn't been replied to. 396 if ( 397 strlen( $topic->post_content ) <= 100 398 && ! bbp_get_topic_reply_count( $topic->ID, true ) 399 ) { 400 return 'stale'; 401 } 402 403 // Thread is old 404 $last_modified_date = get_post_meta( $topic->ID, '_bbp_last_active_time', true ) ?: $topic->post_date; 405 if ( strtotime( $last_modified_date ) <= time() - 2*YEAR_IN_SECONDS ) { 406 return 'stale'; 407 } 408 409 return 'fresh'; 410 }, 411 bbpress()->topic_query->posts 412 ); 413 414 // See if all posts 'stale' by checking that no fresh topics exists 415 $all_topics_noindexed = array_search( 'fresh', $individually_stale, true ) === false; 416 417 // #4324, #4338 418 // Post count is <= 1 419 // Last Modified <= -2 years 420 // All topics are also noindexed ( See bbp_is_single_topic() logic ) 421 if ( 422 bbpress()->topic_query->post_count <= 1 || 423 $all_topics_noindexed 424 ) { 425 $robots = true; 426 } 427 428 } elseif ( bbp_is_single_topic() ) { 429 if ( ! bbpress()->reply_query->query ) { 430 bbp_has_replies(); // Populate bbpress()->reply_query. 431 } 432 433 // If no replies and short content - #4283 434 if ( 435 ! bbpress()->reply_query->has_posts() && 436 strlen( bbp_get_topic_content() ) <= 100 437 ) { 438 $robots = true; 439 } 440 } 441 442 if ( $robots ) { 443 echo '<meta name="robots" content="noindex, follow" />',"\n"; 444 } 445 } 446 447 /** 359 448 * Outputs rel="next", rel="prev" for paginated archives. 360 449 */ … … 367 456 368 457 if ( bbp_is_single_view() ) { 369 bbp_view_query(); // Populate bbpress()->topic_query. 458 if ( ! bbpress()->topic_query->query ) { 459 bbp_view_query(); // Populate bbpress()->topic_query. 460 } 370 461 bbpress()->topic_query->is_tax = false; 371 462 $max_pages = bbpress()->topic_query->max_num_pages; 372 463 } elseif ( bbp_is_single_topic() ) { 373 bbp_has_replies(); // Populate bbpress()->reply_query. 464 if ( ! bbpress()->reply_query->query ) { 465 bbp_has_replies(); // Populate bbpress()->reply_query. 466 } 374 467 $max_pages = bbpress()->reply_query->max_num_pages; 375 468 } elseif ( bbp_is_single_forum() ) {
Note: See TracChangeset
for help on using the changeset viewer.