WordPress.org

Ready to get started?Download WordPress

Forums

Football Pool
[resolved] Shortcode for Current User Position (8 posts)

  1. Joepiooo
    Member
    Posted 10 months ago #

    Is there a shortcode to display the current user position?

    That would be awesome:)

    http://wordpress.org/plugins/football-pool/

  2. AntoineH
    Member
    Plugin Author

    Posted 10 months ago #

    No there isn't, but it is relatively easy to code. So I'll add it to the next version.

  3. Joepiooo
    Member
    Posted 9 months ago #

    Ok very nice!:)

    When can we expect the next version? Or is it hard to say how long it is gonna take?

  4. AntoineH
    Member
    Plugin Author

    Posted 9 months ago #

    A few weeks. I am not planning any big changes in this release. Just some filters and actions that make the plugin more extensible.

  5. Joepiooo
    Member
    Posted 8 months ago #

    Hello,

    Did you manage to create the current user position allready? I tried it myselve but no luck so far... Would be a great add-on:)

    Thanks

    Best regards

  6. AntoineH
    Member
    Plugin Author

    Posted 8 months ago #

    Yes, the shortcode is finished. But the release is not yet finished. If you can't wait, you can download the latest development version here.

  7. Joepiooo
    Member
    Posted 8 months ago #

    Very nice!

    If I copy the shortcode form your class-football-pool-shortcodes.php en past it into mine... Is that enough or is there more coding in different files?

    I cant update your plugin because I changed to much and not in a child theme... :(

    My mistake... So I have to edit it myself

    Thanks:)

  8. AntoineH
    Member
    Plugin Author

    Posted 8 months ago #

    No, just copying the shortcode is not enough.

    Changes in classes\class-football-pool-shortcodes.php:
    1. Add the line
    add_shortcode( 'fp-user-ranking', array( 'Football_Pool_Shortcodes', 'shortcode_user_ranking' ) );

    2. Add the shortcode function inside the class:

    public function shortcode_user_ranking( $atts ) {
    		extract( shortcode_atts( array(
    					'user' => '',
    					'ranking' => FOOTBALLPOOL_RANKING_DEFAULT,
    					'date' => 'now',
    					'text' => '',
    				), $atts ) );
    
    		$output = $text;
    
    		if ( $user == '' || ! is_numeric( $user ) ) {
    			$user = get_current_user_id();
    		}
    
    		if ( ( int ) $user > 0 ) {
    			$pool = new Football_Pool_Pool;
    			$rank = $pool->get_user_rank( $user, $ranking, self::date_helper( $date ) );
    			if ( $rank != null ) $output = $rank;
    		}
    
    		return apply_filters( 'footballpool_shortcode_html_fp-user-ranking', $output );
    	}

    3. Add function get_user_rank() to the file classes\class-football-pool-pool.php:

    public function get_user_rank( $user, $ranking_id = FOOTBALLPOOL_RANKING_DEFAULT, $score_date = '' ) {
    		global $wpdb;
    		$prefix = FOOTBALLPOOL_DB_PREFIX;
    
    		$sql = $wpdb->prepare(
    						sprintf( "SELECT ranking FROM {$prefix}scorehistory
    								WHERE user_id = %%d AND ranking_id = %%d
    								AND ( %s score_date <= %%s )
    								ORDER BY score_date DESC LIMIT 1"
    								, ( $score_date == '' ? '1 = 1 OR' : '' )
    						) , $user, $ranking_id, $score_date );
    		return $wpdb->get_var( $sql ); // return null if nothing found
    	}

Reply

You must log in to post.

About this Plugin

About this Topic