Grab 75% Off Lifetime Access – Limited Time, Don't Miss Out!Get it NoW

BuddyPress User Field: Number of log entries to show

Navigation:

Description

In this short tutorial I will show you how you can setup a custom user field where your members can set how many rows myCRED should show when they are viewing their points history. If the user does not change this value, the default number of rows will be returned.

Requirements

  • myCRED 1.3 +
  • BuddyPress Add-on enabled
  • BuddyPress User Field Component enabled

The User Field

First, we need to create a custom user field which will hold the number of rows a user want to show. As with all user fields, we create them under the “Users” menu item in our admin area.

It does not matter under which group you save this field or what you call it. Just make sure you select “Text Field” as field type and make a note of the title you set.

Hooking into myCRED

The number of rows shown for each users points history is set by the mycred_bp_history_num_to_show filter. We can use this filter to grab our users set value and if it’s not empty, use that value.

add_filter( 'mycred_bp_history_num_to_show', 'buddypress_number_of_rows_to_show' );
function buddypress_number_of_rows_to_show( $num ) {
	$user_id = bp_displayed_user_id();
	$number = xprofile_get_field_data( 'Your User Fields Title', $user_id );
	if ( ! empty( $number ) )
		return $number;

	return $num;
}

Make sure you replace the above field name with your own title and make sure it matches exactly.

Done!

Add the above code to your themes functions.php file and upload. Once done, visit your BuddyPress profile and edit your settings. Set the number of rows you want to see and save. If you visit the myCRED Log page in your BuddyPress profile, you should now see the set number of rows (if there are that many).

11