Reputation: 103
I've been looking for a while and haven't been able to find an answer to my question anywhere. I'm building a member directory for an arts council website, and I'm using the Wordpress plugin Memberpress to manage an annual subscription fee. I am trying to print the user information to a simple directory page - currently just echoing the user values in php like so:
<?php
$user_query = new WP_User_Query( array( 'role' => 'Subscriber' ) );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<p>' . $user->display_name . '</p>';
echo '<p>' . $user->user_email . '</p>';
echo '<p>' . $user->user_url . '</p>';
echo '<p>' . $user->description . '</p>';
echo '<p>' . $user->subscription . '</p>';
echo '<p>' . $user->memberpress_authorized . '</p>';
$type = $user->mepr_artist_type;
for($i=0; $i<=sizeof($type); $i+=1) {
echo '<p>' . $type[$i] . '</p>';
}
}
} else {
echo 'No users found.';
}
?>
This all works fine, and is just for testing right now, but I'm trying to figure out how to check if the user has an active subscription. This property is not stored in the WP_User_Query database, and I don't know how to check for it elsewhere.
I have checked the code in the Memberpress plugin for hints, and tried using the WP_mepr_members database, which does seem to store a membership name value, but so far I've been unsuccessful. Memberpress documentation has been unhelpful, though I did find this function:
<?php if(current_user_can('mepr_auth')) {
// acf content output here
}
However, it isn't formatted in a useful way for what I'm trying to do, as it only checks permission for the current user, not for all users. Does anyone know how to fix this?
Thanks.
Upvotes: 5
Views: 4703
Reputation: 421
A bit late here, but you can tap into the MeprUser class. Here's an example function to get the name of the user's subscription title and display it in the admin area.
function display_user_sub() {
$user_ID = get_current_user_id(); // get the user ID
$member = new MeprUser(); // initiate the class
$member->ID = $user->ID; // if using this in admin area, you'll need this to make user id the member id
$result = $member->get_active_subscription_titles("<br/>"); //MeprUser function that gets subscription title
echo $result // displays sub title, example 'Gold Membership'
}
You can search the plugin for MeprUser for more methods and properties to use for your scenario.
Upvotes: 3