Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
Last active June 20, 2020 21:32
Show Gist options
  • Save ultimatemember/643cd90967e5e415378d to your computer and use it in GitHub Desktop.
Save ultimatemember/643cd90967e5e415378d to your computer and use it in GitHub Desktop.
Custom profile tab example: showing user pages
/* add a custom tab to show user pages */
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$tabs['pages'] = array(
'name' => 'Pages',
'icon' => 'um-faicon-pencil',
'custom' => true
);
return $tabs;
}
/* Tell the tab what to display */
add_action('um_profile_content_pages_default', 'um_profile_content_pages_default');
function um_profile_content_pages_default( $args ) {
global $ultimatemember;
$loop = $ultimatemember->query->make('post_type=page&posts_per_page=10&offset=0&author=' . um_profile_id() );
while ($loop->have_posts()) { $loop->the_post(); $post_id = get_the_ID();
?>
<div class="um-item">
<div class="um-item-link"><i class="um-icon-ios-paper"></i><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
</div>
<?php
}
}
@hirenshah
Copy link

This worked for me:
https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles

function um_mycustomtab_add_tab( $tabs ) {
	/**
	 * You could set the default privacy for custom tab.
	 * There are values for 'default_privacy' atribute:
	 * 0 - Anyone,
	 * 1 - Guests only,
	 * 2 - Members only,
	 * 3 - Only the owner
	 */
	$tabs[ 'mycustomtab' ] = array(
		'name' => 'My Custom',
		'icon' => 'um-faicon-pencil',
		'default_privacy' => 3,
	);

	UM()->options()->options[ 'profile_tab_' . 'mycustomtab' ] = true;

	return $tabs;
}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );

/**
 * Render tab content
 * @param array $args
 */
function um_profile_content_mycustomtab_default( $args ) {
    echo do_shortcode('[elementor-template id="5457"]');
}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default' );

@almadeaventura
Copy link

Hi guys... i use this code and works good but only with "register type forms"... if i use "profile type forms" the page goes "This page isn’t workingenamorarse.cl is currently unable to handle this request.
HTTP ERROR 500 "

can u help me with this?
https://gist.github.com/ultimatemember/643cd90967e5e415378d#gistcomment-3091597

@hirenshah
Copy link

Hi guys... i use this code and works good but only with "register type forms"... if i use "profile type forms" the page goes "This page isn’t workingenamorarse.cl is currently unable to handle this request.
HTTP ERROR 500 "

can u help me with this?
https://gist.github.com/ultimatemember/643cd90967e5e415378d#gistcomment-3091597

Are you using my cut-down version or UM's full version?

I had placed my intended content (a map where the user could set their location - from another plugin) in a template and then called that in the new tab. No longer use that now though because I've integrated the UM City field and that map functionality 🙂

@rgravine
Copy link

Tabs are producing the data I want. In back-end of Ultimate member all functions are working correctly but I'm having an issue with privacy.

I have echoed user roles with:

which are:

um_musician-level-1
um_musician-level-2
um_musician-level-3

I need SOUNDCLOUD and YOUTUBE tab for role = um_musician-level-3

Anyone can see the tab on any profile as long as said profile has role = um_musician-level-3

Level 3 will always have the tab on their profile. Level 1 and 2 should not because they have not paid for it.

I had it working I BELIEVE but got so deep into other coding as you can see below I must have made a typo.

/**

Add a new SoundCloud Embed Profile tab
*/
function um_mycustomtab_add_tab( $tabs ) {

$tabs[ 'mycustomtab' ] = array(
'name' => 'Sound Cloud',
'icon' => 'um-faicon-soundcloud',
'custom' => true,
'default_privacy' => 0,

);

// Show to other profiles
if ( is_user_logged_in() && get_current_user_id() != $user_id ) {
$tabs['mycustomtab'] = array(
'name' => 'Sound Cloud',
'icon' => 'fa fa-soundcloud',
'custom' => true
);
}

// Hide from specific roles
$hide_from_roles = array( 'um_musician-level-1','um_musician-level-2' );

if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles ) ) {
$tabs['mycustomtab'] = array(
'name' => 'Sound Cloud',
'icon' => 'fa fa-soundcloud',
'custom' => true
);
}

UM()->options()->options[ 'profile_tab_' . 'mycustomtab' ] = true;

return $tabs;

}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );

// Render Tab Content
function um_profile_content_mycustomtab_default( $args ) {
$action = 'mycustomtab';
$fields_metakey = array('sound_cloud_user_id'

);

$nonce = filter_input( INPUT_POST, '_wpnonce' );
if( $nonce && wp_verify_nonce( $nonce, $action ) && um_is_myprofile() ) {
foreach( $fields_metakey as $metakey ) {
update_user_meta( um_profile_id(), $metakey, filter_input( INPUT_POST, $metakey ) );
}
UM()->user()->remove_cache( um_profile_id() );
}

$fields = UM()->builtin()->get_specific_fields( implode( ',', $fields_metakey ) );
?>

<script> var url = new URL(window.location.href); var query_string = url.search; var search_params = new URLSearchParams(query_string); var sound_cloud_user_id = var iframe = "<iframe height='800px' width='100%' frameborder='0' allowTransparency='true' scrolling='no' src='https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/users/"+sound_cloud_user_id+"&color=%23dc2751&auto_play=true&hide_related=false&show_comments=false&show_user=true&show_reposts=false&show_teaser=false'></iframe>"; document.write(iframe ); </script>

@hirenshah
Copy link

hirenshah commented Mar 27, 2020

@rgravine

Once you have set up the tabs, you should be using the options available under UM Settings > Appearance > Profile Menu

All the tabs you create appear there automatically and you can select the roles. Example of one of my tabs below:

Annotation 2020-03-27

@rgravine
Copy link

rgravine commented Mar 28, 2020

I can change that. But that does not solve my issue.

I need a drop-down or function for custom tab to:

Select user roles allowed to have this tab.

not

Select the the user roles allowed to view this tab.

Everyone should be able to view any tab on any profile that has it. Im trying to restrict a profile tab to certain user profiles. HAS profile tab not VIEW profile tab.

@rgravine
Copy link

I did find this but get WHITE SCREEN when adding it to functions.php

add_filter('um_profile_tabs', 'remove_posts_tab_for_members', 1000 );
function remove_posts_tab_for_members( $tabs ) {

global $ultimatemember;

// Check if user role is not "Company"
if ($ultimatemember->user->get_role() != 'company') {
	unset($tabs['posts']);
}

return $tabs;

}

Receive white screen with error:

[28-Mar-2020 02:31:55 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_role() on null in /home3/hisking3/public_html/wp-content/themes/recond-child/functions.php:154
Stack trace:
#0 /home3/hisking3/public_html/wp-includes/class-wp-hook.php(288): remove_posts_tab_for_members(Array)
#1 /home3/hisking3/public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters(Array, Array)
#2 /home3/hisking3/public_html/wp-content/plugins/ultimate-member/includes/core/class-profile.php(150): apply_filters('um_profile_tabs', Array)
#3 /home3/hisking3/public_html/wp-content/plugins/ultimate-member/includes/class-config.php(580): um\core\Profile->tabs()
#4 /home3/hisking3/public_html/wp-content/plugins/ultimate-member/includes/class-init.php(969): um\Config->__construct()
#5 /home3/hisking3/public_html/wp-content/plugins/ultimate-member/includes/um-short-functions.php(1334): UM->config()
#6 /home3/hisking3/public_html/wp-content/plugins/ultimate-member/includes/core/um-filters-profile.php(49): um_is_core_page('user')
#7 /home3/hisking3/public_html/wp in /home3/hisking3/public_html/wp-content/themes/recond-child/functions.php on line 154

If function is removed site is back up. I'm assuming the function get_role() has changed to something else

@hirenshah
Copy link

hirenshah commented Mar 28, 2020

@rgravine

Try this:
$ultimatemember->user->get_role_name()

You may also need to fetch the current user first:

$user_id = get_current_user_id();
um_fetch_user( $user_id );

@rgravine
Copy link

TRY THIS WHERE? Can you provide me full code with your edits pretty please

@hirenshah
Copy link

hirenshah commented Mar 28, 2020

TRY THIS WHERE? Can you provide me full code with your edits pretty please

global $ultimatemember;
$user_id = get_current_user_id();
um_fetch_user( $user_id );
// Check if user role is not "Company"
if ($ultimatemember->user->get_role_name() != 'company') {
	unset($tabs['posts']);
}
return $tabs;

No need for the capitals... I am just another user who has been trying to figure this kind of stuff out on my own, and am just trying to help you out here.

@rgravine
Copy link

rgravine commented Mar 28, 2020

I actually went about it a different way. I know it s a bit of a process but once completed it allows for ALLOT OF CONTROL!!!

Installed:

Ultimate Member - Profile Tabs
https://wordpress.org/plugins/profile-tabs-for-ultimate-member/

Ran fix

https://gist.github.com/gboudreau/dc94478877dab935edf562f826531906

This creates a custom shortcode to call to external php file and print.

https://wordpress.stackexchange.com/questions/49675/include-php-file-in-content-using-shortcode

if (is_admin()) {
include dirname(__FILE__) . '/admin.php';

} else {

function includeme_call($attrs, $content = null) {

    if (isset($attrs['file'])) {
        $file = strip_tags($attrs['file']);
        if ($file[0] != '/')
            $file = ABSPATH . $file;

        ob_start();
        include($file);
        $buffer = ob_get_clean();
        $options = get_option('includeme', array());
        if (isset($options['shortcode'])) {
            $buffer = do_shortcode($buffer);
        }
    } else {
        $tmp = '';
        foreach ($attrs as $key => $value) {
            if ($key == 'src') {
                $value = strip_tags($value);
            }
            $value = str_replace('&amp;', '&', $value);
            if ($key == 'src') {
                $value = strip_tags($value);
            }
            $tmp .= ' ' . $key . '="' . $value . '"';
        }
        $buffer = '<iframe' . $tmp . '></iframe>';
    }
    return $buffer;
}
add_shortcode('includeme', 'includeme_call');
}

Created new profile tab

ULTIMATE MEMBER >> PROFILE TABS

Profile tab creation also has its own options

Profile Tabs Options

Added Shortcode to profile tab text editor not visual

[includeme file="wp-content/soundcloud.php"]

Created File

public_html/wp-content/youtube.php

Now I can recycle to add as many tabs as I like with custom conditions and custom code for my needs

I appreciate the fix but for me this has way more control. Kinda glad I was a bit inpatient.

@rgravine
Copy link

rgravine commented Mar 29, 2020

@luismiguelrosero
Copy link

Halfway, this has worked for me: https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles

Before continuing I want to greet and applaud you for such an excellent plugin, it is a very good job, congratulations.

I am using the basic version available in the WordPress plugin repository

By implementing the code that you have provided at: https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles

I can only see basic user profile information

line 36 of the code

36 'description'
);

But I would like to be able to replace that information with a page or the shortcode of a page. Do you think you could tell us how this objective can be achieved?

Thank you very much UM

@kazakh1979
Copy link

I actually went about it a different way. I know it s a bit of a process but once completed it allows for ALLOT OF CONTROL!!!

Installed:

Ultimate Member - Profile Tabs
https://wordpress.org/plugins/profile-tabs-for-ultimate-member/

Ran fix

https://gist.github.com/gboudreau/dc94478877dab935edf562f826531906

This creates a custom shortcode to call to external php file and print.

https://wordpress.stackexchange.com/questions/49675/include-php-file-in-content-using-shortcode

if (is_admin()) {
include dirname(__FILE__) . '/admin.php';

} else {

function includeme_call($attrs, $content = null) {

    if (isset($attrs['file'])) {
        $file = strip_tags($attrs['file']);
        if ($file[0] != '/')
            $file = ABSPATH . $file;

        ob_start();
        include($file);
        $buffer = ob_get_clean();
        $options = get_option('includeme', array());
        if (isset($options['shortcode'])) {
            $buffer = do_shortcode($buffer);
        }
    } else {
        $tmp = '';
        foreach ($attrs as $key => $value) {
            if ($key == 'src') {
                $value = strip_tags($value);
            }
            $value = str_replace('&amp;', '&', $value);
            if ($key == 'src') {
                $value = strip_tags($value);
            }
            $tmp .= ' ' . $key . '="' . $value . '"';
        }
        $buffer = '<iframe' . $tmp . '></iframe>';
    }
    return $buffer;
}
add_shortcode('includeme', 'includeme_call');
}

Created new profile tab

ULTIMATE MEMBER >> PROFILE TABS

Profile tab creation also has its own options

Profile Tabs Options

Added Shortcode to profile tab text editor not visual

[includeme file="wp-content/soundcloud.php"]

Created File

public_html/wp-content/youtube.php

Now I can recycle to add as many tabs as I like with custom conditions and custom code for my needs

I appreciate the fix but for me this has way more control. Kinda glad I was a bit inpatient.

Can you share step for step how you did this please.

@codingdudecom
Copy link

Hi guys,

thanks for this great plugin. I tried the code for adding a new tab, but ran into a problem

I had to change

$loop = $ultimatemember->query->make

to

$loop = $ultimatemember->query()->make

Please make the change in the documentation, as it took me half an hour to figure out

@luismiguelrosero
Copy link

luismiguelrosero commented Jun 20, 2020

@codingdudecom & @hirenshah

Cordial greeting

Excuse me gentlemen, I KNOW very well that it is not your obligation, much less, but I really do not know what to do or who to turn to.

I am not a programmer, I am just a humble designer who has made a web page using the Ultimate Member plugin, because it is free (it is what is within the reach of my economy ...)

I see that you and several here in this thread, have had the need to create additional tabs for your users, well, me too, only I do not know anything about code and although it is very difficult for me to do so, I presume to understand after some time of effort and a lot of trial and error, but in the end I manage to understand.

I will tell you about my case to see if someone can guide me a little and give me a hand, specifically and at the risk of sounding a little daring, ask, with much respect and humility, for the lines of code that will help me solve the great problem that I am facing. now. (Believe me, I have done everything in the UM plugin developer documentation to the letter, but this does not give me a positive result.)

I have my website, I have UM, I have user registration enabled, so far, so good.

I have two user types with attribute level 2 (members only) (- * There are values ​​for 'default_privacy' attribute:

  • 0 - Anyone,
  • 1 - Guests only,
  • 2 - Members only,
  • 3 - Only the owner
  • / -)

And in turn those members or registered users of level 2 are: Employer and Employee.

---- I hope I have understood up to here ----

Using the sample code from the original plugin documentation
(https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles)

I have managed to create an additional tab, I will actually need two, but I cannot get the first one to work properly.

What I'm looking for is that when a level two user enters the profile, they see ONLY the tab that corresponds to them, I explain a little more, as I already mentioned, I only have two types of registered users, Employer and Employee, well, what I seek to achieve is that if the employer user enters their profile in the new personalized tab, they can find an html

in their content where there will be a button that takes them or directs them to a form to request employees according to the needs and characteristics demanded, example : I request baker, Man, with a motorcycle ... and that this new tab is only shown to this level two user who has registered under the Employer profile.

But ----, eye, but, if the one who enters your profile is a level two user but of the Employee type, they will be shown, also 1 single tab, different from that of the employer, but in the same location, that is to say the tab next to the "information" tab that has UM by default, and that tab in its content also has an html

but with a button that takes you to a form to fill out, complete and send your resume.

tab 1, shows the content only to the user registered as an employer
tab 2, shows only the content to the user registered as an employee

Pdta. The forms I have already solved satisfactorily and each one I have on a different and independent page, on the one hand, a page for the employer form on the other hand, another page for the form of the person who is seeking employment or specifically the Employee.

To those who can help me, all that remains is to reiterate again and again and my gratitude and respect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment