Using Gravity Forms ‘gform_shortcode_user’ PHP filter

The gform_shortcode_user Gravity Forms PHP function/filter/action is a dynamically generated hook name, used in the Gravity Forms User Registration Add-On. It is derived from the gform_shortcode_{ACTION} hook, with the “ACTION” portion replaced by “user”.

Usage

add_filter('gform_shortcode_user', 'your_custom_function', 10, 2);
function your_custom_function($output, $attributes) {
    // your custom code here
    return $output;
}

Parameters

  • $output (string) – The existing output generated by the shortcode.
  • $attributes (array) – An array of attributes passed to the shortcode.

More information

See Gravity Forms Docs: gform_shortcode_{ACTION}

Examples

Display a custom message for logged-in users

add_filter('gform_shortcode_user', 'display_custom_message', 10, 2);
function display_custom_message($output, $attributes) {
    if (is_user_logged_in()) {
        $output .= 'Welcome back, valued user!';
    }
    return $output;
}

Show the user’s email address

add_filter('gform_shortcode_user', 'show_user_email', 10, 2);
function show_user_email($output, $attributes) {
    $current_user = wp_get_current_user();
    if ($current_user->ID != 0) {
        $output .= 'Your email address is: ' . $current_user->user_email;
    }
    return $output;
}

Display user’s first and last name

add_filter('gform_shortcode_user', 'show_user_full_name', 10, 2);
function show_user_full_name($output, $attributes) {
    $current_user = wp_get_current_user();
    if ($current_user->ID != 0) {
        $output .= 'Your name is: ' . $current_user->first_name . ' ' . $current_user->last_name;
    }
    return $output;
}

Show a custom message based on user role

add_filter('gform_shortcode_user', 'show_message_based_on_role', 10, 2);
function show_message_based_on_role($output, $attributes) {
    $current_user = wp_get_current_user();
    if (in_array('administrator', $current_user->roles)) {
        $output .= 'Hello, Administrator!';
    }
    return $output;
}

Display the user’s registration date

add_filter('gform_shortcode_user', 'show_user_registration_date', 10, 2);
function show_user_registration_date($output, $attributes) {
    $current_user = wp_get_current_user();
    if ($current_user->ID != 0) {
        $output .= 'You registered on: ' . date('F j, Y', strtotime($current_user->user_registered));
    }
    return $output;
}