Making WordPress.org


Ignore:
Timestamp:
11/24/2015 10:52:53 PM (10 years ago)
Author:
coffee2code
Message:

Slack: Allow get_security_team() to return team members by specified field rather than only by user_login.

Notifications now deal in user_nicename instead of user_login.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/slack/security-team.php

    r1801 r2128  
    2626}
    2727
    28 function get_security_team() {
     28/**
     29 * Returns array of security team members by specified field value.
     30 *
     31 * @param string $user_field Optional. The user column value to return for each security team member. Defaut 'user_login'.
     32 * @return array
     33 */
     34function get_security_team( $user_field = 'user_login' ) {
    2935    global $wpdb;
    3036    $group = slack_api( 'groups.info', array( 'channel' => SECURITY_GROUP_ID ) );
     
    4349    $user_ids = array_map( 'intval', $user_ids );
    4450    $user_ids_for_sql = implode( ', ', $user_ids );
    45     $user_logins = $wpdb->get_col( "SELECT user_login FROM $wpdb->users WHERE ID IN ($user_ids_for_sql)" );
     51
     52    // Whitelist user field before using.
     53    if ( ! in_array( $user_field, array( 'ID', 'user_email', 'user_login', 'user_nicename', 'display_name' ) ) ) {
     54        $user_field = 'user_login';
     55    }
     56
     57    $user_logins = $wpdb->get_col( "SELECT $user_field FROM $wpdb->users WHERE ID IN ($user_ids_for_sql)" );
    4658    return $user_logins;
    4759}
Note: See TracChangeset for help on using the changeset viewer.