Making WordPress.org

Changeset 10802

Timestamp:
03/10/2021 05:34:15 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Don't overwrite the global $post object in Plugin_Directory::get_plugin_post().

It's not clear why this function was overriding the global $post object sometimes (not always) and could set it to invalid data.

Follow up to [10801].

File:
1 edited

Legend:

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

    r10801 r10802  
    16831683     */
    16841684    public static function get_plugin_post( $plugin_slug = null ) {
    1685         global $post;
    1686 
    16871685        if ( $plugin_slug instanceof \WP_Post ) {
    16881686            return $plugin_slug;
     
    16921690        if (
    16931691            is_int( $plugin_slug ) &&
    1694             ( $post_obj = get_post( $plugin_slug ) ) &&
    1695             ( $post_obj->ID === $plugin_slug )
     1692            ( $post = get_post( $plugin_slug ) ) &&
     1693            ( $post->ID === $plugin_slug )
    16961694        ) {
    1697             $post = $post_obj;
    1698             return $post_obj;
     1695            return $post;
    16991696        }
    17001697
    17011698        // Use the global $post object when appropriate
    1702         if ( ! empty( $post ) && 'plugin' == $post->post_type ) {
     1699        if (
     1700            ! empty( $GLOBALS['post']->post_type ) &&
     1701            'plugin' === $GLOBALS['post']->post_type
     1702        ) {
    17031703            // Default to the global object.
    17041704            if ( is_null( $plugin_slug ) || 0 === $plugin_slug ) {
    1705                 return get_post( $post->ID );
     1705                return get_post( $->ID );
    17061706            }
    17071707
    17081708            // Avoid hitting the database if it matches.
    1709             if ( $plugin_slug == $post->post_name ) {
    1710                 return get_post( $post->ID );
     1709            if ( $plugin_slug == $->post_name ) {
     1710                return get_post( $->ID );
    17111711            }
    17121712        }
Note: See TracChangeset for help on using the changeset viewer.