function mycred_render_my_rank($atts, $content = NULL) { extract(shortcode_atts(array('user_id' => NULL, 'show_title' => 1, 'show_logo' => 0, 'first' => 'logo'), $atts)); if ($user_id === NULL && !is_user_logged_in()) { return; } if ($user_id === NULL) { $user_id = get_current_user_id(); } $rank_name = mycred_get_users_rank($user_id); $show = array(); if ($show_logo) { $show[] = mycred_get_rank_logo($rank_name); } if ($show_title) { $show[] = $rank_name; } if ($first != 'logo') { $show = array_reverse($show); } if (empty($show)) { return; } return '<div class="mycred-my-rank">' . implode(' ', $show) . '</div>'; }
function mycred_get_my_rank() { return mycred_get_users_rank(get_current_user_id()); }
/** * Widget Output */ function widget($args, $instance) { extract($args, EXTR_SKIP); // If we are logged in if (is_user_logged_in()) { // Current user id $user_id = get_current_user_id(); // Load myCRED Now if (!isset($instance['type']) || empty($instance['type'])) { $instance['type'] = 'mycred_default'; } $mycred = mycred($instance['type']); // If this is an excluded user we bail if ($mycred->exclude_user($user_id)) { return; } // Start echo $before_widget; // Title if (!empty($instance['title'])) { echo $before_title; echo $mycred->template_tags_general($instance['title']); echo $after_title; } // Balance $balance = $mycred->get_users_cred($user_id, $instance['type']); if (empty($balance)) { $balance = 0; } $layout = $mycred->template_tags_amount($instance['cred_format'], $balance); $layout = $mycred->template_tags_user($layout, false, wp_get_current_user()); // Include Ranking if ($instance['show_rank']) { if (function_exists('mycred_get_users_rank')) { $rank_name = mycred_get_users_rank($user_id); $ranking = str_replace('%rank%', $rank_name, $instance['rank_format']); $ranking = str_replace('%rank_logo%', mycred_get_rank_logo($rank_name), $ranking); $ranking = str_replace('%ranking%', '', $ranking); } else { $ranking = str_replace(array('%rank%', '%ranking%'), '', $instance['rank_format']); } $ranking = '<div class="myCRED-rank">' . $ranking . '</div>'; $layout .= $ranking; } echo '<div class="myCRED-balance">' . $layout . '</div>'; // If we want to include history if ($instance['show_history']) { echo '<div class="myCRED-widget-history">'; // Query Log $log = new myCRED_Query_Log(array('user_id' => $user_id, 'number' => $instance['number'], 'ctype' => $instance['type'])); // Have results if ($log->have_entries()) { // Title if (!empty($instance['history_title'])) { $history_title = $instance['history_title']; echo $before_title . $mycred->template_tags_general($history_title) . $after_title; } // Organized List echo '<ol class="myCRED-history">'; $alt = 0; $date_format = get_option('date_format'); foreach ($log->results as $entry) { // Row Layout $layout = $instance['history_format']; $layout = str_replace('%date%', '<span class="date">' . date_i18n($date_format, $entry->time) . '</span>', $layout); $layout = str_replace('%entry%', $mycred->parse_template_tags($entry->entry, $entry), $layout); $layout = $mycred->allowed_tags($layout); $layout = $mycred->template_tags_general($layout); $layout = $mycred->template_tags_amount($layout, $entry->creds); // Alternating rows $alt = $alt + 1; if ($alt % 2 == 0) { $class = 'row alternate'; } else { $class = 'row'; } // Output list item echo '<li class="' . $class . '">' . $layout . '</li>'; } echo '</ol>'; } $log->reset_query(); echo '</div>'; } // End echo $after_widget; } else { // If we want to show a message, then do so if ($instance['show_visitors']) { echo $before_widget; $mycred = mycred($instance['type']); // Title if (!empty($instance['title'])) { echo $before_title; echo $mycred->template_tags_general($instance['title']); echo $after_title; } $message = $instance['message']; $message = $mycred->template_tags_general($message); $message = $mycred->allowed_tags($message); echo '<div class="myCRED-my-balance-message"><p>' . nl2br($message) . '</p></div>'; echo $after_widget; } } }
/** * Custom User Balance Content * Inserts a users rank for each point type. * @since 1.6 * @version 1.0 */ public function custom_user_column_content($balance, $user_id, $type) { $rank = mycred_get_users_rank($user_id, 'post_title', NULL, NULL, $type); if ($rank == '') { $rank = '-'; } $balance .= '<small style="display:block;">' . sprintf(__('<strong>Rank:</strong> %s', 'mycred'), $rank) . '</small>'; return $balance; }
/** * Customize User Columns Content * @filter 'mycred_user_row_actions' * @since 1.1.1 * @version 1.0 */ public function custom_user_column_content($value, $column_name, $user_id) { if ('mycred-rank' != $column_name) { return $value; } return mycred_get_users_rank($user_id); }
/** * Show Balance in Header * @since 0.1 * @version 1.4.1 */ public function show_balance($dump = NULL, $context = 'header') { // Prep $output = ''; $user_id = bp_displayed_user_id(); // Check for exclusion if ($this->core->exclude_user($user_id)) { return; } // Check visibility settings if (!$this->buddypress['visibility']['balance'] && !bp_is_my_profile() && !mycred_is_admin()) { return; } // Parse template $template = $this->buddypress['balance_template']; if (function_exists('mycred_get_users_rank')) { $rank_name = mycred_get_users_rank($user_id); $template = str_replace('%rank%', $rank_name, $template); $template = str_replace('%rank_logo%', mycred_get_rank_logo($rank_name), $template); $template = str_replace('%ranking%', mycred_leaderboard_position($user_id), $template); } $template = str_replace(array('%ranking%', '%rank%'), mycred_leaderboard_position($user_id), $template); // Loop though all post types $mycred_types = mycred_get_types(); if (!empty($mycred_types)) { $_template = $template; foreach ($mycred_types as $type => $label) { $template = $_template; // Load myCRED with this points type $mycred = mycred($type); // Check if user is excluded from this type if ($mycred->exclude_user($user_id)) { continue; } // Get users balance $balance = $mycred->get_users_cred($user_id, $type); // Output $template = str_replace('%label%', $label, $template); $template = $mycred->template_tags_general($template); $output .= '<div class="mycred-balance mycred-' . $type . '">' . $template . ' ' . $mycred->format_creds($balance) . '</div>'; } } echo apply_filters('mycred_bp_profile_header', $output, $this->buddypress['balance_template'], $this); }