Making WordPress.org

Changeset 9190


Ignore:
Timestamp:
10/16/2019 07:17:46 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Use our own canonical url rather than trusting core to produce the correct link.

See #4325.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r9180 r9190  
    165165         */
    166166        public static function archive_link_rel_prev_next() {
    167                 global $paged, $wp_query;
     167                global $paged, $wp_query, $wp_rewrite;
    168168                if ( ! is_archive() && ! is_search() ) {
    169169                        return;
     
    178178                $prevpage = intval( $paged ) - 1;
    179179
     180                // re-implement get_pagenum_link() using our canonical url.
     181                $current_url = Template::get_current_url();
     182                if ( ! $current_url ) {
     183                        return;
     184                }
     185
     186                $current_url = remove_query_arg( 'paged', $current_url );
     187                $current_url = preg_replace( "|{$wp_rewrite->pagination_base}/\d+/?$|", '', $current_url );
     188
     189                // Just assume pretty permalinks everywhere.
     190                $next_url = $current_url . "{$wp_rewrite->pagination_base}/{$nextpage}/";
     191                $prev_url = $current_url . ( $prevpage > 1 ? "{$wp_rewrite->pagination_base}/{$prevpage}/" : '' );
     192
    180193                if ( $prevpage >= 1 ) {
    181194                        printf(
    182195                                '<link rel="prev" href="%s">' . "\n",
    183                                 esc_url( get_pagenum_link( $prevpage ) )
     196                                esc_url( $prev_url )
    184197                        );
    185198                }
     
    188201                        printf(
    189202                                '<link rel="next" href="%s">' . "\n",
    190                                 esc_url( get_pagenum_link( $nextpage ) )
     203                                esc_url( $next_url )
    191204                        );
    192205                }
Note: See TracChangeset for help on using the changeset viewer.