Are those point ranges for badge points or for the user’s total points?
Each user has a user meta key of “_badgeos_points” that stores their current point total. Hopefully that helps a bit more.
Okay, can you help me a little more with the code?
By meta key of “_badgeos_points” what do you mean?
I should use:
if(_badgeos_points > 0 && _badgeos_points < 100)
return <span class=”level”>Level 1</span>
else if(_badgeos_points > 100 && _badgeos_points <250)
return <span class=”level”>Level 2</span>
?
Thanks
You’ll have to query for the user meta via get_user_meta() function. Codex reference
Basically assign that value to a variable like so
$user_points = get_user_meta( 1, '_badgeos_points', true );
if ( $user_points < '100' ) {
//Do something
} else if ( $user_points >= '100' && $user_points < '250' )
//Do something
} else {
//Sometihing default
}
Can’t recall offhand exactly how well the string data will compare against each other, but I think what you see above should be a nice start.
Feel free to ask more questions if confused.
Thank you for your answer, but I am having trouble to make this work!
I used the function above and got a white screen in my profile :/
could you paste what you tried exactly, so that I can help out. I did foolishly forget to say replace the first parameter with the actual user ID. If you need help retrieving that, I’ll have to type of a quick demo for that too.
Maybe it’d be best to ask your familiarity with php in general
Well, my familiarity with php is small, the basics I think.
What I tried:
<?php
$user_points = get_user_meta( 1, '_badgeos_points', true );
if ( $user_points < '100' ) {
echo <span class="badge-points"><?php _e( "Level 1", 'viewr' ); ?></span>
} else if ( $user_points >= '100' && $user_points < '250' )
echo <span class="badge-points"><?php _e( "Level 2", 'viewr' ); ?></span>
} else {
echo <span class="badge-points"><?php _e( "Level 0", 'viewr' ); ?></span>
}
?>
For some reason this code isnt working, the php tag dont close properly.
Also, if you can help me retrieving the current user id I will be grateful!
And thanks again for helping me out!
Yeah, that 1 in the get_user_meta corresponds to the current user ID, so you’ll need to actually change that part. Also as you noted, some php issues. Try this version below:
<?php
//Grabs the current user for the viewing of the page.
$current_user = wp_get_current_user();
//grab the points user meta value, based on current user's ID
$user_points = get_user_meta( $current_user->ID, '_badgeos_points', true );
if ( $user_points < '100' ) { ?>
<span class="badge-points"><?php _e( "Level 1", 'viewr' ); ?></span>
<?php
} else if ( $user_points >= '100' && $user_points < '250' ) { ?>
<span class="badge-points"><?php _e( "Level 2", 'viewr' ); ?></span>
<?php
} else { ?>
<span class="badge-points"><?php _e( "Level 0", 'viewr' ); ?></span>
<?php
}
?>
Thank you so much Michael! It worked perfectly!
You are awesome man!
š
// Edit
Another quick one, how can I make this code to work only if the badgeOS are present?
Something like:
<?php if (function_exists(‘badgeOS’)) {
//the above code here;
} else {}
?>
Your example above looks like it should work. I’d just make sure to confirm that “badgeOS” is the actual function name, case sensitive.
I only got it to work by checking if this function exists:
badgeos_get_achievements
Ah, if you were looking at this line:
class BadgeOS
you’d need to use class_exists()
The plugin is using Object Orientated style of programming, at least for a decent chunk of it.
Thank you very much for helping me with this!
I made a plugin to display the points in the members header without need to touch the members header file š
Next Step is to make a plugin to show the user level!
Hi Michael, me again!
Can you please take a look at this code?
http://pastebin.com/Va8gqLjC
Its the code that you helped me build, theres an error in some part, but as I said, I am not good with php.
Thanks again