Making WordPress.org

Changeset 10349


Ignore:
Timestamp:
10/06/2020 04:13:41 AM (5 years ago)
Author:
dd32
Message:

Support Forum: Don't assume that the plugin or theme actually exists, the metadata for threads can get out of sync with reality causing it to constantly query for a plugin/theme it'll never get valid data for.

Fixes a bunch of PHP notices.

File:
1 edited

Legend:

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

    r10344 r10349  
    887887
    888888        // Check the cache.
    889         $cache_key = $slug;
     889        $cache_key   = $slug;
    890890        $cache_group = $this->compat() . '-authors-slugs';
    891         $authors = wp_cache_get( $cache_key, $cache_group );
    892         if ( ! $authors ) {
    893 
     891        $authors     = wp_cache_get( $cache_key, $cache_group );
     892        if ( $authors === false ) {
     893            $authors = array();
    894894            if ( $this->compat() == 'theme' ) {
    895895                $theme = $this->get_object( $slug );
    896                 $author = get_user_by( 'id', $theme->post_author );
    897                 $authors = array( $author->user_nicename );
     896                if ( $theme ) {
     897                    $author = get_user_by( 'id', $theme->post_author );
     898                    if ( $author ) {
     899                        $authors = array( $author->user_nicename );
     900                    }
     901                }
    898902            } else {
    899903                $plugin = $this->get_object( $slug );
    900                 $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
    901                 // Note: Intentionally not considering posts of 'plugin' post_type with
    902                 // 'post_author' matching this author because the field only relates to
    903                 // the user who submitted the plugin. It does not confer special access,
    904                 // rights, or ownership.
    905                 $authors = $wpdb->get_col( $wpdb->prepare(
     904                if ( $plugin ) {
     905                    $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
     906                    // Note: Intentionally not considering posts of 'plugin' post_type with
     907                    // 'post_author' matching this author because the field only relates to
     908                    // the user who submitted the plugin. It does not confer special access,
     909                    // rights, or ownership.
     910                    $authors = $wpdb->get_col( $wpdb->prepare(
     911                        "SELECT slug
     912                         FROM {$prefix}terms AS t
     913                         LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
     914                         LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
     915                         WHERE tt.taxonomy = 'plugin_committers' AND tr.object_id = %d",
     916                         $plugin->ID
     917                    ) );
     918                }
     919            }
     920
     921            wp_cache_set( $cache_key, $authors, $cache_group, HOUR_IN_SECONDS );
     922        }
     923        return $authors;
     924    }
     925
     926    public function get_contributors( $slug ) {
     927        global $wpdb;
     928
     929        if ( null !== $this->contributors ) {
     930            return $this->contributors;
     931        }
     932
     933        // Themes do not have contributors right now.
     934        if ( $this->compat() == 'theme' ) {
     935            $contributors = array();
     936            return $contributors;
     937        }
     938
     939        // Check the cache.
     940        $cache_key    = $slug;
     941        $cache_group  = $this->compat() . '-contributors-slugs';
     942        $contributors = wp_cache_get( $cache_key, $cache_group );
     943        if ( $contributors === false ) {
     944            $contributors = array();
     945            $plugin       = $this->get_object( $slug );
     946
     947            if ( $plugin ) {
     948                $prefix       = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
     949                $contributors = $wpdb->get_col( $wpdb->prepare(
    906950                    "SELECT slug
    907951                     FROM {$prefix}terms AS t
    908952                     LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
    909953                     LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    910                      WHERE tt.taxonomy = 'plugin_committers' AND tr.object_id = %d",
     954                     WHERE tt.taxonomy = 'plugin_contributors' AND tr.object_id = %d",
    911955                     $plugin->ID
    912956                ) );
    913957            }
    914958
    915             wp_cache_set( $cache_key, $authors, $cache_group, HOUR_IN_SECONDS );
    916         }
    917         return $authors;
    918     }
    919 
    920     public function get_contributors( $slug ) {
    921         global $wpdb;
    922 
    923         if ( null !== $this->contributors ) {
    924             return $this->contributors;
    925         }
    926 
    927         // Themes do not have contributors right now.
    928         if ( $this->compat() == 'theme' ) {
    929             $contributors = array();
    930             return $contributors;
    931         }
    932 
    933         // Check the cache.
    934         $cache_key = $slug;
    935         $cache_group = $this->compat() . '-contributors-slugs';
    936         $contributors = wp_cache_get( $cache_key, $cache_group );
    937         if ( ! $contributors ) {
    938             $plugin = $this->get_object( $slug );
    939             $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
    940             $contributors = $wpdb->get_col( $wpdb->prepare(
    941                 "SELECT slug
    942                  FROM {$prefix}terms AS t
    943                  LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
    944                  LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    945                  WHERE tt.taxonomy = 'plugin_contributors' AND tr.object_id = %d",
    946                  $plugin->ID
    947             ) );
    948 
    949959            wp_cache_set( $cache_key, $contributors, $cache_group, HOUR_IN_SECONDS );
    950960        }
     961
    951962        return $contributors;
    952963    }
     
    966977
    967978        // Check the cache.
    968         $cache_key = $slug;
    969         $cache_group = $this->compat() . '-support-reps-slugs';
     979        $cache_key    = $slug;
     980        $cache_group  = $this->compat() . '-support-reps-slugs';
    970981        $support_reps = wp_cache_get( $cache_key, $cache_group );
    971         if ( ! $support_reps ) {
    972             $plugin = $this->get_object( $slug );
    973             $prefix = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
    974             $support_reps = $wpdb->get_col( $wpdb->prepare(
    975                 "SELECT slug
    976                  FROM {$prefix}terms AS t
    977                  LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
    978                  LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    979                  WHERE tt.taxonomy = 'plugin_support_reps' AND tr.object_id = %d",
    980                  $plugin->ID
    981             ) );
     982        if ( $support_reps === false ) {
     983            $support_reps = array();
     984            $plugin       = $this->get_object( $slug );
     985
     986            if ( $plugin ) {
     987                $prefix       = $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_';
     988                $support_reps = $wpdb->get_col( $wpdb->prepare(
     989                    "SELECT slug
     990                     FROM {$prefix}terms AS t
     991                     LEFT JOIN {$prefix}term_taxonomy AS tt ON tt.term_id = t.term_id
     992                     LEFT JOIN {$prefix}term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
     993                     WHERE tt.taxonomy = 'plugin_support_reps' AND tr.object_id = %d",
     994                     $plugin->ID
     995                ) );
     996            }
    982997
    983998            wp_cache_set( $cache_key, $support_reps, $cache_group, HOUR_IN_SECONDS );
    984999        }
     1000
    9851001        return $support_reps;
    9861002    }
Note: See TracChangeset for help on using the changeset viewer.