示例#1
0
function kleo_bp_replace_placeholders($output)
{
    $initial_output = $output;
    if (strpos($output, '##profile_link##') !== false) {
        if (!is_user_logged_in()) {
            return '';
        }
        if (function_exists('bp_is_active')) {
            $logged_in_link = bp_loggedin_user_domain('/');
            $output = str_replace('##profile_link##', $logged_in_link, $output);
        } elseif (class_exists('bbPress')) {
            //$logged_in_link = bb_get_profile_link();
            $logged_in_link = bbp_get_user_profile_url(bbp_get_current_user_id());
            $output = str_replace('##profile_link##', $logged_in_link, $output);
        }
    }
    if (strpos($output, '##member_name##') !== false) {
        if (!is_user_logged_in()) {
            return '';
        }
        if (function_exists('bp_is_active')) {
            $logged_in_username = bp_get_loggedin_user_fullname();
            $output = str_replace('##member_name##', $logged_in_username, $output);
        } elseif (class_exists('bbPress')) {
            $logged_in_username = bbp_get_user_nicename(bbp_get_current_user_id());
            $output = str_replace('##member_name##', $logged_in_username, $output);
        }
    }
    $output = apply_filters('kleo_bp_replace_placeholders', $output, $initial_output);
    return $output;
}
示例#2
0
 /**
  * Ajax action for facilitating the topic and reply author auto-suggest
  *
  * @since bbPress (r5014)
  */
 public function suggest_user()
 {
     global $wpdb;
     // Bail early if no request
     if (empty($_REQUEST['q'])) {
         wp_die('0');
     }
     // Bail if user cannot moderate - only moderators can change authorship
     if (!current_user_can('moderate')) {
         wp_die('0');
     }
     // Check the ajax nonce
     check_ajax_referer('bbp_suggest_user_nonce');
     // Try to get some users
     $users_query = new WP_User_Query(array('search' => '*' . $wpdb->esc_like($_REQUEST['q']) . '*', 'fields' => array('ID', 'user_nicename'), 'search_columns' => array('ID', 'user_nicename', 'user_email'), 'orderby' => 'ID'));
     // If we found some users, loop through and display them
     if (!empty($users_query->results)) {
         foreach ((array) $users_query->results as $user) {
             printf(esc_html__('%s - %s', 'bbpress'), bbp_get_user_id($user->ID), bbp_get_user_nicename($user->ID, array('force' => $user->user_nicename)) . "\n");
         }
     }
     die;
 }
示例#3
0
 /**
  * @covers ::bbp_user_nicename
  * @covers ::bbp_get_user_nicename
  */
 public function test_bbp_get_user_nicename()
 {
     $user_nicename = $this->keymaster_userdata->user_nicename;
     // String.
     $this->assertSame($user_nicename, bbp_get_user_nicename($this->keymaster_id));
     // Output.
     $this->expectOutputString($user_nicename);
     bbp_user_nicename($this->keymaster_id);
 }
示例#4
0
/**
 * Return URL to the profile page of a user
 *
 * @since 2.0.0 bbPress (r2688)
 *
 * @param int $user_id Optional. User id
 * @param string $user_nicename Optional. User nicename
 * @uses bbp_get_user_id() To get user id
 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs
 * @uses add_query_arg() To add custom args to the url
 * @uses home_url() To get blog home url
 * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user
 *                        profile url, user id and user nicename
 * @return string User profile url
 */
function bbp_get_user_profile_url($user_id = 0, $user_nicename = '')
{
    // Use displayed user ID if there is one, and one isn't requested
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // Allow early overriding of the profile URL to cut down on processing
    $early_profile_url = apply_filters('bbp_pre_get_user_profile_url', $user_id);
    if (is_string($early_profile_url)) {
        return $early_profile_url;
    }
    // Pretty permalinks
    if (bbp_use_pretty_urls()) {
        // Get username if not passed
        if (empty($user_nicename)) {
            $user_nicename = bbp_get_user_nicename($user_id);
        }
        $url = trailingslashit(bbp_get_root_url() . bbp_get_user_slug()) . $user_nicename;
        $url = user_trailingslashit($url);
        $url = home_url($url);
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(bbp_get_user_rewrite_id() => $user_id), home_url('/'));
    }
    return apply_filters('bbp_get_user_profile_url', $url, $user_id, $user_nicename);
}
示例#5
0
 /**
  * Ajax action for facilitating the topic and reply author auto-suggest
  *
  * @since bbPress (r5014)
  */
 public function suggest_user()
 {
     // Try to get some users
     $users_query = new WP_User_Query(array('search' => '*' . like_escape($_REQUEST['q']) . '*', 'fields' => array('ID', 'user_nicename'), 'search_columns' => array('ID', 'user_nicename', 'user_email'), 'orderby' => 'ID'));
     // If we found some users, loop through and display them
     if (!empty($users_query->results)) {
         foreach ((array) $users_query->results as $user) {
             printf(esc_html__('%s - %s', 'bbpress'), bbp_get_user_id($user->ID), bbp_get_user_nicename($user->ID, array('force' => $user->user_nicename)) . "\n");
         }
     }
     die;
 }