Back to top
Table of Contents / PHP Guide

UserPro API

This documentation is for API and functions only. Looking for standard documentation?

Go to User Manual

UserPro is powered by a solid and powerful yet very easy API and functions that can help you do a lot of stuff just by writing little code. All available API functions will be introduced in this guide. Please read the introduction If you are new to UserPro API. You should have at least a minimal PHP knowledge to use and apply these functions in production mode.

Read the introduction first before exploring the functions. The functions will be listed in alphabetic order.

Introduction to UserPro API

In order to use any of the API functions, you must define a global at the top of your PHP file. This global will tell UserPro that you can access all functions and features of the API. Here is what you need to add to access the API:

<?php global $userpro; ?>

user_exists

Description

This function checks if user exists in your system or not.

Usage


	<?php

	$userpro->user_exists( $user_id );

	?>
	

Parameters

Returns

Return true if user exists, and false if user does not exist.

Examples


	<?php

	if ( $userpro->user_exists( 18 ) ) { // Check if user (18) exists
		// user exists
	} else {
		// user does not exist
	}

	?>
	

Function Reference

userpro_profile_data

Description

This function can output any profile information for a given user. For example, to display user's display name, role, or any other custom field with PHP.

Usage


	<?php

	userpro_profile_data( $field, $user_id );

	?>
	

Parameters

Returns

Return the value of custom field stored for that user (If it exists)

Examples

Display the user's role of admin (User ID: 1)


	<?php echo userpro_profile_data('role', 1); ?>
	

Display user's display name


	<?php echo userpro_profile_data('display_name', 75); ?>
	

userpro_show_badges

Description

This function will output all user earned badges.

Usage


	<?php

	userpro_show_badges( $user_id, $inline=false );

	?>
	

Parameters

Returns

This will return the user badges

Examples

Display the badges of user's ID 5


	<?php echo userpro_show_badges(5); ?>
	

Display user's badges of a comment author (for use in theme comments)


	<?php echo userpro_show_badges( $comment->user_id, $inline=true ); ?>
	

Display user badges for post author


	<?php echo userpro_show_badges( get_the_author_meta('ID') ); ?>
	

Hooks: Filters

userpro_before_value_is_displayed

This filter hook runs before the profile information (custom fields) are displayed in User Profile. Allowing you to tweak and integrate whatever functions or conditions you need to apply to the returned custom field value.

Usage Example

This is an example that modifies the custom field value of user gender output to say something custom, instead of just showing Male or Female.


	<?php
	
	add_filter('userpro_before_value_is_displayed', 'userpro_gender_value', 99, 4);
	function userpro_gender_value($value, $key, $array, $user_id) {
		
		/*
			In this example, we check if custom field key is gender
			and if value is Male/Female we adjust what is the value returned easily
		*/
		if ($key == 'gender') {
			if ($value == 'Male') {
				return 'I am Male!';
			} else {
				return 'I am Female!';
			}
		}
		
		return $value;
	}

	?>
	

userpro_user_profile_url

This filter hook helps you modify the profile permalink for users which is the frontend user profile by default. For example, If you want to convert all frontend profile links to specific user pages (Author archive, etc.)

Usage Example

Here is an example of using this hook to modify the profile permalink to author archive URL dynamically.


	<?php
	
	add_filter('userpro_user_profile_url', 'userpro_author_url', 99, 2);
	function userpro_author_url($link, $user_id) {
		return get_author_posts_url( $user_id );
	}

	?>