Last active
December 11, 2025 19:49
-
-
Save yuriinalivaiko/2e1b74b99c51b65c4e4b4d981b9d0cc0 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Shortcode that displays the form section of the Ultimate Member profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Builds the profile form shortcode output. | |
| * | |
| * The supported attributes for the shortcode are 'form_id'. | |
| * Example 1: [um_profile_form] | |
| * Example 2: [um_profile_form form_id="1740"] | |
| * | |
| * @param array $atts { | |
| * Attributes of the shortcode. | |
| * | |
| * @type int $form_id The profile form ID. The first profile form if blank. | |
| * } | |
| * @param string $content Shortcode content. | |
| * | |
| * @return string|void HTML content to display the profile form. | |
| */ | |
| function um_profile_form_shortcode( $atts, $content ) { | |
| $args = shortcode_atts( | |
| array( | |
| 'form_id' => 0, | |
| ), | |
| $atts | |
| ); | |
| if ( empty( $args['form_id'] ) ) { | |
| // Get the first profile form if the `form_id` attribute is empty. | |
| $forms = get_posts( | |
| array( | |
| 'fields' => 'ids', | |
| 'meta_key' => '_um_mode', | |
| 'meta_value' => 'profile', | |
| 'order' => 'ASC', | |
| 'post_type' => 'um_form', | |
| ) | |
| ); | |
| $args['form_id'] = current( $forms ); | |
| } | |
| if ( empty( $args['form_id'] ) || ! is_user_logged_in() ) { | |
| return; | |
| } | |
| $form_id = (int) $args['form_id']; | |
| $user_id = get_current_user_id(); | |
| $form_args = UM()->query()->post_data( $form_id ); | |
| // save current settings. | |
| global $post; | |
| $global_post = $post; | |
| $set_id = UM()->fields()->set_id; | |
| $set_mode = UM()->fields()->set_mode; | |
| $editing = UM()->fields()->editing; | |
| $viewing = UM()->fields()->viewing; | |
| $form_nonce = UM()->form()->nonce; | |
| $form_suffix = UM()->form()->form_suffix; | |
| // set profile settings. | |
| $post = get_post( um_get_predefined_page_id( 'user' ) ); | |
| UM()->fields()->set_id = $form_id; | |
| UM()->fields()->set_mode = 'profile'; | |
| UM()->fields()->editing = true; | |
| UM()->fields()->viewing = false; | |
| UM()->form()->form_suffix = '-' . $form_id; | |
| UM()->form()->nonce = wp_create_nonce( 'um-profile-nonce' . $user_id ); | |
| UM()->user()->target_id = $user_id; | |
| $classes = UM()->shortcodes()->get_class( 'profile' ); | |
| ob_start(); | |
| ?> | |
| <div class="um <?php echo esc_attr( $classes ); ?> um-<?php echo absint( $form_id ); ?> um-role-<?php echo esc_attr( um_user( 'role' ) ); ?> "> | |
| <div class="um-form" data-mode="profile" data-form_id="<?php echo absint( $form_id ); ?>"> | |
| <form method="post" action=""> | |
| <?php do_action( 'um_profile_content_main', $form_args ); ?> | |
| </form> | |
| </div> | |
| </div> | |
| <?php | |
| $content .= ob_get_clean(); | |
| // restore current settings. | |
| $post = $global_post; | |
| UM()->fields()->set_id = $set_id; | |
| UM()->fields()->set_mode = $set_mode; | |
| UM()->fields()->editing = $editing; | |
| UM()->fields()->viewing = $viewing; | |
| UM()->form()->form_suffix = $form_suffix; | |
| UM()->form()->nonce = $form_nonce; | |
| return $content; | |
| } | |
| add_shortcode( 'um_profile_form', 'um_profile_form_shortcode' ); | |
| // Disable redirect to profile. | |
| add_filter( 'um_update_profile_redirect_after', function( $url, $user_id, $args ) { | |
| return um_is_core_page( 'user' ) ? $url : UM()->permalinks()->get_current_url(); | |
| }, 10, 3 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instruction
Install
Copy a code snippet above (without the opening php tag) and paste it to the functions.php file in the active theme directory.
Add shortcode
You can add the [um_profile_form] shortcode to the page/post content to display the form like the "About" tab content of the Ultimate Member profile.
Attributes
Use optional attribute form_id to select a profile form you prefer. Default: the first profile form.
Examples
[um_profile_form][um_profile_form form_id="1740"]Related Gists