WordPress.org

Making WordPress.org

Changeset 4206


Ignore:
Timestamp:
10/10/2016 07:46:37 PM (3 years ago)
Author:
coffee2code
Message:

Forums Theme: Show Slack username and/or WordPress.org username (linked to profiles.wordpress.org) in user profiles.

Also adds missing translator comments for all the placeholders in the same block.

Props SergeyBiryukov.
Fixes #2068.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-forums
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-forums/bbpress/user-profile.php

    r4145 r4206  
    2121
    2222        <?php if ( current_user_can( 'moderate' ) ) : ?>
    23         <p class="bbp-user-email"><?php        printf( esc_html__( 'Email: %s',           'wporg-forums' ), bbp_get_displayed_user_field( 'user_email' ) ); ?></p>
     23
     24            <p class="bbp-user-email"><?php
     25                /* translators: %s: user's email address */
     26                printf( esc_html__( 'Email: %s', 'wporg-forums' ), bbp_get_displayed_user_field( 'user_email' ) );
     27            ?></p>
     28
    2429        <?php endif; ?>
     30
     31        <p class="bbp-user-wporg-profile"><?php
     32            $user_nicename  = bbp_get_displayed_user_field( 'user_nicename' );
     33            $slack_username = wporg_support_get_slack_username();
     34
     35            if ( $slack_username && $slack_username != $user_nicename ) {
     36                /* translators: 1: user's WordPress.org profile link, 2: user's Slack username, 3: make.wordpress.org/chat URL */
     37                printf( __( '%1$s on WordPress.org, %2$s on <a href="%3$s">Slack</a>', 'wporg-forums' ),
     38                    wporg_support_get_wporg_profile_link(),
     39                    '@' . $slack_username,
     40                    'https://make.wordpress.org/chat/'
     41                );
     42            } elseif( $slack_username ) {
     43                /* translators: 1: WordPress.org and Slack username, 2: URL for information about Slack */
     44                printf( __( '%1$s on WordPress.org and <a href="%2$s">Slack</a>', 'wporg-forums' ),
     45                    wporg_support_get_wporg_profile_link(),
     46                    'https://make.wordpress.org/chat/'
     47                );
     48            } else {
     49                /* translators: %s: user's WordPress.org profile link */
     50                printf( esc_html__( '%s on WordPress.org', 'wporg-forums' ),
     51                    wporg_support_get_wporg_profile_link()
     52                );
     53            }
     54        ?></p>
    2555
    2656        <?php if ( $custom_title = get_user_option( 'title', bbp_get_displayed_user_id() ) ) : ?>
    2757   
    28             <p class="bbp-user-custom-title"><?php printf( esc_html__( 'Title: %s',       'wporg-forums' ), esc_html( $custom_title )      ); ?></p>
     58            <p class="bbp-user-custom-title"><?php
     59                /* translators: %s: user's custom title */
     60                printf( esc_html__( 'Title: %s', 'wporg-forums' ), esc_html( $custom_title ) );
     61            ?></p>
    2962   
    3063        <?php endif; ?>
    3164
    32         <p class="bbp-user-forum-role"><?php   printf( esc_html__( 'Forum Role: %s',      'wporg-forums' ), bbp_get_user_display_role()    ); ?></p>
    33         <p class="bbp-user-member-since"><?php printf( esc_html__( 'Member Since: %s',    'wporg-forums' ), wporg_support_get_user_registered_date() ); ?></p>
    34         <p class="bbp-user-topic-count"><?php  printf( esc_html__( 'Topics Started: %s',  'wporg-forums' ), bbp_get_user_topic_count_raw() ); ?></p>
    35         <p class="bbp-user-reply-count"><?php  printf( esc_html__( 'Replies Created: %s', 'wporg-forums' ), bbp_get_user_reply_count_raw() ); ?></p>
     65        <p class="bbp-user-forum-role"><?php
     66            /* translators: %s: user's forum role */
     67            printf( esc_html__( 'Forum Role: %s', 'wporg-forums' ), bbp_get_user_display_role() );
     68        ?></p>
     69        <p class="bbp-user-member-since"><?php
     70            /* translators: %s: user's registration date */
     71            printf( esc_html__( 'Member Since: %s', 'wporg-forums' ), wporg_support_get_user_registered_date() );
     72        ?></p>
     73        <p class="bbp-user-topic-count"><?php
     74            /* translators: %s: number of user's topics */
     75            printf( esc_html__( 'Topics Started: %s', 'wporg-forums' ), bbp_get_user_topic_count_raw() );
     76        ?></p>
     77        <p class="bbp-user-reply-count"><?php
     78            /* translators: %s: number of user's replies */
     79            printf( esc_html__( 'Replies Created: %s', 'wporg-forums' ), bbp_get_user_reply_count_raw() );
     80        ?></p>
    3681    </div>
    3782</div><!-- #bbp-author-topics-started -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-forums/functions.php

    r4163 r4206  
    174174
    175175/**
     176 * Get user's WordPress.org profile link.
     177 *
     178 * @param int $user_id
     179 * @return string
     180 */
     181function wporg_support_get_wporg_profile_link( $user_id = 0 ) {
     182    $user_nicename = bbp_get_user_nicename( $user_id );
     183
     184    return sprintf( '<a href="%s">@%s</a>',
     185        esc_url( 'https://profiles.wordpress.org/' . $user_nicename ),
     186        $user_nicename
     187    );
     188}
     189
     190/**
     191 * Get user's Slack username.
     192 *
     193 * @param int $user_id
     194 * @return string The user's Slack username (without '@') if user has one.
     195 */
     196function wporg_support_get_slack_username( $user_id = 0 ) {
     197    global $wpdb;
     198
     199    $user_id = bbp_get_user_id( $user_id );
     200    $slack_username = '';
     201
     202    $data = $wpdb->get_var( $wpdb->prepare( "SELECT profiledata FROM slack_users WHERE user_id = %d", $user_id ) );
     203    if ( $data && ( $data = json_decode( $data, true ) ) ) {
     204        $slack_username = $data['name'];
     205    }
     206
     207    return $slack_username;
     208}
     209
     210/**
    176211 * Get user's registration date.
     212 *
     213 * @param int $user_id
     214 * @return string
    177215 */
    178216function wporg_support_get_user_registered_date( $user_id = 0 ) {
Note: See TracChangeset for help on using the changeset viewer.