I am trying to create a default "Membership Alert" page, so if a user's membership has been cancelled, has expired, requires approval or requires confirmation I want to give them a message on this page. I need to get the user's status, and I'm not sure which API function has access to this info, then I want to create conditional arguments based on this info to display the right "alert" message.

I started with this:

$user = wp_get_current_user(); $user_id = $user->ID; $user_status = wlmapi_get_member_by('user_id', $user_id); print_r($user_status);

And tested it with a user I had just cancelled. But the array isn't displaying the info I need.

UPDATE! Here's the solution I came up with:

$user = wp_get_current_user();
$user_id = $user->ID;
$my_levels = wlmapi_get_member_levels($user_id);
$my_levels = json_decode(json_encode($my_levels), true);

foreach ($my_levels as $my_level) :
    $level_id = $my_level['Level_ID'];
    echo '<h2>' . $my_level['Name'] . ':</h2>';
    $member_data = wlmapi_get_level_member_data($level_id, $user_id);
    $member_data = json_decode(json_encode($member_data), true);
    $member_status = $member_data['member']['level']['Status']['0'];

    if($member_status == 'Cancelled') :
        if(get_field('membership_cancelled')) :
            echo '<p>' . the_field('membership_cancelled') . '</p>';
    elseif($member_status == 'Expired') :
        if(get_field('membership_expired')) :
            echo '<p>' . the_field('membership_expired') . '</p>';
    elseif($member_status == 'For Approval') :
        if(get_field('membership_requires_approval')) :
            echo '<p>' . the_field('membership_requires_approval') . '</p>';
    elseif($member_status == 'Pending') :
        if(get_field('membership_requires_confirmation')) :
            echo '<p>' . the_field('membership_requires_confirmation') . '</p>';
    else :
        echo '<p>Your membership is active!</p>';

I don't know if this is the most elegant solution but it works. If anyone has any refinements I would love to learn from them.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.