Below, you’ll find a detailed guide on how to add the Profile Builder Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Profile Builder Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Profile Builder Plugin and the shortcodes it provides:
"User Profile Builder is a versatile WordPress plugin that enables seamless creation of beautiful user registration forms, user profiles, and user role editing. Make user management simple with Profile Builder."
- [compare]
- []
- [wppb-list-roles]
- [wppb-resend-activation]
- [user_meta]
- [wppb-restrict]
- [wppb-logout]
- [wppb-embed]
Profile Builder [compare] Shortcode
The Profile Builder Plugin shortcode, ‘compare’, performs comparison operations. It accepts three attributes: ‘val1’, ‘val2’, and ‘operator’. The ‘val1’ and ‘val2’ attributes represent values to compare, while ‘operator’ defines the type of comparison. Supported operators include ‘==’, ‘===’, ‘!=’, ‘<‘, ‘>’, ‘<=’, and ‘>=’. If the comparison is true, the shortcode returns the content enclosed within the shortcode. If the operator is not recognized, an error message is displayed.
Shortcode: [compare]
Parameters
Here is a list of all possible compare shortcode parameters and attributes:
val1
– The first value to be compared.val2
– The second value to be compared.operator
– The comparison operator. It can be ‘==’, ‘===’, ‘!=’, ‘<', '>‘, ‘<=', '>=’ or empty.
Examples and Usage
Basic example – The following example demonstrates how to use the ‘compare’ shortcode with two values and an ‘equals’ operator. If the two values are equal, the content inside the shortcode will be displayed.
[compare val1="10" val2="10" operator="==" ]Content to display if the condition is met[/compare]
Advanced examples
Here, the ‘compare’ shortcode is used to evaluate if one value is less than another. If ‘val1’ is less than ‘val2’, then the content inside the shortcode will be displayed.
[compare val1="5" val2="10" operator="<" ]Content to display if the condition is met[/compare]
In this next example, the ‘compare’ shortcode is used to evaluate if one value is not equal to another. If ‘val1’ is not equal to ‘val2’, then the content inside the shortcode will be displayed.
[compare val1="5" val2="10" operator="!=" ]Content to display if the condition is met[/compare]
Lastly, this example shows the ‘compare’ shortcode being used to evaluate if one value is greater than or equal to another. If ‘val1’ is greater than or equal to ‘val2’, then the content inside the shortcode will be displayed.
[compare val1="10" val2="5" operator=">=" ]Content to display if the condition is met[/compare]
PHP Function Code
In case you have difficulties debugging what causing issues with [compare]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'compare', 'wppb_toolbox_compare_shortcode' );
Shortcode PHP function:
function wppb_toolbox_compare_shortcode( $atts, $content ){
extract(
$out = shortcode_atts( array( 'val1' => '', 'val2' => '', 'operator' => ''), $atts )
);
foreach($out as $key => $value){
$out[$key] = str_replace('”', '', $value );
}
$l = $out['val1'];
$r = $out['val2'];
$operators = array(
'==' => function($l, $r) {
return $l == $r;
},
'===' => function($l, $r) {
return $l === $r;
},
'!=' => function($l, $r) {
return $l != $r;
},
'<' => function($l, $r) {
return $l < $r;
},
'>' => function($l, $r) {
return $l > $r;
},
'<=' => function($l, $r) {
return $l <= $r;
},
'>=' => function($l, $r) {
return $l >= $r;
},
'' => function($l, $r) {
return $l == $r;
},
);
if ( !array_key_exists($out['operator'], $operators ) )
return '<p>The compare operator <strong style="padding:0 10px;">' . $out["operator"] . '</strong> is not recognized. Please try: == , ===, !=, <, >, <=, >=';
$bool = $operators[$out['operator']]($l, $r);
if( $bool )
return do_shortcode( $content );
}
Code file location:
profile-builder/profile-builder/admin/advanced-settings/includes/shortcodes/compare.php
Profile Builder [wppb-list-roles] Shortcode
The Profile Builder Plugin shortcode, ‘wppb-list-roles’, lists user roles. It accepts a ‘user_id’ parameter, which can be multiple IDs separated by commas. If the ‘user_id’ parameter is provided, it lists the roles of the specified users. If no ‘user_id’ is given, it lists the roles of the current user. The roles are returned as a comma-separated string.
Shortcode: [wppb-list-roles]
Parameters
Here is a list of all possible wppb-list-roles shortcode parameters and attributes:
user_id
– specifies the user IDs to list the roles for
Examples and Usage
Basic example – Show the roles of a specific user by using their user ID.
[wppb-list-roles user_id=2 /]
Advanced examples
Display the roles of multiple users by listing their user IDs separated by commas. The roles will be displayed in the order of the user IDs provided.
[wppb-list-roles user_id=2,3,4 /]
Without specifying any user ID, the shortcode will default to showing the roles of the current logged-in user.
[wppb-list-roles /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wppb-list-roles]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wppb-list-roles', 'wppb_toolbox_list_roles_handler' );
Shortcode PHP function:
function wppb_toolbox_list_roles_handler($atts){
$args = shortcode_atts(
array(
'user_id' => array(),
),
$atts
);
$content = '';
if ( ! empty( $args['user_id'] ) )
{
$users_id = array_map( 'trim', explode( ',', $args['user_id'] ) );
$all_users = get_users();
foreach ( $all_users as $user )
{
if ( in_array( $user->ID, $users_id ) )
{
$roles_list = implode( ', ', $user->roles );
$content = $content . $roles_list . '<br>';
}
}
}
else {
$current_user = wp_get_current_user();
if ( ! empty( $current_user->roles ) ) {
$roles_list = implode( ', ', $current_user->roles );
$content = $content . $roles_list;
}
}
return do_shortcode( $content );
}
Code file location:
profile-builder/profile-builder/admin/advanced-settings/includes/shortcodes/list-roles.php
Profile Builder [wppb-resend-activation] Shortcode
The Profile Builder shortcode, ‘[wppb-resend-activation]’, triggers a function that generates a form allowing users to resend an activation email. The form includes an email input field and a submit button. Upon submission, the activation email is resent to the user. The form also includes various filters for customization.
Shortcode: [wppb-resend-activation]
Examples and Usage
Basic Example – The basic usage of the ‘wppb-resend-activation’ shortcode is to resend the activation email. This is particularly useful when the user has lost the initial activation email.
[wppb-resend-activation /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wppb-resend-activation]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wppb-resend-activation', 'wppb_toolbox_resend_activation_url_handler' );
Shortcode PHP function:
function wppb_toolbox_resend_activation_url_handler() {
$button_name = __('Resend activation email', 'profile-builder');
$output = '<form enctype="multipart/form-data" method="post" id="wppbc-resend_activation" class="wppb-user-forms" action="">';
$output .= '
<li class="wppb-form-field'. apply_filters( 'wppb_resend_activation_extra_css_class', '', 'resend_activation_email') .'">
<label for="username_email" style="padding-right: 30px;">'.__( 'Email', 'profile-builder' ).'</label>
<input class="text-input" name="email" type="text" id="username_email" value="" '. apply_filters( 'wppb_resend_activation_extra_attr', '', __( 'Email', 'profile-builder' ), 'text' ) .'/>
<div style="padding-top: 20px;">
<input name="resend_activation" type="submit" id="wppbc-resend-activation-button" class="submit button" value="'. $button_name . '" />
<input name="action" type="hidden" id="action" value="wppbc_resend_activation" />
<input type="hidden" name="wppb_nonce" value="'. esc_attr( wp_create_nonce( 'wppbc_resend_activation' ) ) . '" />
</div>
</li>
</form>';
// return $output;
return apply_filters('wppb_resend_activation_form_before_content_output', $output);
}
Code file location:
profile-builder/profile-builder/admin/advanced-settings/includes/shortcodes/resend-activation.php
Profile Builder [user_meta] Shortcode
The Profile Builder shortcode, ‘user_meta’, manages user metadata. It fetches specific user data based on the attributes provided. It checks for the user’s ID, size, prefix, postfix, and wpautop attributes. If not provided, default values are set. It restricts access to sensitive data such as ‘user_pass’ and ‘user_activation_key’. For the ‘avatar’ key, it returns the user’s avatar. For the ‘id’ key, it changes the key to ‘ID’. If the user property exists, it returns the value, formatted if ‘wpautop’ is ‘on’.
Shortcode: [user_meta]
Parameters
Here is a list of all possible user_meta shortcode parameters and attributes:
user_id
– Identifies the specific user by their ID.size
– Specifies the size of the user’s avatar.pre
– Add text or HTML before the user’s meta data.post
– Add text or HTML after the user’s meta data.wpautop
– Automatically adds paragraph tags to the user’s meta data.key
– Specifies which user meta data to display. ‘avatar’ for user’s avatar, ‘id’ for user’s ID, and any other valid user meta key.
Examples and Usage
Basic example – A simple way to use the shortcode to display the current user’s avatar with a size of 50.
[user_meta key="avatar" size="50" /]
Advanced examples
1. Displaying the current user’s avatar with a size of 100, adding a prefix and suffix text.
[user_meta key="avatar" size="100" pre="Avatar: " post=" End of Avatar" /]
2. Displaying a specific user’s (user_id=2) first name with a prefix and suffix.
[user_meta user_id="2" key="first_name" pre="First Name: " post=" End of First Name" /]
3. Displaying a specific user’s (user_id=3) bio with ‘wpautop’ parameter set to ‘on’ for automatic paragraph breaks.
[user_meta user_id="3" key="description" wpautop="on" /]
Note: The shortcode will not display anything for the keys ‘user_pass’ and ‘user_activation_key’ due to security reasons. Also, if the user or key does not exist, the shortcode will not return anything.
PHP Function Code
In case you have difficulties debugging what causing issues with [user_meta]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('user_meta', 'wppb_toolbox_usermeta_handler');
Shortcode PHP function:
function wppb_toolbox_usermeta_handler( $atts, $content=null){
if ( !isset( $atts['user_id'] ) ){
$user = wp_get_current_user();
$atts['user_id'] = $user->ID;
}
if ( !isset( $atts['size'] ) ){
$atts['size'] = '50';
}
if ( !isset( $atts['pre'] ) ) {
$atts['pre'] = '';
}
if ( !isset( $atts['post'] ) ) {
$atts['post'] = '';
}
if ( !isset( $atts['wpautop'] ) ) {
$atts['wpautop'] = '';
}
if( in_array( $atts['key'], array( 'user_pass', 'user_activation_key' ) ) )
return;
$user = new WP_User( $atts['user_id'] );
if ( !$user->exists() ) return;
if ( !array_key_exists( 'key', $atts ) ) return;
if( $atts['key'] == 'avatar' ){
return $atts['pre'] . get_avatar( $user->ID, $atts['size']) . $atts['post'] ;
}
if( $atts['key'] === 'id' ){
$atts['key'] = 'ID';
}
if ( $user->has_prop( $atts['key'] ) ){
if ($atts['wpautop'] == 'on'){
$value = wpautop( $user->get( $atts['key'] ) );
} else {
$value = $user->get( $atts['key'] );
}
}
if (!empty( $value )){
return $atts['pre'] . $value . $atts['post'] ;
}
return;
}
Code file location:
profile-builder/profile-builder/admin/advanced-settings/includes/shortcodes/usermeta.php
Profile Builder [wppb-restrict] Shortcode
The Profile Builder shortcode ‘wppb-restrict’ is designed to restrict content based on user roles and IDs. This shortcode checks if a user is logged in and their role or ID. If they match the specified criteria, the content is displayed. If not, a custom or default message is shown. The shortcode allows for content customization based on user status, enhancing user experience.
Shortcode: [wppb-restrict]
Parameters
Here is a list of all possible wppb-restrict shortcode parameters and attributes:
user_roles
– Defines the user roles that can view the contentdisplay_to
– Controls who can see content, either logged in or not logged in usersmessage
– The message displayed when content is restrictedusers_id
– Specifies the user IDs that can access the content
Examples and Usage
Basic example – A straightforward usage of the shortcode to restrict content based on user roles.
[wppb-restrict user_roles="subscriber, contributor" message="Sorry, this content is restricted." /]
Advanced examples
Using the shortcode to restrict content to specific users by their IDs. If the user is not logged in or their ID is not in the list, they will see the specified message.
[wppb-restrict users_id="1,2,3" message="This content is for specific users only." /]
Using the shortcode to display content only to logged out users. If a user is logged in, they will see the custom message.
[wppb-restrict display_to="not_logged_in" message="This content is only for visitors." /]
Using the shortcode to restrict content based on both user roles and specific user IDs. The content will be displayed if the logged-in user’s role or ID matches the specified values. If not, they will see the custom message.
[wppb-restrict user_roles="administrator" users_id="4,5,6" message="This content is for specific roles and users only." /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wppb-restrict]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wppb-restrict', 'wppb_content_restriction_shortcode' );
Shortcode PHP function:
function wppb_content_restriction_shortcode( $atts, $content = null ) {
$args = shortcode_atts(
array(
'user_roles' => array(),
'display_to' => '',
'message' => '',
'users_id' => array()
),
$atts
);
// Message to replace the content of checks do not match
if( ! empty( $args['message'] ) ) {
$message = '<span class="wppb-shortcode-restriction-message">' . $args['message'] . '</span>';
} else {
$type = ( is_user_logged_in() ? 'logged_in' : 'logged_out' );
$message = '<span class="wppb-content-restriction-message">' . wpautop( wppb_get_restriction_content_message( $type ) ) . '</span>';
}
/*
* Filter the message
*
* @param string $message - the current message, whether it is the default one from the settings or
* the one set in the shortcode attributes
* @param array $args - the shortcode attributes
*
*/
$message = apply_filters( 'wppb_content_restriction_shortcode_message', $message, $args );
if( is_user_logged_in() ) {
// Show for administrators
if( current_user_can( 'manage_options' ) ) {
return do_shortcode( $content );
}
if( $args['display_to'] == 'not_logged_in' ) {
return $message;
}
if( ! empty($args['users_id'] ) ){
$users_id=array_map('trim', explode(',', $args['users_id']));
$current_user_id = get_current_user_id(); // the current id user
if( ! empty($current_user_id)){
if(in_array($current_user_id, $users_id))
{
return do_shortcode( $content );
}
else{
return $message;
}
}
}
elseif( ! empty( $args['user_roles'] ) ) {
$user_roles = array_map( 'trim', explode( ',', $args['user_roles'] ) );
$user_data = get_userdata( get_current_user_id() );
if( ! empty( $user_data->roles ) ) {
$common_user_roles = array_intersect( $user_roles, $user_data->roles );
if( ! empty( $common_user_roles ) ) {
return do_shortcode( $content );
} else {
return $message;
}
}
} else {
return do_shortcode( $content );
}
} else {
if( $args['display_to'] == 'not_logged_in' ) {
return do_shortcode( $content );
} else {
return $message;
}
}
}
Code file location:
profile-builder/profile-builder/features/content-restriction/content-restriction-functions.php
Profile Builder [wppb-logout] Shortcode
The Profile Builder shortcode ‘wppb-logout’ is designed to manage user logout operations on the frontend. It first checks if a user is logged in. If so, it retrieves the user’s data. Depending on the ‘loginWith’ setting, it displays either the username or email. It then sets up the redirect URL for after logout. The shortcode also creates a logout link and replaces certain meta tags in the text with user data. Finally, it returns a logout message with the logout link.
Shortcode: [wppb-logout]
Parameters
Here is a list of all possible wppb-logout shortcode parameters and attributes:
text
– The message displayed when the user is logged in.redirect
– The URL to redirect to after logging out.redirect_url
– The default URL to redirect to after logging out.redirect_priority
– Defines the priority of the redirect.link_text
– The text displayed on the logout link.url_only
– If set to ‘yes’, only the logout URL will be returned.
Examples and Usage
Basic example – A simple usage of the shortcode to log out a user.
[wppb-logout /]
Advanced examples
Using the shortcode to log out a user and redirect them to a specific URL after logging out.
[wppb-logout redirect_url="http://example.com" /]
Customizing the logout message and link text using the shortcode.
[wppb-logout text="You are now logged out, %s." link_text="Logout Now" /]
Using the shortcode to only return the logout URL without any additional text or HTML.
[wppb-logout url_only="yes" /]
Customizing the logout message with user meta tags to include the user’s name in the message.
[wppb-logout text="Goodbye, {{meta_first_name}} {{meta_last_name}}. Come back soon." /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wppb-logout]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wppb-logout', 'wppb_front_end_logout' );
Shortcode PHP function:
function wppb_front_end_logout( $atts ) {
if( !is_user_logged_in() )
return;
$current_user = get_userdata( get_current_user_id() );
$wppb_generalSettings = get_option( 'wppb_general_settings' );
if( !empty( $wppb_generalSettings['loginWith'] ) && $wppb_generalSettings['loginWith'] == 'email' ) {
$display_username_email = $current_user->user_email;
}
else {
$display_username_email = $current_user->user_login;
}
extract(shortcode_atts(array('text' => sprintf(__('You are currently logged in as %s. ', 'profile-builder'), $display_username_email), 'redirect' => '', 'redirect_url' => wppb_curpageurl(), 'redirect_priority' => 'normal', 'link_text' => __('Log out »', 'profile-builder'), 'url_only' => ''), $atts));
if( ! empty( $redirect ) ) {
$redirect_url = $redirect;
}
// CHECK FOR REDIRECT
$redirect_url = wppb_get_redirect_url( $redirect_priority, 'after_logout', $redirect_url, $current_user );
$redirect_url = apply_filters( 'wppb_after_logout_redirect_url', $redirect_url );
if( isset( $url_only ) && $url_only == 'yes' )
return wp_logout_url( $redirect_url );
$logout_link = '<a href="' . wp_logout_url( $redirect_url ) . '" class="wppb-logout-url" title="' . __( 'Log out of this account', 'profile-builder' ) . '">' . $link_text . '</a>';
$meta_tags = apply_filters( 'wppb_front_end_logout_meta_tags', array( '{{meta_user_name}}', '{{meta_first_name}}', '{{meta_last_name}}', '{{meta_display_name}}' ) );
$meta_tags_values = apply_filters( 'wppb_front_end_logout_meta_tags_values', array( $current_user->user_login, $current_user->first_name, $current_user->last_name, $current_user->display_name ) );
$text = apply_filters( 'wppb_front_end_logout_text', str_replace( $meta_tags, $meta_tags_values, $text ), $current_user );
return apply_filters( 'wppb_logout_message', '<p class="wppb-front-end-logout"><span>' . $text . '</span>' . $logout_link . '</p>');
}
Code file location:
profile-builder/profile-builder/features/functions.php
Profile Builder [wppb-embed] Shortcode
The Profile Builder shortcode ‘wppb-embed’ is used to embed media content. It accepts width and height attributes for customization. If these are empty, it defaults to the WordPress embed settings.
Shortcode: [wppb-embed]
Parameters
Here is a list of all possible wppb-embed shortcode parameters and attributes:
width
– determines the width of the embedded contentheight
– sets the height of the embedded content
Examples and Usage
Basic example – Embeds a content without specifying width and height. The width and height will be set to default.
[wppb-embed]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/wppb-embed]
Advanced examples
Embeds a content with a specified width and height. The width is set to 500 and the height is set to 400.
[wppb-embed width="500" height="400"]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/wppb-embed]
Embeds a content with a specified width only. The width is set to 500 and the height will be set to default.
[wppb-embed width="500"]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/wppb-embed]
Embeds a content with a specified height only. The height is set to 400 and the width will be set to default.
[wppb-embed height="400"]https://www.youtube.com/watch?v=dQw4w9WgXcQ[/wppb-embed]
PHP Function Code
In case you have difficulties debugging what causing issues with [wppb-embed]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wppb-embed', 'wppb_embed');
Shortcode PHP function:
<pre class="wp-block-syntaxhighlighter-code">function wppb_embed($atts, $content){
$atts = shortcode_atts( array(
'width' => '',
'height' => ''
), $atts, 'wppb-embed' );
global $wp_embed;
if(empty($atts['width']) || empty($atts['height'])){
$content = $wp_embed->run_shortcode('<a href="http://'.$content.'">'.$content.'</a>');
} else {
$content = $wp_embed->run_shortcode('<a href="http://.'%20height='.$atts%5B'height'%5D.'%5D'.$content.'">.'" height="'.$atts['height'].'"]'.$content.'</a>');
}
return $content;
}</pre>
Code file location:
profile-builder/profile-builder/features/functions.php
Conclusion
Now that you’ve learned how to embed the Profile Builder Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply