Last active
February 24, 2025 18:54
-
-
Save yuriinalivaiko/079c952fbc79d6bbf784834b1871f570 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Shortcode that displays the header 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 | |
| /** | |
| * Shortcode that displays the profile header. | |
| * Example: [um_profile_header form_id="7" user_id="1"] | |
| * | |
| * @global \wpdb $wpdb | |
| * | |
| * @param array $atts Shortcode attributes: | |
| * - (int) form_id - profile form ID. The first profile form if blank. | |
| * - (int) user_id - user ID. The current page/post author if blank. | |
| * | |
| * @return string The profile header HTML. | |
| */ | |
| function um_profile_header_shortcode( $atts ) { | |
| $args = shortcode_atts( | |
| array( | |
| 'form_id' => 0, | |
| 'user_id' => 0, | |
| ), | |
| $atts | |
| ); | |
| global $wpdb; | |
| if ( empty( $args['form_id'] ) ) { | |
| $args['form_id'] = (int) $wpdb->get_var( | |
| "SELECT pm.post_id | |
| FROM {$wpdb->postmeta} pm | |
| WHERE pm.meta_key = '_um_mode' | |
| AND pm.meta_value = 'profile' | |
| LIMIT 1;" | |
| ); | |
| } | |
| if ( empty( $args['user_id'] ) ) { | |
| $args['user_id'] = is_singular() ? get_the_author_meta( 'ID' ) : um_profile_id(); | |
| } | |
| if ( empty( $args['form_id'] ) || empty( $args['user_id'] ) ) { | |
| return; | |
| } | |
| $post_data = UM()->query()->post_data( $args['form_id'] ); | |
| if ( is_array( $post_data ) ) { | |
| $args = array_merge( $args, $post_data ); | |
| } | |
| $args = apply_filters( 'um_pre_args_setup', $args ); | |
| $args = apply_filters( 'um_shortcode_args_filter', $args ); | |
| if ( ! um_get_requested_user() ) { | |
| um_set_requested_user( $args['user_id'] ); | |
| um_fetch_user( $args['user_id'] ); | |
| } | |
| ob_start(); | |
| ?> | |
| <div class="um um-profile um-viewing <?php echo esc_attr( 'um-' . $args['form_id'] ); ?> um-profile-header-shortcode"> | |
| <div class="um-form" data-mode="profile"> | |
| <?php | |
| do_action( 'um_profile_header_cover_area', $args ); | |
| do_action( 'um_profile_header', $args ); | |
| do_action( 'um_profile_navbar', $args ); | |
| ?> | |
| </div> | |
| </div> | |
| <?php | |
| UM()->shortcodes()->dynamic_css( $args ); | |
| $content = ob_get_clean(); | |
| if ( um_get_requested_user() ) { | |
| um_reset_user(); | |
| } | |
| return $content; | |
| } | |
| add_shortcode( 'um_profile_header', 'um_profile_header_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@demian1985
Maybe you have multiple profile forms with different settings. The shortcode gets settings from the first fount profile form if there is no
form_idattribute.