Support » Plugin: Ultimate Member - User Profile & Membership Plugin » Fatal error – $ultimatemember->user->get_role()

  • hi, I get a fatal error when trying to restrict the user access to my WordPress page using PHP as below. After reading some other users posts here, I also tried UM()->user... but that didn’t work either. Any suggestions and help here is welcome!
    Thanks in advance.

    if ($ultimatemember->user->get_role() == 'subscriber' || $ultimatemember->user->get_role() == 'administrator') { // Show this to premium subscribers and admins
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Towhid

    (@cryptex_vinci)

    Hi @frankmarks

    You can try checking the user roles this way:

    <?php 
    
    $user = wp_get_current_user();
    
    if ( $user->roles[0] == 'administrator' || $user->roles[0] == 'subscriber' ) {
    	echo "Show this";
    }
    
    ?>

    Thanks

    SuitePlugins

    (@suiteplugins)

    @frankmarks

    Are you fetching the user data using um_fetch_user before calling the function?

    Here’s what you can do

    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    
    if ( UM()->user()->get_role() == 'subscriber' ) {
    
    }
    
    frankmarks

    (@frankmarks)

    Hi Both,

    Thanks for your suggestions and support.

    In both cases, the page isn’t loaded when I access it as a subscriber, the CSS loader spins endless and in the console I see the following error: Failed to load resource: the server responded with a status of 500 ().

    I want to make it as easy as possible and prefer to use Asif’s solution as it uses core functionality. but somehow it doesn’t seem to work. With the page, I am also loading several page-specific Javascript files using the wp_enqueue_script function, in functions.php. Could this somehow cause the error? I believe not, because blocking the page for guest viewers with the code if( is_user_logged_in() ) { echo "you're logged in and can view this"; } works just fine!

    Thanks for any further ideas and suggestions.

    Best, Frank

    SuitePlugins

    (@suiteplugins)

    Hey Frank,

    Can you paste more of the script that you have in your functions.php file? There might be something related to how it’s written or where it’s written and I would love to assist.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fatal error – $ultimatemember->user->get_role()’ is closed to new replies.