Hi Justin,
Majority of “WordPress development” is going to be PHP development, and all of the fundamentals of PHP are going to apply.
We’ll use the snippet you pointed out for a good example to start with.
badgeos_get_users_points
is one of the functions that was defined in the BadgeOS plugin as a “helper” function to achieve a bigger task. It’s also able to be used on its own.
Inside the /badgeos/includes/points-functions.php file is the following:
function badgeos_get_users_points( $user_id = 0 ) {
// Use current user's ID if none specified
if ( ! $user_id )
$user_id = wp_get_current_user()->ID;
// Return our user's points as an integer (sanely falls back to 0 if empty)
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
It takes one parameter, $user_id, an integer, and that parameter defaults to 0. It will use the 0 value if no other integer value is passed in. The if ( ! $user_id )
line is a boolean check that if the $user_id has an integer value. In this case, the default 0 will be “false”. The exclamation mark is checking that a value of “false” is “true”. If that evaluates to “false is true”, it will grab the ID of the current user. Anything above 0 would be “true is true” and the $user_id = wp_get_current_user()->ID;
line would be skipped.
This allows you to use this function for whichever user may be viewing the page at the time, or a specific user.
After that, it *returns* the absolute integer value of the user meta value stored for the specified user. Which, in this case, will be their total points.
How the function returns data to the server is important. In this case, it returns the value, which allows you to use it in other code or assign to variables for further processing. To display it to the browser, you have to echo the value.
If this line:
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
was
echo absint( get_user_meta( $user_id, '_badgeos_points', true ) );
,
then all you’d have to do to use it is
badgeos_get_users_points()
or badgeos_get_users_points(4)
Hopefully this is a good start.
Function references:
https://codex.www.ads-software.com/Function_Reference/absint