Changeset 4309 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php
- Timestamp:
- 10/29/2016 07:35:06 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php
r4308 r4309 36 36 // Adjust breadcrumbs for plugin and theme related topics. 37 37 add_filter( 'bbp_breadcrumbs', array( $this, 'breadcrumbs' ) ); 38 39 // Redirect old topic ids to topic permalinks. 40 add_action( 'template_redirect', array( $this, 'redirect_old_topic_id' ), 9 ); 38 41 39 42 $this->loaded = true; … … 427 430 } 428 431 432 /** 433 * In bbPress 1, topics could be referenced using their topic id, and many 434 * are indexed/linked via this rather than their pretty permalink. The 435 * custom table topic2post makes it possible to quickly dereference these 436 * and redirect them appropriately. 437 */ 438 public function redirect_old_topic_id() { 439 global $wpdb; 440 if ( is_404() && 'topic' == get_query_var( 'post_type' ) && is_numeric( get_query_var( 'topic' ) ) ) { 441 $topic_id = absint( get_query_var( 'topic' ) ); 442 if ( ! $topic_id ) { 443 return; 444 } 445 446 $cache_key = $topic_id; 447 $cache_group = 'topic2post'; 448 $post_id = wp_cache_get( $cache_key, $cache_group ); 449 if ( false === $post_id ) { 450 $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}topic2post WHERE topic_id = %d LIMIT 1", $topic_id ) ); 451 if ( $post_id ) { 452 $post_id = absint( $post_id ); 453 wp_cache_set( $cache_key, $post_id, $cache_group ); 454 } 455 } 456 457 if ( $post_id ) { 458 $permalink = get_permalink( $post_id ); 459 if ( $permalink ) { 460 wp_safe_redirect( $permalink, 301 ); 461 exit; 462 } 463 } 464 } 465 } 429 466 }
Note: See TracChangeset
for help on using the changeset viewer.