Making WordPress.org

Changeset 10596


Ignore:
Timestamp:
01/19/2021 06:32:12 AM (6 years ago)
Author:
dd32
Message:

Support Forums: Add a 301 redirect for the old /support/topic.php?id=1234 URL structure.

Fixes #5274.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r10595 r10596  
    309309         *  - /users/$id & /profile/$slug to /users/$slug
    310310         *
     311         * See also: Support_Compat in inc/class-support-compat.php
    311312         */
    312313        public function redirect_legacy_urls() {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php

    r9178 r10596  
    563563        public function redirect_old_topic_id() {
    564564                global $wpdb;
    565                 if ( is_404() && 'topic' == get_query_var( 'post_type' ) && is_numeric( get_query_var( 'topic' ) ) ) {
     565
     566                if ( ! is_404() ) {
     567                        return;
     568                }
     569
     570                $topic_id = false;
     571
     572                // /support/topic/1234
     573                if (
     574                        'topic' == get_query_var( 'post_type' ) &&
     575                        is_numeric( get_query_var( 'topic' ) )
     576                ) {
    566577                        $topic_id = absint( get_query_var( 'topic' ) );
    567                         if ( ! $topic_id ) {
    568                                 return;
     578                }
     579
     580                // /support/topic.php?id=1234
     581                if (
     582                        // topic.php sanitized to topic-php.
     583                        'topic-php' === get_query_var( 'pagename' ) &&
     584                        isset( $_GET['id'] ) &&
     585                        is_numeric( $_GET['id'] )
     586                ) {
     587                        $topic_id = absint( $_GET['id'] );
     588                }
     589
     590                if ( ! $topic_id ) {
     591                        return;
     592                }
     593
     594                $cache_key = $topic_id;
     595                $cache_group = 'topic2post';
     596                $post_id = wp_cache_get( $cache_key, $cache_group );
     597                if ( false === $post_id ) {
     598                        $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}topic2post WHERE topic_id = %d LIMIT 1", $topic_id ) );
     599                        if ( $post_id ) {
     600                                $post_id = absint( $post_id );
     601                                wp_cache_set( $cache_key, $post_id, $cache_group );
    569602                        }
    570 
    571                         $cache_key = $topic_id;
    572                         $cache_group = 'topic2post';
    573                         $post_id = wp_cache_get( $cache_key, $cache_group );
    574                         if ( false === $post_id ) {
    575                                 $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}topic2post WHERE topic_id = %d LIMIT 1", $topic_id ) );
    576                                 if ( $post_id ) {
    577                                         $post_id = absint( $post_id );
    578                                         wp_cache_set( $cache_key, $post_id, $cache_group );
    579                                 }
    580                         }
    581 
    582                         if ( $post_id ) {
    583                                 $permalink = get_permalink( $post_id );
    584                                 if ( $permalink ) {
    585                                         wp_safe_redirect( $permalink, 301 );
    586                                         exit;
    587                                 }
    588                         }
     603                }
     604
     605                if ( ! $post_id ) {
     606                        return;
     607                }
     608
     609                $permalink = get_permalink( $post_id );
     610                if ( $permalink ) {
     611                        wp_safe_redirect( $permalink, 301 );
     612                        exit;
    589613                }
    590614        }
Note: See TracChangeset for help on using the changeset viewer.