Array of IDs for all Active Members

Im trying to get an array of IDs for all my active members for use with another plugin.

Something like this:
$active_members = array( 1, 2, 3, 4 ) // my active members IDs here

So when I go to my Membership page to view all members, if I click Deactivate, this person's user ID won't be in the array anymore. But if I click Active they will be again.

Not sure how to do this. Thanks

  • Jarel

    Thanks for the help with the code. This helped a lot.

    However I found a weird issue with the Active/Inactive table with my database. Going to Membership > All Members in my dashboard I can see the Active column listing each member status like normal. But in the database the value for all the members was neither "yes" or "no". It was just empty.

    I ran this little function in my header.php like so:

    $blogusers = get_users( 'orderby=nicename&role=subscriber' );
    	echo '<ol>';
    	foreach ( $blogusers as $user ) {
    		$user_is_active = get_user_option( 'membership_active', $user->ID );
    		echo '<li>' . esc_html( $user->ID ) . ': '. esc_html( $user->nickname ) .' - '. $user_is_active .'</li>';
    	}
    	echo '</ol>';

    Each person just looked something like this:
    123: John Smith - .

    I found that if I manually deactivated a person then reactivated them, the correct yes/no value was saved in the db. It doesn't matter if I created the user initially, or imported them from a csv file, or a user chose to become a free or paid member. No matter what, all my users initially have an empty value in this table.

    I went through my entire members list and manually deactivated/activated each person, so the correct yes/no value is present in the db, but it's weird it wasn't there before. After this, the function I listed above correctly listed each person's status.

    Any idea what could be causing this? Thanks.

  • Vaughan

    Hi Jarel,

    I've asked the developer for some feedback on this for you, as i'm not entirely sure why that's the case.

    Were all these members registered on the site before you installed membership? it might be that this option only get's filled after a users subscription has expired or something, i'm not sure, but hopefully the developer should be able to clarify this more.

    Hopefully he should respond shortly, but it could take a little longer than usual depending on his workload.

    Thanks

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.