Ultimate Member Shortcodes

Below, you’ll find a detailed guide on how to add the Ultimate Member 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 Ultimate Member Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Ultimate Member Plugin and the shortcodes it provides:

Plugin Icon
Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin

"Ultimate Member is a versatile WordPress plugin that provides user profile creation, registration, login, member directory, content restriction, and membership management functionality."

★★★★✩ (1396) Active Installs: 200000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [ultimatemember_account]
  • [ultimatemember_password]
  • [ultimatemember]
  • [ultimatemember_login]
  • [ultimatemember_register]
  • [ultimatemember_profile]
  • [ultimatemember_directory]
  • [um_loggedin]
  • [um_loggedout]
  • [um_show_content]
  • [ultimatemember_searchform]

Ultimate Member [ultimatemember_account] Shortcode

The Ultimate Member Account shortcode enables the display of user account information. If the user is not logged in, it returns an empty string. It uses the ‘shortcode_atts_ultimatemember_account’ filter to customize arguments. It also has a singleton feature to prevent rendering the same form multiple times on one page. The shortcode allows tab selection, with ‘general’ as the default if ‘account’ is chosen. If a specific tab is selected, it renders the account form for that tab. If no tab is specified, it loads the default form. Shortcode: [ultimatemember_account]

Shortcode: [ultimatemember_account]

Parameters

Here is a list of all possible ultimatemember_account shortcode parameters and attributes:

  • template – specifies the template to be used for the account
  • mode – determines the mode of the shortcode, typically ‘account’
  • form_id – the unique identifier for the form
  • tab – determines the current tab displayed in the account

Examples and Usage

Basic example – Display the Ultimate Member Account form on a page.

[ultimatemember_account]

Advanced examples

Display the Ultimate Member Account form with a specific tab open. In this case, the ‘general’ tab will be open by default when the form is loaded.

[ultimatemember_account tab="general"]

Display the Ultimate Member Account form with a specific template. In this case, the ‘custom_account’ template will be used to display the form.

[ultimatemember_account template="custom_account"]

Combine multiple attributes to customize the Ultimate Member Account form. In this case, the ‘custom_account’ template will be used, and the ‘password’ tab will be open by default.

[ultimatemember_account template="custom_account" tab="password"]

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_account] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_account', array( &$this, 'ultimatemember_account' ) );

Shortcode PHP function:

function ultimatemember_account( $args = array() ) {
			if ( ! is_user_logged_in() ) {
				return '';
			}

			um_fetch_user( get_current_user_id() );

			/** There is possible to use 'shortcode_atts_ultimatemember_account' filter for getting customized $args. This filter is documented in wp-includes/shortcodes.php "shortcode_atts_{$shortcode}" */
			$args = shortcode_atts(
				array(
					'template' => 'account',
					'mode'     => 'account',
					'form_id'  => 'um_account_id',
					'tab'      => '',
				),
				$args,
				'ultimatemember_account'
			);

			/**
			 * Filters Account shortcode arguments.
			 *
			 * @since 1.3.x
			 * @hook  um_account_shortcode_args_filter
			 * @deprecated 2.6.9
			 *
			 * @param {array} $args Shortcode arguments.
			 *
			 * @return {array} Shortcode arguments.
			 *
			 * @example <caption>Change Account arguments.</caption>
			 * function my_account_shortcode_args( $args ) {
			 *     $args['tab'] = 'password';
			 *     return $args;
			 * }
			 * add_filter( 'um_account_shortcode_args_filter', 'my_account_shortcode_args' );
			 */
			$args = apply_filters_deprecated( 'um_account_shortcode_args_filter', array( $args ), '2.6.9', 'shortcode_atts_ultimatemember_account' );

			$account_hash = md5( wp_json_encode( $args ) );

			/**
			 * Filters variable for enable singleton shortcode loading on the same page.
			 * Note: Set it to `false` if you don't need to render the same form twice or more on the same page.
			 *
			 * @since 2.6.9
			 *
			 * @hook  um_ultimatemember_account_shortcode_disable_singleton
			 *
			 * @param {bool}  $disable Disabled singleton. By default, it's `true`.
			 * @param {array} $args    Shortcode arguments.
			 *
			 * @return {bool} Disabled singleton or not.
			 *
			 * @example <caption>Turn off ability to use ultimatemember_account shortcode twice.</caption>
			 * add_filter( 'um_ultimatemember_account_shortcode_disable_singleton', '__return_false' );
			 */
			$disable_singleton_shortcode = apply_filters( 'um_ultimatemember_account_shortcode_disable_singleton', true, $args );
			if ( false === $disable_singleton_shortcode && in_array( $account_hash, $this->account_exist, true ) ) {
				return '';
			}

			ob_start();

			if ( ! empty( $args['tab'] ) ) {

				if ( 'account' === $args['tab'] ) {
					$args['tab'] = 'general';
				}

				$this->init_tabs( $args );

				$this->current_tab = $args['tab'];

				if ( ! empty( $this->tabs[ $args['tab'] ] ) ) { ?>
					<div class="um um-custom-shortcode-tab">
						<div class="um-form">
							<form method="post" action="">
								<?php
								/**
								 * Fires for render account form hidden fields.
								 *
								 * @since 1.3.x
								 * @hook um_account_page_hidden_fields
								 *
								 * @param {array} $args Account shortcode arguments.
								 *
								 * @example <caption>Make some action before account tab loading.</caption>
								 * function my_account_page_hidden_fields( $args ) {
								 *     // your code here
								 * }
								 * add_action( 'um_account_page_hidden_fields', 'my_account_page_hidden_fields' );
								 */
								do_action( 'um_account_page_hidden_fields', $args );

								$this->render_account_tab( $args['tab'], $this->tabs[ $args['tab'] ], $args );
								?>
							</form>
						</div>
					</div>
					<?php
				}
			} else {

				$this->init_tabs( $args );

				/**
				 * Filters Account shortcode default tab.
				 *
				 * @since 2.0
				 * @hook  um_change_default_tab
				 *
				 * @param {string} $tab  Current account tab.
				 * @param {array}  $args Shortcode arguments.
				 *
				 * @return {string} Current account tab.
				 *
				 * @example <caption>Change Account default tab to Password.</caption>
				 * function my_um_change_default_tab( $tab, $args ) {
				 *     $tab = 'password';
				 *     return $tab;
				 * }
				 * add_filter( 'um_change_default_tab', 'my_um_change_default_tab, 10, 2 );
				 */
				$this->current_tab = apply_filters( 'um_change_default_tab', $this->current_tab, $args );

				/** This filter is documented in includes/core/class-shortcodes.php */
				do_action( "um_pre_{$args['mode']}_shortcode", $args );
				/** This filter is documented in includes/core/class-shortcodes.php */
				do_action( 'um_before_form_is_loaded', $args );
				/** This filter is documented in includes/core/class-shortcodes.php */
				do_action( "um_before_{$args['mode']}_form_is_loaded", $args );

				UM()->shortcodes()->template_load( $args['template'], $args );
			}

			if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
				UM()->shortcodes()->dynamic_css( $args );
			}

			$output = ob_get_clean();

			$this->account_fields_hash();

			$this->account_exist[] = $account_hash;

			return $output;
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-account.php

Ultimate Member [ultimatemember_password] Shortcode

The Ultimate Member Password shortcode is designed to manage password reset functionality. It customizes the password reset form’s appearance and behavior. This shortcode allows you to define the template, mode, form ID, maximum width, and alignment of the password reset form. It also allows for custom settings, providing flexibility in its implementation. In addition, it enables the use of cookies to populate hidden fields for the password reset form, enhancing user experience and security. The shortcode ensures the form is properly loaded and displayed, with dynamic CSS for non-admin users.

Shortcode: [ultimatemember_password]

Parameters

Here is a list of all possible ultimatemember_password shortcode parameters and attributes:

  • template – Specifies the type of template for the password form
  • mode – Determines the mode of the form, which is ‘password’ by default
  • form_id – Unique identifier of the password reset form
  • max_width – Sets the maximum width of the form
  • align – Aligns the form to ‘center’ by default
  • use_custom_settings – Allows usage of custom settings if not empty
  • rp_key – Key used for resetting the password
  • login – Holds the login credentials for resetting password

Examples and Usage

Basic example – A simple usage of the shortcode to reset the password. Here, the shortcode is used with its default parameters.

[ultimatemember_password /]

Advanced examples

Modifying the shortcode to change the alignment of the form. Here, the shortcode is used with an additional parameter to align the form to the right.

[ultimatemember_password align="right" /]

Using the shortcode to customize the form further. In this example, the shortcode is used with additional parameters to set the maximum width of the form and to change the mode to ‘change password’.

[ultimatemember_password max_width="500px" mode="change" /]

Utilizing the shortcode to use a custom template for the form. Here, the shortcode is used with an additional parameter to specify a custom template for the form.

[ultimatemember_password template="custom-password-reset" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_password] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_password', array( &$this, 'ultimatemember_password' ) );

Shortcode PHP function:

function ultimatemember_password( $args = array() ) {
			/** There is possible to use 'shortcode_atts_ultimatemember_password' filter for getting customized $atts. This filter is documented in wp-includes/shortcodes.php "shortcode_atts_{$shortcode}" */
			$args = shortcode_atts(
				array(
					'template'  => 'password-reset',
					'mode'      => 'password',
					'form_id'   => 'um_password_id',
					'max_width' => '450px',
					'align'     => 'center',
				),
				$args,
				'ultimatemember_password'
			);

			if ( empty( $args['use_custom_settings'] ) ) {
				$args = array_merge( $args, UM()->shortcodes()->get_css_args( $args ) );
			} else {
				$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
			}
			/**
			 * Filters extend Reset Password Arguments
			 *
			 * @since 1.3.x
			 * @hook  um_reset_password_shortcode_args_filter
			 *
			 * @param {array} $args Shortcode arguments.
			 *
			 * @return {array} Shortcode arguments.
			 *
			 * @example <caption>Extend Reset Password Arguments.</caption>
			 * function my_reset_password_shortcode_args( $args ) {
			 *     // your code here
			 *     return $args;
			 * }
			 * add_filter( 'um_reset_password_shortcode_args_filter', 'my_reset_password_shortcode_args', 10, 1 );
			 */
			$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );

			if ( false !== $this->change_password ) {
				// then COOKIE are valid then get data from them and populate hidden fields for the password reset form
				$args['template'] = 'password-change';
				$args['rp_key']   = '';
				$rp_cookie        = 'wp-resetpass-' . COOKIEHASH;
				if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
					list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );

					$args['login']  = $rp_login;
					$args['rp_key'] = $rp_key;
				}
			}

			if ( empty( $args['mode'] ) || empty( $args['template'] ) ) {
				return '';
			}

			UM()->fields()->set_id = absint( $args['form_id'] );

			ob_start();

			/** This filter is documented in includes/core/class-shortcodes.php */
			do_action( "um_pre_{$args['mode']}_shortcode", $args );
			/** This filter is documented in includes/core/class-shortcodes.php */
			do_action( 'um_before_form_is_loaded', $args );
			/** This filter is documented in includes/core/class-shortcodes.php */
			do_action( "um_before_{$args['mode']}_form_is_loaded", $args );

			UM()->shortcodes()->template_load( $args['template'], $args );

			if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
				UM()->shortcodes()->dynamic_css( $args );
			}

			return ob_get_clean();
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-password.php

Ultimate Member [ultimatemember] Shortcode

The Ultimate Member shortcode is a powerful tool for WordPress developers. It enables the creation and customization of user forms on a website. The shortcode allows you to define a ‘form_id’ and an ‘is_block’ parameter. The ‘form_id’ is the unique identifier for each form, while ‘is_block’ determines if the form is a block element or not. A significant feature of this shortcode is the ‘um_ultimatemember_shortcode_disable_singleton’ filter. This filter controls whether the same form can be rendered multiple times on a single page. By default, it’s set to ‘true’, meaning the form will only appear once. However, you can override this by setting it to ‘false’. In conclusion, the Ultimate Member shortcode offers flexibility and control over user form creation and display in WordPress.

Shortcode: [ultimatemember]

Parameters

Here is a list of all possible ultimatemember shortcode parameters and attributes:

  • form_id – Unique identifier of the Ultimate Member form
  • is_block – Determines if the form should be displayed as a block

Examples and Usage

Basic Example – A shortcode to display a form using its ID.

[ultimatemember form_id=1 /]

Advanced Examples

Displaying a form with the ID, and specifying the ‘is_block’ parameter. If ‘is_block’ is set to true, the form will be displayed as a block element.

[ultimatemember form_id=1 is_block=true /]

Using the shortcode to display a form by referencing the ID and disabling the singleton. This allows the same form to be rendered multiple times on the same page.

[ultimatemember form_id=1 disable_singleton=false /]

Using the shortcode to display a form by referencing the ID and enabling the singleton. This will prevent the same form from being rendered multiple times on the same page.

[ultimatemember form_id=1 disable_singleton=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember', array( &$this, 'ultimatemember' ) );

Shortcode PHP function:

function ultimatemember( $args = array() ) {
			// There is possible to use 'shortcode_atts_ultimatemember' filter for getting customized `$args`.
			$args = shortcode_atts(
				array(
					'form_id'  => '',
					'is_block' => false,
				),
				$args,
				'ultimatemember'
			);

			// Sanitize shortcode arguments.
			$args['form_id']  = ! empty( $args['form_id'] ) ? absint( $args['form_id'] ) : '';
			$args['is_block'] = (bool) $args['is_block'];

			/**
			 * Filters variable for enable singleton shortcode loading on the same page.
			 * Note: Set it to `false` if you don't need to render the same form twice or more on the same page.
			 *
			 * @since 2.6.8
			 * @since 2.6.9 $disable argument set to `true` by default
			 *
			 * @hook  um_ultimatemember_shortcode_disable_singleton
			 *
			 * @param {bool}  $disable Disabled singleton. By default, it's `true`.
			 * @param {array} $args    Shortcode arguments.
			 *
			 * @return {bool} Disabled singleton or not.
			 *
			 * @example <caption>Turn off ability to use ultimatemember shortcode twice.</caption>
			 * add_filter( 'um_ultimatemember_shortcode_disable_singleton', '__return_false' );
			 */
			$disable_singleton_shortcode = apply_filters( 'um_ultimatemember_shortcode_disable_singleton', true, $args );
			if ( false === $disable_singleton_shortcode ) {
				if ( isset( $args['form_id'] ) ) {
					$id = $args['form_id'];
					if ( isset( $this->forms_exist[ $id ] ) && true === $this->forms_exist[ $id ] ) {
						return '';
					}
					$this->forms_exist[ $id ] = true;
				}
			}

			return $this->load( $args );
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [ultimatemember_login] Shortcode

The Ultimate Member Login shortcode is a handy tool that enables users to log in to a website. It fetches the default login ID from the database and generates a login form.

Shortcode: [ultimatemember_login]

Parameters

Here is a list of all possible ultimatemember_login shortcode parameters and attributes:

  • form_id – Identifier of the default login form
  • meta_key – Specifies the type of user metadata
  • meta_value – Specifies the value of the user metadata
  • version – Version of the WordPress installation

Examples and Usage

Basic example – A simple way to use the ‘ultimatemember_login’ shortcode is to call it without any additional parameters. This will display the default login form.

[ultimatemember_login /]

Advanced examples

It is possible to customize the ‘ultimatemember_login’ shortcode by adding parameters. For instance, you can specify the form_id to display a specific login form.

[ultimatemember_login form_id=3 /]

You can also add multiple parameters to further customize the shortcode. In the following example, we’re specifying both the form_id and setting a custom redirect URL after successful login.

[ultimatemember_login form_id=3 redirect_url="http://yourwebsite.com/welcome" /]

Remember that the parameters you can use depend on the functionality provided by the ‘ultimatemember_login’ shortcode. Always refer to the plugin’s documentation for a list of available parameters and their usage.

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_login', array( &$this, 'ultimatemember_login' ) );

Shortcode PHP function:

function ultimatemember_login( $args = array() ) {
			global $wpdb;

			$args = ! empty( $args ) ? $args : array();

			$default_login = $wpdb->get_var(
				"SELECT pm.post_id
				FROM {$wpdb->postmeta} pm
				LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
				WHERE pm.meta_key = '_um_mode' AND
					  pm.meta_value = 'login' AND
					  pm2.meta_value = '1'"
			);

			$args['form_id'] = $default_login;
			$shortcode_attrs = '';
			foreach ( $args as $key => $value ) {
				$shortcode_attrs .= " {$key}=\"{$value}\"";
			}

			if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
				return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
			} else {
				return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
			}
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [ultimatemember_register] Shortcode

The Ultimate Member Register shortcode is a powerful tool. It pulls the default registration form ID from the database and applies it to the ‘ultimatemember’ shortcode. This allows users to register directly on your site. It checks the WordPress version and applies the suitable shortcode function accordingly.

Shortcode: [ultimatemember_register]

Parameters

Here is a list of all possible ultimatemember_register shortcode parameters and attributes:

  • args – array of additional arguments for the shortcode
  • form_id – unique identifier of the registration form
  • meta_key – key used for custom fields in the database
  • meta_value – value associated with the meta_key
  • post_id – unique identifier of the post
  • version_compare – function to compare WordPress versions
  • get_bloginfo('version') – retrieves the current WordPress version
  • do_shortcode – function to execute a shortcode
  • apply_shortcodes – function to apply all shortcodes

Examples and Usage

Basic example – The simple usage of the shortcode to display the default registration form.

[ultimatemember_register /]

Advanced examples

Displaying the registration form by specifying the form id. This allows you to choose which form to display when you have multiple registration forms.

[ultimatemember_register form_id=2 /]

Another advanced usage is to display a registration form with custom attributes. The shortcode allows you to add custom attributes to the form like ‘name’ and ’email’.

[ultimatemember_register form_id=2 name="John Doe" email="john.doe@example.com" /]

In this example, the registration form will be displayed with the name field pre-filled as ‘John Doe’ and the email field as ‘john.doe@example.com’.

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_register] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_register', array( &$this, 'ultimatemember_register' ) );

Shortcode PHP function:

function ultimatemember_register( $args = array() ) {
			global $wpdb;

			$args = ! empty( $args ) ? $args : array();

			$default_register = $wpdb->get_var(
				"SELECT pm.post_id
				FROM {$wpdb->postmeta} pm
				LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
				WHERE pm.meta_key = '_um_mode' AND
					  pm.meta_value = 'register' AND
					  pm2.meta_value = '1'"
			);

			$args['form_id'] = $default_register;
			$shortcode_attrs = '';
			foreach ( $args as $key => $value ) {
				$shortcode_attrs .= " {$key}=\"{$value}\"";
			}

			if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
				return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
			} else {
				return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
			}
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [ultimatemember_profile] Shortcode

The Ultimate Member Profile shortcode is designed to retrieve and display the default user profile. It uses the global WordPress database variable to fetch the profile ID. This shortcode takes optional arguments, which it uses to build a new shortcode. The newly created shortcode is then processed and its output is returned. The function checks the WordPress version to ensure compatibility, using the appropriate function to process the shortcode based on the version.

Shortcode: [ultimatemember_profile]

Parameters

Here is a list of all possible ultimatemember_profile shortcode parameters and attributes:

  • form_id – Specifies the ID of the default Ultimate Member profile form.
  • version – The WordPress version to use the appropriate shortcode function.
  • meta_key – Used to fetch data related to the Ultimate Member profile.
  • meta_value – Used to confirm the meta_key’s associated value.

Examples and Usage

Basic example – A shortcode to display the default profile form in Ultimate Member.

[ultimatemember_profile /]

Advanced examples

Display a specific profile form by passing the form_id parameter.

[ultimatemember_profile form_id=2 /]

Passing multiple parameters to modify the behavior of the shortcode. Here, we are passing form_id and a hypothetical parameter ‘layout’ to customize the form’s appearance.

[ultimatemember_profile form_id=3 layout="grid" /]

Please note that the ‘layout’ parameter is hypothetical and may not work unless the Ultimate Member plugin has been customized to accept and process this parameter. Always check the plugin’s documentation or source code to understand which parameters are accepted.

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_profile] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_profile', array( &$this, 'ultimatemember_profile' ) );

Shortcode PHP function:

function ultimatemember_profile( $args = array() ) {
			global $wpdb;

			$args = ! empty( $args ) ? $args : array();

			$default_profile = $wpdb->get_var(
				"SELECT pm.post_id
				FROM {$wpdb->postmeta} pm
				LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
				WHERE pm.meta_key = '_um_mode' AND
					  pm.meta_value = 'profile' AND
					  pm2.meta_value = '1'"
			);

			$args['form_id'] = $default_profile;

			$shortcode_attrs = '';
			foreach ( $args as $key => $value ) {
				$shortcode_attrs .= " {$key}=\"{$value}\"";
			}

			if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
				return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
			} else {
				return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
			}
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [ultimatemember_directory] Shortcode

The Ultimate Member Directory shortcode retrieves the default directory ID from the database. It uses this ID to generate a shortcode, which, when executed, displays the default user directory.

Shortcode: [ultimatemember_directory]

Parameters

Here is a list of all possible ultimatemember_directory shortcode parameters and attributes:

  • args – array of arguments to customize the directory
  • form_id – specifies the ID of the default directory

Examples and Usage

Basic example – The following shortcode is a basic usage of the ‘ultimatemember_directory’ shortcode. Here, we are not passing any parameters, hence it will fetch the default directory.

[ultimatemember_directory /]

Advanced examples

In this example, we are passing the ‘form_id’ parameter to the shortcode. This will fetch the directory associated with the specified form id.

[ultimatemember_directory form_id=2 /]

In this example, we are passing multiple parameters to the shortcode. The ‘form_id’ parameter specifies the form id, and the ‘version’ parameter specifies the version of the directory to fetch. This will fetch the directory associated with the specified form id and version.

[ultimatemember_directory form_id=2 version='5.4' /]

Note: Replace ‘2’ and ‘5.4’ with your actual form id and version respectively.

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_directory] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_directory', array( &$this, 'ultimatemember_directory' ) );

Shortcode PHP function:

function ultimatemember_directory( $args = array() ) {
			global $wpdb;

			$args = ! empty( $args ) ? $args : array();

			$default_directory = $wpdb->get_var(
				"SELECT pm.post_id
				FROM {$wpdb->postmeta} pm
				LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
				WHERE pm.meta_key = '_um_mode' AND
					  pm.meta_value = 'directory' AND
					  pm2.meta_value = '1'"
			);

			$args['form_id'] = $default_directory;

			$shortcode_attrs = '';
			foreach ( $args as $key => $value ) {
				$shortcode_attrs .= " {$key}=\"{$value}\"";
			}

			if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
				return do_shortcode( "[ultimatemember {$shortcode_attrs} /]" );
			} else {
				return apply_shortcodes( "[ultimatemember {$shortcode_attrs} /]" );
			}
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [um_loggedin] Shortcode

The Ultimate Member shortcode, ‘um_loggedin’, is designed to restrict content visibility based on user login status. This shortcode displays a customizable message to users who are not logged in, prompting them to log in to view the content. If a user is logged in, the shortcode displays the content. It also supports locker tags and is compatible with WordPress versions 5.4 and below.

Shortcode: [um_loggedin]

Parameters

Here is a list of all possible um_loggedin shortcode parameters and attributes:

  • lock_text – The message displayed when users are not logged in
  • show_lock – Controls whether to show the locked content message or not

Examples and Usage

Basic example – The following shortcode displays a default message and a login link to the users who are not logged in.

[um_loggedin]

Advanced Examples

Customizing the locked content message. This shortcode will display a custom message to the users who are not logged in. The “{login_referrer}” placeholder will be replaced by the actual login page URL.

[um_loggedin lock_text="You need to log in to view this content."]

Hide the locked content message. This shortcode will hide the locked content message for users who are not logged in. Instead, they will see nothing.

[um_loggedin show_lock="no"]

Combining multiple parameters. This shortcode will display a custom message to the users who are not logged in, but if the “show_lock” parameter is set to “no”, they will see nothing.

[um_loggedin lock_text="You need to log in to view this content." show_lock="no"]

PHP Function Code

In case you have difficulties debugging what causing issues with [um_loggedin] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'um_loggedin', array( &$this, 'um_loggedin' ) );

Shortcode PHP function:

function um_loggedin( $args = array(), $content = "" ) {
			ob_start();

			$args = shortcode_atts(
				array(
					'lock_text' => __( 'This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.', 'ultimate-member' ),
					'show_lock' => 'yes',
				),
				$args,
				'um_loggedin'
			);

			if ( ! is_user_logged_in() ) {
				if ( 'no' === $args['show_lock'] ) {
					echo '';
				} else {
					$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
					UM()->get_template( 'login-to-view.php', '', $args, true );
				}
			} else {
				if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
					echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
				} else {
					echo apply_shortcodes( $this->convert_locker_tags( wpautop( $content ) ) );
				}
			}

			$output = ob_get_clean();

			return htmlspecialchars_decode( $output, ENT_NOQUOTES );
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [um_loggedout] Shortcode

The Ultimate Member ‘um_loggedout’ shortcode is designed to display content only to logged-out users. It checks if a user is logged in and then decides whether to display content. The PHP function ‘um_loggedout’ initiates with an empty output buffer. If the user is logged in, it echoes an empty string. If not, it echoes the content. The final output is then returned.

Shortcode: [um_loggedout]

Examples and Usage

Basic example – The shortcode below will display the content if the user is not logged in. If the user is logged in, the content will be hidden.

[um_loggedout]Your content here[/um_loggedout]

Advanced examples

Displaying a login form to non-logged-in users, while logged-in users will not see anything. If the WordPress version is below 5.4, the shortcode will use the wpautop function to add paragraph tags. If the version is 5.4 or higher, it will use the apply_shortcodes function instead.

[um_loggedout][contact-form-7 id="123" title="Contact form 1"][/um_loggedout]

Showing a special offer to non-logged-in users. Logged-in users will not see this offer. The content is wrapped in a div for styling purposes.

[um_loggedout]
Special offer for new users!
[/um_loggedout]

Displaying a registration form to non-logged-in users. Logged-in users will not see this form. The form is displayed using a shortcode from another plugin, and the um_loggedout shortcode ensures that it only displays to non-logged-in users.

[um_loggedout][user-registration-form id="123"][/um_loggedout]

PHP Function Code

In case you have difficulties debugging what causing issues with [um_loggedout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'um_loggedout', array( &$this, 'um_loggedout' ) );

Shortcode PHP function:

function um_loggedout( $args = array(), $content = '' ) {
			ob_start();

			// Hide for logged in users
			if ( is_user_logged_in() ) {
				echo '';
			} else {
				if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
					echo do_shortcode( wpautop( $content ) );
				} else {
					echo apply_shortcodes( wpautop( $content ) );
				}
			}

			$output = ob_get_clean();
			return $output;
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [um_show_content] Shortcode

The Ultimate Member shortcode ‘um_show_content’ is designed to control content visibility based on user roles. It allows specific content to be displayed only to users with certain roles. This shortcode checks if a user is logged in, fetches their user roles, and compares these roles with the ones specified in the shortcode attributes. If the user’s role matches the specified roles, the content is displayed. If not, no content is returned. This shortcode is particularly useful for websites that want to tailor content based on user roles, providing a personalized user experience.

Shortcode: [um_show_content]

Parameters

Here is a list of all possible um_show_content shortcode parameters and attributes:

  • roles – determines user roles that can view the content
  • not – specifies user roles that are barred from seeing the content
  • is_profile – displays the content if the user is viewing their own profile

Examples and Usage

Basic example – Show content only to users with specific roles

[um_show_content roles="administrator,editor"]Your exclusive content here[/um_show_content]

This shortcode will display the content inside the shortcode only to users who are logged in and have either the ‘administrator’ or ‘editor’ role.

Advanced examples

Displaying content to users that do not have specific roles

[um_show_content not="subscriber"]Your exclusive content here[/um_show_content]

In this example, the content within the shortcode will only be displayed to users who are logged in and do not have the ‘subscriber’ role.

Using the shortcode to display content based on profile

[um_show_content is_profile=true roles="author"]Your exclusive content here[/um_show_content]

This shortcode will display the content to users who are viewing their own profile and have the ‘author’ role. If ‘is_profile’ is set to true, it will fetch the profile of the logged-in user. If the user has the specified roles, then the content will be displayed.

PHP Function Code

In case you have difficulties debugging what causing issues with [um_show_content] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'um_show_content', array( &$this, 'um_shortcode_show_content_for_role' ) );

Shortcode PHP function:

function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) {
			global $user_ID;

			if ( ! is_user_logged_in() ) {
				return;
			}

			$a = shortcode_atts( array(
				'roles' => '',
				'not' => '',
				'is_profile' => false,
			), $atts );

			if ( $a['is_profile'] ) {
				um_fetch_user( um_profile_id() );
			} else {
				um_fetch_user( $user_ID );
			}

			$current_user_roles = um_user( 'roles' );

			if ( ! empty( $a['not'] ) && ! empty( $a['roles'] ) ) {
				if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
					return do_shortcode( $this->convert_locker_tags( $content ) );
				} else {
					return apply_shortcodes( $this->convert_locker_tags( $content ) );
				}
			}

			if ( ! empty( $a['not'] ) ) {
				$not_in_roles = explode( ",", $a['not'] );

				if ( is_array( $not_in_roles ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $not_in_roles ) ) <= 0 ) ) {
					if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
						return do_shortcode( $this->convert_locker_tags( $content ) );
					} else {
						return apply_shortcodes( $this->convert_locker_tags( $content ) );
					}
				}
			} else {
				$roles = explode( ",", $a['roles'] );

				if ( ! empty( $current_user_roles ) && is_array( $roles ) && count( array_intersect( $current_user_roles, $roles ) ) > 0 ) {
					if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
						return do_shortcode( $this->convert_locker_tags( $content ) );
					} else {
						return apply_shortcodes( $this->convert_locker_tags( $content ) );
					}
				}
			}

			return '';
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Ultimate Member [ultimatemember_searchform] Shortcode

The Ultimate Member Search Form shortcode is a powerful tool for enhancing user search capabilities. It checks if a members page exists, obtains member directory IDs, and prioritizes user roles. It ensures only authorized roles can perform searches. If search parameters are set, it sanitizes the input and generates a search form template. This shortcode is vital for creating user-friendly, secure search forms.

Shortcode: [ultimatemember_searchform]

Examples and Usage

Basic example – The basic usage of the shortcode will simply call the ‘ultimatemember_searchform’ function without any additional parameters or attributes.

[ultimatemember_searchform]

Advanced examples – In these examples, we add parameters to the shortcode to customize its output. Please remember that the parameters used in these examples are hypothetical and may not work with the actual ‘ultimatemember_searchform’ function without additional coding.

Example 1: Using the shortcode to display a search form with a specified member directory ID. The search form will only display if the member directory ID exists and the current user role has the ability to search.

[ultimatemember_searchform directory_id=1]

Example 2: Using the shortcode to display a search form with a specified member directory ID and a priority user role. The search form will only display if the member directory ID exists and the current user role matches the specified priority user role.

[ultimatemember_searchform directory_id=1 priority_role="administrator"]

Please note that these are hypothetical examples and may require additional coding to work as expected. Always check the plugin documentation or consult with a developer for accurate shortcode usage.

PHP Function Code

In case you have difficulties debugging what causing issues with [ultimatemember_searchform] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ultimatemember_searchform', array( &$this, 'ultimatemember_searchform' ) );

Shortcode PHP function:

function ultimatemember_searchform( $args = array(), $content = '' ) {
			if ( ! UM()->options()->get( 'members_page' ) ) {
				return '';
			}

			$member_directory_ids = array();

			$page_id = UM()->config()->permalinks['members'];
			if ( ! empty( $page_id ) ) {
				$member_directory_ids = UM()->member_directory()->get_member_directory_id( $page_id );
			}

			if ( empty( $member_directory_ids ) ) {
				return '';
			}

			//current user priority role
			$priority_user_role = false;
			if ( is_user_logged_in() ) {
				$priority_user_role = UM()->roles()->get_priority_user_role( get_current_user_id() );
			}

			$query = array();
			foreach ( $member_directory_ids as $directory_id ) {
				$directory_data = UM()->query()->post_data( $directory_id );

				if ( isset( $directory_data['roles_can_search'] ) ) {
					$directory_data['roles_can_search'] = maybe_unserialize( $directory_data['roles_can_search'] );
				}

				$show_search = empty( $directory_data['roles_can_search'] ) || ( ! empty( $priority_user_role ) && in_array( $priority_user_role, $directory_data['roles_can_search'] ) );
				if ( empty( $directory_data['search'] ) || ! $show_search ) {
					continue;
				}

				$hash = UM()->member_directory()->get_directory_hash( $directory_id );

				$query[ 'search_' . $hash ] = ! empty( $_GET[ 'search_' . $hash ] ) ? sanitize_text_field( $_GET[ 'search_' . $hash ] ) : '';
			}

			if ( empty( $query ) ) {
				return '';
			}

			$search_value = array_values( $query );

			$template = UM()->get_template( 'searchform.php', '', array( 'query' => $query, 'search_value' => $search_value[0], 'members_page' => um_get_core_page( 'members' ) ) );

			return $template;
		}

Code file location:

ultimate-member/ultimate-member/includes/core/class-shortcodes.php

Conclusion

Now that you’ve learned how to embed the Ultimate Member 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *