su_shortcode_user

The shortcodes-ultimate su shortcode user function.

Published Date - February 15, 2021

Description

su_shortcode_user( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_user' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/user.php';
}

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_user( $atts, $content );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/user.php

function su_shortcode_user( $atts = null, $content = null ) {

	$atts = su_parse_shortcode_atts( 'user', $atts );

	if ( 'user_pass' === $atts['field'] ) {

		return su_error_message(
			'User',
			__( 'password field is not allowed', 'shortcodes-ultimate' )
		);

	}

	$atts['user_id'] = su_do_attribute( $atts['user_id'] );

	if ( ! $atts['user_id'] ) {
		$atts['user_id'] = get_current_user_id();
	}

	if ( ! is_numeric( $atts['user_id'] ) || $atts['user_id'] < 0 ) {

		return su_error_message(
			'User',
			__( 'invalid user ID', 'shortcodes-ultimate' )
		);

	}

	$user = get_user_by( 'id', $atts['user_id'] );

	if ( ! $user ) {

		return su_error_message(
			'User',
			__( 'user not found', 'shortcodes-ultimate' )
		);

	}

	$data = $user->get( $atts['field'] );

	if ( ! is_string( $data ) || '' === $data ) {
		$data = su_do_attribute( $atts['default'] );
	}

	if (
		$atts['filter'] &&
		su_is_filter_safe( $atts['filter'] ) &&
		function_exists( $atts['filter'] )
	) {
		$data = call_user_func( $atts['filter'], $data );
	}

	return $data ? $atts['before'] . $data . $atts['after'] : '';

}