Making WordPress.org

Changeset 11945


Ignore:
Timestamp:
07/07/2022 12:59:26 AM (2 years ago)
Author:
dd32
Message:

Support: Don't show deactivated Slack account details on forum user profiles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r11571 r11945  
    355355
    356356    $user_id = bbp_get_user_id( $user_id );
    357     $slack_username = '';
    358 
    359     $data = $wpdb->get_var( $wpdb->prepare( "SELECT profiledata FROM slack_users WHERE user_id = %d", $user_id ) );
     357
     358    $data = wp_cache_get( "user_id:$user_id", 'slack_data' );
     359    if ( false === $data ) {
     360        $data = $wpdb->get_var( $wpdb->prepare( "SELECT profiledata FROM slack_users WHERE user_id = %d", $user_id ) );
     361
     362        // Cache nonexistence as an empty string.
     363        wp_cache_add( "user_id:$user_id", (string) $data, 'slack_data', 1800 );
     364    }
     365
    360366    if ( $data && ( $data = json_decode( $data, true ) ) ) {
    361         if ( isset( $data['profile']['display_name'] ) ) {
    362             $slack_username = $data['profile']['display_name'];
     367        if ( ! empty( $data['deleted'] ) ) {
     368            return false;
    363369        }
    364     }
    365 
    366     return $slack_username;
     370
     371        // Optional Display Name field
     372        if ( ! empty( $data['profile']['display_name'] ) ) {
     373            return $data['profile']['display_name'];
     374        }
     375
     376        // Fall back to "Full Name" field.
     377        if ( ! empty( $data['profile']['real_name'] ) ) {
     378            return $data['profile']['real_name'];
     379        }
     380    }
     381
     382    return false;
    367383}
    368384
Note: See TracChangeset for help on using the changeset viewer.