Title: Shortcode for Current user Score
Last modified: August 21, 2016

---

# Shortcode for Current user Score

 *  Resolved [fanbolero](https://wordpress.org/support/users/fanbolero/)
 * (@fanbolero)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/shortcode-for-current-user-score/)
 * Is there a shortcode to display the current user total point score?
 * [http://wordpress.org/extend/plugins/football-pool/](http://wordpress.org/extend/plugins/football-pool/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [AntoineH](https://wordpress.org/support/users/antoineh/)
 * (@antoineh)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/shortcode-for-current-user-score/#post-3709440)
 * No, there is not a shortcode for this. But I put something together that may 
   be useful for you. If you are familiar with PHP you can add the following to 
   your plugin code.
 * Add the following function to class `Football_Pool_Pool` in file `classes\class-
   football-pool-pool.php`:
 *     ```
       public function get_user_score( $user, $ranking_id = FOOTBALLPOOL_RANKING_DEFAULT, $score_date = '' ) {
       	global $wpdb;
       	$prefix = FOOTBALLPOOL_DB_PREFIX;
   
       	$sql = $wpdb->prepare(
       					sprintf( "SELECT totalScore FROM {$prefix}scorehistory
       							WHERE userId = %%d AND ranking_id = %%d
       							AND ( %s scoreDate <= %%s )
       							ORDER BY scoreDate DESC LIMIT 1"
       							, ( $score_date == '' ? '1 = 1 OR' : '' )
       					) , $user, $ranking_id, $score_date );
       	return $wpdb->get_var( $sql ); // return null if nothing found
       }
       ```
   
 * Register the shortcode in file `classes\class-football-pool-shortcodes.php` (
   somewhere at the top of the file):
 *     ```
       add_shortcode( 'fp-user-score', array( 'Football_Pool_Shortcodes', 'shortcode_user_score' ) );
       ```
   
 * Add the handling method for the shortcode to the class `Football_Pool_Shortcodes`
   in the same file:
 *     ```
       //[fp-user-score]
       //  Displays the score for a given user in the given ranking.
       //
       //    user    : user Id, defaults to the logged in user
       //    ranking : ranking Id, defaults to the default ranking
       //    date    : show score up until this date,
       //              possible values 'now', 'postdate', a datetime value formatted like this 'Y-m-d H:i',
       //              defaults to 'now'
       //    text    : text to display if no user or no score is found, defaults to "0"
       public function shortcode_user_score( $atts ) {
       	extract( shortcode_atts( array(
       				'user' => '',
       				'ranking' => FOOTBALLPOOL_RANKING_DEFAULT,
       				'date' => 'now',
       				'text' => '0',
       			), $atts ) );
   
       	$output = $text;
   
       	if ( $user == '' || ! is_numeric( $user ) ) {
       		$user = get_current_user_id();
       	}
   
       	if ( ( int ) $user > 0 ) {
       		if ( $date == 'postdate' ) {
       			$score_date = get_the_date( 'Y-m-d H:i' );
       		} elseif ( ( $score_date = date_create( $date ) ) !== false ) {
       			$score_date = $score_date->format( 'Y-m-d H:i' );
       		} else {
       			$score_date = ''; // default aka now
       		}
   
       		$pool = new Football_Pool_Pool;
       		$score = $pool->get_user_score( $user, $ranking, $score_date );
       		if ( $score != null ) $output = $score;
       	}
   
       	return $output;
       }
       ```
   
 * I will release this code (after some more testing) in my next version.
 * p.s. This code was made in my development branch, so it is possible that it may
   not work in your code because of some missing functionality. I did not test it
   in an v2.2.x version of the plugin.
 *  Thread Starter [fanbolero](https://wordpress.org/support/users/fanbolero/)
 * (@fanbolero)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/shortcode-for-current-user-score/#post-3709589)
 * Thanks AntoineH,
 * It works like a charm!!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Shortcode for Current user Score’ is closed to new replies.

 * ![](https://ps.w.org/football-pool/assets/icon-256x256.png?rev=983880)
 * [Football Pool](https://wordpress.org/plugins/football-pool/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/football-pool/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/football-pool/)
 * [Active Topics](https://wordpress.org/support/plugin/football-pool/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/football-pool/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/football-pool/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [fanbolero](https://wordpress.org/support/users/fanbolero/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/shortcode-for-current-user-score/#post-3709589)
 * Status: resolved