Making WordPress.org

Changeset 8577


Ignore:
Timestamp:
04/03/2019 06:48:36 AM (7 years ago)
Author:
dd32
Message:

Support Forums: Redirect Attachment pages to their attachment.

Fixes #4334.

File:
1 edited

Legend:

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

    r8468 r8577  
    3636                // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1
    3737                add_action( 'bbp_template_redirect', array( $this, 'redirect_page_zero_one' ) );
     38
     39                // Redirect Attachments to their file
     40                add_action( 'bbp_template_redirect', array( $this, 'redirect_attachments' ) );
    3841
    3942                // REST API.
     
    156159                                exit;
    157160                        }
     161                }
     162        }
     163
     164        public function redirect_attachments() {
     165                if ( is_attachment() ) {
     166                        $url = wp_get_attachment_url( get_queried_object_id() );
     167                        if ( ! $url ) {
     168                                return;
     169                        }
     170
     171                        if (
     172                                function_exists( 'jetpack_photon_url' ) &&
     173                                class_exists( '\Jetpack' ) &&
     174                                method_exists( '\Jetpack', 'get_active_modules' ) &&
     175                                in_array( 'photon', \Jetpack::get_active_modules() )
     176                        ) {
     177                                $url = jetpack_photon_url( $url );
     178                        }
     179
     180                        wp_redirect( $url, 301 );
     181                        exit;
    158182                }
    159183        }
Note: See TracChangeset for help on using the changeset viewer.