WordPress.org

Ready to get started?Download WordPress

Forums

Bainternet User Ranks
[resolved] Tried PHP code in PHP widget and in theme - no dice... (16 posts)

  1. famousb
    Member
    Posted 3 years ago #

    i've installed and activated this plugin, and have tried putting the recommended code:

    <?php $baur_plugin = new baur_Plugin();
    $user_rank = $baur_plugin->ba_get_user_points($user_id,true);
    echo "title: ". $user_rank['title'] .
    "<br />Points: " . $user_rank['points'];?>

    in a PHP code widget in my sidebar, and also directly in my theme. Neither actually shows stats for posts or the title.

    What else needs to be done to get this to work?

  2. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    You need to set the $user_id in order to get results, for example if you want results for the current logged-in user the your widget code should look like this:

    //first check if a user has loogged-in
    if (is_user_logged_in()){
    	// then get the current user id using  get_currentuserinfo();
    	global $current_user;
    	get_currentuserinfo();
    	//then use the plugins class: and pass the current  user ID
    	$baur_plugin = new baur_Plugin();
    	$user_rank = $baur_plugin->ba_get_user_points($current_user->ID,true);
    	echo "title: ". $user_rank['title'] .
    	"<br />Points: " . $user_rank['points'];
    }
  3. famousb
    Member
    Posted 3 years ago #

    what about for users not logged in?

  4. famousb
    Member
    Posted 3 years ago #

    for user info while in a post by another user, i used:

    get_the_author_meta( 'ID' )

    in place of

    $current_user->ID
  5. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    @famousb as long as you pass an actual user id this will work, the plugin keeps score for users and can't keep score for guests. so if you want to display a rank and title of a registered user to guests it ok. and if you are using the plugin within the loop the you can just use:

    $post->post_author
    instead of

    get_the_author_meta( 'ID' )
    //or
    $current_user->ID
  6. paulson101
    Member
    Posted 3 years ago #

    I really need to be able to show a list of the top rated people on a site I am doing. Could you show me how to show a list to users if there is no one logged in please!

  7. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    you don't need anyone to be logged in, just get a list of your users ids and for each one you can use:

    $baur_plugin = new baur_Plugin();
    $user_rank = $baur_plugin->ba_get_user_points($user_id,true);
    echo "title: ". $user_rank['title'] ."<br />Points: " . $user_rank['points'];

    and each time change the $user_id.

    as for top rated you will need wait for the next update.

  8. paulson101
    Member
    Posted 3 years ago #

    I would really really appreciate a top rated. It is a very key part of the website I am setting up right now. And to my knowledge you are the only guy with this type of plugin.

    Do you have an estimate for how long before it is completed?

  9. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    @paulson101 done, check out the new version 1.3.0
    which has a new method to get top ranked and also a shortcode functionally for single user and top ranked user list.

    for usage instructions head to the faq section

  10. paulson101
    Member
    Posted 3 years ago #

    That looks really good! However I think I am doing something wrong with the shortcodes. they dont seem to give any values. I would love the php code that would give me a list of say the top 10 ranked users?

    I love the unlimited titles feature, that is super helpful!

    thanks for your hard work!

  11. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    @paulson101 like i said

    for usage instructions head to the faq section

    it has an example of top ranked php template tag usage.

  12. paulson101
    Member
    Posted 3 years ago #

    haha, I went there before and they weren't up for me. I see them now! this is excellent. However the shortcodes still do not work for me, but the PHP code did so that is awesome!

  13. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    care to provide some input on what exactly didn't work with the shortcodes ?

  14. paulson101
    Member
    Posted 3 years ago #

    well I have tried the shortcodes in posts, widgets, and in html/php templates. and they just show up as regular text?

    also when I use the code:

    <?php $baur_plugin = new baur_Plugin();
    $top_users = $baur_plugin->get_top_users(5);
    foreach ($top_users as $user){
    $user_info = get_userdata($user['user_id']);
    echo $user_info->user_login . "
    title: ". $user_rank['title'] . "
    Points: " . $user_rank['points'];
    echo "
    ";
    }
    ?>

    it shows a list of users,
    each user has the same amount of points as the person that is logged in,
    and it doesn't show if everyone is logged out?

    Any ideas?

  15. Bainternet
    Member
    Plugin Author

    Posted 3 years ago #

    yes i have an idea!

    you are using $user_rank which is not in the scope change your code to this:

    <?php $baur_plugin = new baur_Plugin();
    $top_users = $baur_plugin->get_top_users(5);
    foreach ($top_users as $user){
        $user_info = get_userdata($user['user_id']);
        echo $user_info->user_login . "title: ". $user['title'] ."Points: " . $user['points'];
    }
    ?>
  16. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Hi Bainternet! I need your help, as I am using your plugin. But am facing a little problem changing it to READ the ID of registered User Commenters.

    http://wordpress.org/support/topic/comment-author-ranks-close-to-being-done-need-help?replies=2#post-2160901

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic