How to extend Ultimate Member Profile Menu using Hooks?

Photo of author
Written By geekerhub

Lorem ipsum dolor sit amet consectetur pulvinar ligula augue quis venenatis. 

Ultimate Member offers a range of features including user profiles, member directories, user registration/login, user role editing, content restriction and along with that all the customization using filters and hooks.

Steps to follow:

In this tutorial, we will see on how to extend the ultimate member profile menu using Hooks.
In order to extend Profile Menu, the developer needs to follow the below steps

  • Create a new custom tab using a filter
  • Save the newly created tab from the profile menu settings
  • Logic development on the tab
  • Data display on the newly created tab

Create new custom tab using the `um_profile_tabs` filter

function geekerhub_list_add_tab( $tabs ) {
  $tabs['geekerhub'] = array(
    'name'        => 'My Team',
    'icon'        => 'um-faicon-pencil',
    'default_privacy'   => 3,
  );
  return $tabs;
}
add_filter( 'um_profile_tabs', 'geekerhub_list_add_tab', 1000 );

Go to profile menu settings (wp-admin/admin.php?page=um_options&tab=appearance&section=profile_menu) and you will find the newly created tab name. Check the newly created tab and save.

Do necessary logic development to whom this tab will be visible using this filter `um_user_profile_tabs`

function geekerhub_list_add_tab_visibility( $tabs ) {
  if ( empty( $tabs['geekerhub'] ) ) {
    return $tabs;
  }

  $user_id = um_profile_id();

  $redirect_on_roles = array( 'um_corporate-member' );
  
  if ( !in_array( um_user('role'), $redirect_on_roles  ) ) {
    unset( $tabs['geekerhub'] );
  }
  
  return $tabs;
}
add_filter( 'um_user_profile_tabs', 'geekerhub_list_add_tab_visibility', 2000, 1 );

`um_profile_content_geekerhub_default` action is dynamic based on the slug of the tab. We have used the “geekerhub” as a slug for the tab in step 1.

function um_profile_content_geekerhub_default( $args ) {
  
  $user_id = um_profile_id();
  //You logic goes here
  //You HTML goes here
  echo "Hi";
}
add_action( 'um_profile_content_geekerhub_default', 'um_profile_content_geekerhub_default' );

Leave a Comment