WordPress.org

Making WordPress.org

Changeset 9870


Ignore:
Timestamp:
05/13/2020 06:00:48 AM (2 months ago)
Author:
dd32
Message:

Theme Directory: Switch to using get_queried_object() instead of get_post() due to get_post not returning correctly on the theme directory sometimes.

Also moves the outdated theme noindexing to it's own filter.

See #5173.
Fixes #4994.

File:
1 edited

Legend:

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

    r9864 r9870  
    10991099    }
    11001100
    1101     $post = get_post();
    1102     if ( ! $post ) {
     1101    $post = get_queried_object();
     1102    if ( ! $post || !( $post instanceof WP_Post ) ) {
    11031103        return;
    11041104    }
     
    11211121        echo "<meta name='twitter:image' content='" . esc_attr( $theme->screenshot_url . '?w=560&amp;strip=all' ) . "' />\n";
    11221122    }
    1123 
    1124     // If it's outdated, noindex the theme.
    1125     if ( time() - strtotime( $theme->last_updated ) > 2 * YEAR_IN_SECONDS ) {
    1126         add_filter( 'wporg_noindex_request', '__return_true' );
    1127     }
    11281123}
    11291124add_action( 'wp_head', 'wporg_themes_add_meta_tags' );
     1125
     1126/**
     1127 * Noindex outdated themes.
     1128 */
     1129function wporg_themes_noindex_request( $noindex ) {
     1130    if ( is_single() && ( $post = get_queried_object() ) && $post instanceof WP_Post ) {
     1131        $theme = wporg_themes_theme_information( $post->post_name );
     1132        if ( $theme ) {
     1133            // If it's outdated, noindex the theme.
     1134            if ( time() - strtotime( $theme->last_updated ) > 2 * YEAR_IN_SECONDS ) {
     1135                $noindex = true;
     1136            }
     1137        }
     1138    }
     1139
     1140    return $noindex;
     1141}
     1142add_filter( 'wporg_noindex_request', 'wporg_themes_noindex_request' );
    11301143
    11311144/**
Note: See TracChangeset for help on using the changeset viewer.