Making WordPress.org


Ignore:
Timestamp:
05/13/2020 05:03:21 AM (7 years ago)
Author:
dd32
Message:

Support Forums: Remove specific SEO fixes that are included in the generic SEO fixes plugin.

See #5173.

File:
1 edited

Legend:

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

    r9850 r9863  
    2323                add_action( 'wp_print_footer_scripts',         array( $this, 'replace_quicktags_blockquote_button' ) );
    2424
    25                 // Output rel="canonical" meta tag. Runs before WP's rel_canonical to unhook that if needed.
    26                 add_action( 'wp_head', array( $this, 'rel_canonical' ), 9 );
    27 
    28                 // Output rel="next", rel="prev" meta tags.
    29                 add_action( 'wp_head', array( $this, 'rel_next_prev' ), 9 );
    30 
    31                 // Output robots headers.
    32                 add_action( 'wp_head', array( $this, 'robots_noindex_header' ));
     25                // Add bbPress support to the WordPress.org SEO plugin.
     26                add_filter( 'wporg_canonical_base_url', array( $this, 'wporg_canonical_base_url' ) );
     27                add_filter( 'wporg_canonical_url',      array( $this, 'wporg_canonical_url' ) );
     28                // Correct the number of pages, to respect the bbPress queries.
     29                add_filter( 'wporg_rel_next_pages',     array( $this, 'rel_next_prev_max_pages' ) );
     30                // Add extra conditionals to the noindexing.
     31                add_filter( 'wporg_noindex_request',    array( $this, 'should_noindex_robots' ) );
    3332
    3433                // Output meta description.
    … …  
    366365
    367366        /**
    368          * Returns the canonical URL for various bbPress pages.
    369          *
    370          * @return array The canonical URL.
    371          */
    372         public function get_canonical_url() {
    373                 $canonical_url  = false;
    374                 $supports_paged = true;
    375 
     367         * Add bbPress support to the WordPress.org SEO plugin for Canonical locations.
     368         */
     369        public function wporg_canonical_base_url( $canonical_url ) {
    376370                if ( bbp_is_topic_tag() ) {
    377371                        $canonical_url = bbp_get_topic_tag_link();
    … …  
    387381                        // This covers all user pages rather than using 6 different bbp_is_*() calls.
    388382                        $canonical_url  = 'https://profiles.wordpress.org/' . bbpress()->displayed_user->user_nicename . '/';
    389                         $supports_paged = false;
    390                 }
    391 
    392                 $canonical_url = mb_strtolower( $canonical_url, 'UTF-8' );
    393 
    394                 return [ $canonical_url, $supports_paged ];
    395         }
    396 
    397         /**
    398          * Outputs <link rel="canonical"> tags for various bbPress pages.
    399          */
    400         public function rel_canonical() {
    401                 list( $canonical_url, $canonical_supports_paged ) = $this->get_canonical_url();
    402 
    403                 if ( bbp_is_single_topic() || bbp_is_single_forum() ) {
    404                         remove_action( 'wp_head', 'rel_canonical' ); // Doesn't handle pagination.
    405                 }
    406 
    407                 // Make sure canonical has pagination if needed.
    408                 $page = get_query_var( 'paged', 0 );
    409                 if ( $canonical_url && $canonical_supports_paged && $page >= 2 ) {
    410                         $canonical_url .= 'page/' . absint( $page ) . '/';
    411                 }
    412 
    413                 if ( $canonical_url ) {
    414                         echo '<link rel="canonical" href="' . esc_url( $canonical_url ) . '" />' . "\n";
    415                 }
    416         }
    417 
    418         /**
    419          * Adds noindex robots headers to various pages.
    420          */
    421         public function robots_noindex_header() {
    422                 $robots = false;
    423 
     383                }
     384
     385                return $canonical_url;
     386        }
     387
     388        /**
     389         * Add bbPress support to the WordPress.org SEO plugin for Canonical locations.
     390         */
     391        public function wporg_canonical_url( $canonical_url ) {
     392                global $wp_rewrite;
     393
     394                // profiles links don't support pagination.
     395                if ( false !== stripos( $canonical_url, 'profiles.wordpress.org' ) ) {
     396                        $canonical_url = remove_query_arg( 'paged', $canonical_url );
     397                        $canonical_url = preg_replace( "#/{$wp_rewrite->pagination_base}/\d+/?($|\?)#", '$1', $canonical_url );
     398                }
     399
     400                return $canonical_url;
     401        }
     402
     403        /**
     404         * Enables the noindex robots headers.
     405         */
     406        public function should_noindex_robots( $robots ) {
    424407                if ( bbp_is_search() ) {
    425408                        // #3955
    … …  
    516499                }
    517500
    518                 if ( $robots ) {
    519                         echo '<meta name="robots" content="noindex, follow" />',"\n";
    520                 }
    521         }
    522 
    523         /**
    524          * Outputs rel="next", rel="prev" for paginated archives.
    525          */
    526         public function rel_next_prev() {
    527                 global $wp_query;
    528 
    529                 list( $canonical_url ) = $this->get_canonical_url();
    530 
    531                 $max_pages = $wp_query->max_num_pages;
    532 
     501                return $robots;
     502        }
     503
     504        /**
     505         * Add bbPress support to the WordPress.org SEO plugin for rel="next|prev" archive tags.
     506         */
     507        public function rel_next_prev_max_pages( $max_pages ) {
    533508                if ( bbp_is_single_view() ) {
    534509                        if ( ! bbpress()->topic_query->query ) {
    … …  
    537512                        bbpress()->topic_query->is_tax = false;
    538513                        $max_pages = bbpress()->topic_query->max_num_pages;
     514
    539515                } elseif ( bbp_is_single_topic() ) {
    540516                        if ( ! bbpress()->reply_query->query ) {
    … …  
    542518                        }
    543519                        $max_pages = bbpress()->reply_query->max_num_pages;
     520
    544521                } elseif ( bbp_is_single_forum() ) {
    545522                        $topic_count = get_post_meta( get_queried_object_id(), '_bbp_topic_count', true );
    … …  
    549526                }
    550527
    551                 if ( ! $canonical_url || ! $max_pages ) {
    552                         return;
    553                 }
    554 
    555                 $page      = max( 1, get_query_var( 'paged', 0 ) );
    556                 $next_page = min( $page + 1, $max_pages );
    557                 $prev_page = max( $page - 1, 1 );
    558 
    559                 if ( $page < $max_pages ) {
    560                         $next_page_url = $canonical_url . 'page/' . absint( $next_page ) . '/';
    561                         echo '<link rel="next" href="' . esc_url( $next_page_url ) . '" />' . "\n";
    562                 }
    563 
    564                 if ( $page > 1 ) {
    565                         $prev_page_url = $canonical_url . ( $prev_page > 1 ? 'page/' . absint( $prev_page ) . '/' : '' );
    566                         echo '<link rel="prev" href="' . esc_url( $prev_page_url ) . '" />' . "\n";
    567                 }
     528                return $max_pages;
    568529        }
    569530
Note: See TracChangeset for help on using the changeset viewer.