Extending Ultimate Member Profile Menu using Hooks
We recommend using the Profile tabs extension to extend the profile menu with extra tabs.
The profile menu can be extended using a custom code. See example below. The code is based on these hooks:
um_profile_tabs
- this hook is used to modify and extend the profile menu.um_user_profile_tabs
- (optional) this hook is used to modify and extend the profile menu for the certain user.um_profile_content_{$tab_id}
- this hook is used to display content for the desired tab, where{$tab_id}
is the tab key in the$tabs
array.
This file contains 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
// You could set the default privacy for custom tab and disable to change the tab privacy settings in admin menu. | |
/* | |
* There are values for 'default_privacy' atribute | |
* 0 - Anyone, | |
* 1 - Guests only, | |
* 2 - Members only, | |
* 3 - Only the owner | |
*/ | |
// Filter | |
function um_mycustomtab_add_tab( $tabs ) { | |
$tabs['mycustomtab'] = array( | |
'name' => 'My Custom', | |
'icon' => 'um-faicon-pencil', | |
'default_privacy' => 3, | |
); | |
return $tabs; | |
} | |
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 ); | |
/** | |
* Check an ability to view tab | |
* | |
* @param $tabs | |
* | |
* @return mixed | |
*/ | |
function um_mycustomtab_add_tab_visibility( $tabs ) { | |
if ( empty( $tabs['mycustomtab'] ) ) { | |
return $tabs; | |
} | |
$user_id = um_profile_id(); | |
if ( ! user_can( $user_id, '{here some capability which you need to check}' ) ) { | |
unset( $tabs['mycustomtab'] ); | |
} | |
return $tabs; | |
} | |
add_filter( 'um_user_profile_tabs', 'um_mycustomtab_add_tab_visibility', 2000, 1 ); | |
// Action | |
function um_profile_content_mycustomtab_default( $args ) { | |
echo 'Hello world!'; | |
} | |
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default' ); |
NOTE: We have created this code example to provide guidance and to make it easier for you to implement this code into your website. However, we are not able to provide any support when it comes to customizing the plugin. If you need help implementing this code, please hire a developer.