Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author AntoineH

    (@antoineh)

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

    Thread Starter Joepiooo

    (@joepiooo)

    Ok very nice!:)

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

    Plugin Author AntoineH

    (@antoineh)

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

    Thread Starter Joepiooo

    (@joepiooo)

    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

    Plugin Author AntoineH

    (@antoineh)

    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.

    Thread Starter Joepiooo

    (@joepiooo)

    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:)

    Plugin Author AntoineH

    (@antoineh)

    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
    	}

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Shortcode for Current User Position’ is closed to new replies.