Customizing the Ultimate Member

Case Study: Developing and Customizing the Ultimate Member Plugin

Getting your Trinity Audio player ready...

Introduction

The Ultimate Member plugin is one of the most powerful and versatile WordPress tools for creating membership sites. However, out-of-the-box functionality often requires customization to meet specific client needs. This case study details the process, challenges, and solutions we employed to develop and customize the Ultimate Member plugin to meet the unique requirements of a client.

Customizing the Ultimate Member
Customizing the Ultimate Member

Project Overview

Objective

To create a membership platform that:

  1. Allows administrators to view and manage all user data.
  2. Enables subscribers to access and edit their own data.
  3. Restricts subscribers from accessing other users’ information.
  4. Incorporates additional functionality such as custom profile fields, role-based access control, and aesthetic enhancements.

Challenges

  1. Adapting the default behavior of the Ultimate Member plugin to meet complex role-based access needs.
  2. Dynamically displaying user-specific data on profile and directory pages.
  3. Ensuring a seamless user experience without disrupting core plugin functionality.

Step-by-Step Process

1. Planning and Requirement Analysis

Before diving into development, we conducted a detailed analysis of the client’s requirements. The primary needs included:

  • Role-Based Access: Admins must see all profiles, while subscribers can only view their own.
  • Custom Fields: Adding fields such as membership status, expiry date, and QR code.
  • Custom Error Messaging: Displaying appropriate messages when access is denied.

We identified key areas of the Ultimate Member plugin that required customization, such as:

  • Profile templates
  • User data hooks
  • Conditional logic for data visibility

2. Customizing Profile Data Display

The Ultimate Member plugin uses hooks and filters to manage data display. We used the um_before_form hook to inject custom logic.

Code Implementation:

function display_user_info( $args ) {
    $current_user_id = get_current_user_id();
    $current_user = wp_get_current_user();
    $current_user_roles = $current_user->roles;

    $viewed_user_id = isset( $args['user_id'] ) ? intval( $args['user_id'] ) : $current_user_id;
    $is_admin = in_array( 'administrator', $current_user_roles );

    if ( !$is_admin && $current_user_id !== $viewed_user_id ) {
        echo '<div class="um-member-custom-info">You are not supposed to be here.</div>';
        return;
    }

    $user = get_userdata( $viewed_user_id );
    $user_email = $user ? $user->user_email : '';
    $first_name = get_user_meta( $viewed_user_id, 'first_name', true );
    $last_name = get_user_meta( $viewed_user_id, 'last_name', true );

    echo '<div class="um-member-custom-info">';
    if ( $first_name ) {
        echo "<div>First Name: <strong>" . ucfirst( esc_html( $first_name ) ) . "</strong></div>";
    }
    if ( $last_name ) {
        echo "<div>Last Name: <strong>" . ucfirst( esc_html( $last_name ) ) . "</strong></div>";
    }
    if ( $user_email ) {
        echo "<div>Email: <strong>" . esc_html( $user_email ) . "</strong></div>";
    }
    echo '</div>';
}
add_action( 'um_before_form', 'display_user_info' );

3. Enhancing the Directory Page

The directory page required logic to display different information based on the viewer’s role. For instance:

  • Admins: Full access to user details.
  • Subscribers: Limited access to their own details only.

We modified the um_ajax_get_members_data filter to customize directory data.

Code Implementation:

function customize_directory_data( $user_id, $directory_data ) {
    $current_user_id = get_current_user_id();
    um_fetch_user( $user_id );

    $data_array = array(
        'id' => absint( $user_id ),
        'avatar' => wp_kses( get_avatar( $user_id, 96 ), UM()->get_allowed_html( 'templates' ) ),
        'cover_photo' => wp_kses( um_user( 'cover_photo', 'medium' ), UM()->get_allowed_html( 'templates' ) ),
    );

    if ( $current_user_id === $user_id || current_user_can( 'administrator' ) ) {
        $data_array['display_name'] = esc_html( um_user( 'display_name' ) );
        $data_array['profile_url'] = esc_url( um_user_profile_url() );
    } else {
        $data_array['display_name'] = esc_html__( 'Restricted', 'ultimate-member' );
        $data_array['profile_url'] = '';
    }

    um_reset_user_clean();
    return $data_array;
}
add_filter( 'um_ajax_get_members_data', 'customize_directory_data', 10, 2 );

4. Adding Custom Profile Fields

Using Ultimate Member’s custom field feature, we added:

  • Membership Status
  • Expiry Date
  • QR Code

To make these fields functional, we registered them through the plugin’s settings and extended their display with custom hooks.

5. Role-Based Redirects

We implemented conditional redirects to ensure that users were sent to the correct pages after login based on their role.

Code Implementation:

function role_based_redirect( $redirect, $user ) {
    if ( in_array( 'administrator', $user->roles ) ) {
        return admin_url();
    } elseif ( in_array( 'subscriber', $user->roles ) ) {
        return site_url( '/my-profile/' );
    }
    return $redirect;
}
add_filter( 'login_redirect', 'role_based_redirect', 10, 2 );

Challenges and Solutions

1. Overwriting Default Plugin Behavior

The plugin’s default behavior didn’t support role-based visibility. We overcame this by using custom hooks and filters to inject dynamic logic.

2. Data Privacy

Ensuring that subscribers couldn’t access others’ data was a top priority. By implementing strict ID checks, we secured data visibility.

3. User Experience

We customized error messages and role-based redirects to guide users intuitively, reducing confusion and improving engagement.


Results

  • A fully customized membership platform tailored to the client’s needs.
  • Enhanced admin capabilities for managing user profiles and directories.
  • A secure and intuitive experience for subscribers.

Conclusion

The Ultimate Member plugin provides a robust foundation for membership sites. With strategic customization, it can be tailored to meet complex requirements. Our approach highlights the importance of understanding client needs, leveraging plugin extensibility, and ensuring user-centric design.

If you’re looking to develop a custom membership solution, don’t hesitate to contact us!

Similar Posts

Leave a Reply