Wondering if it is possible to add additional Subscription Status types?

I am wondering if we are able to additional Subscription Status types? By default, it comes with Active / Cancelled / Expired but we want to add 'deceased'. Well, we don't necessarily need deceased, but we do need one for SUSPENDED.
This is because some members violate our terms and we need to suspend their memberships. There are certain steps they can do to get their memberships back. So we would need a list of the suspended members. Please help.

  • Adam Czajczyk
    • Support Gorilla

    Hi Simon

    I hope you're well today and thank you for your question!

    Adding a "full featured" additional statuses wouldn't be that easy. It would require a lot of "under the hood" issues to be addressed and that would mean quite a lot of additional development on a plugin's core level.

    However, it might be possible to add some statuses in that sense that they'd actually be just "names" - so for example a "suspended" status would not affect a member in any way except temporarily blocking access (like removing membership at all) and just "naming" the status as "suspended", but not e.g. changing the end date of the payment. But that's only my opinion so far and I need to consult that with developers so I'm not making promises for now. I hope that's fine.

    Having that said, I passed the question to our developers and asked them about that. Please keep an eye on this ticket and we'll let you know if there's some reasonable solution to that (and if so, what could that be) or if it wouldn't be doable (or would require a whole complex custom development).

    Best regards,
    Adam

  • Panos
    • SLS

    Hi there Simon ,

    It's not that simple to add new status as it is being checked in several places in plugin code and will be hard to achieve and preserve after updates. I looked for available filters and they won't be helpful for this requirement. For this you would have to hire a skilled developer and it needs to be repeated on each plugin update.

    I would suggest a different approach here, which again requires some custom coding, so we can't support this fully. I'll provide snippet examples which you can use as a guide. These should be working properly, but would ban a member from all posts/pages that have protection enabled.

    After that being said, I would suggest to use a custom user meta field, eg ms_is_banned to flag a member as banned. Then we can use that in the ms_get_rule_value as in the following example snippet:

    add_filter( 'ms_get_rule_value', function( $value, $id, $rule_type, $ms_rule ){
    
    	if ( is_user_logged_in() ) {
    
    		$is_banned = get_user_meta( get_current_user_id(), 'ms_is_banned', true );
    		$is_banned = ( empty( $is_banned ) || ! $is_banned ) ? false : true; 
    
    		if (
    			$is_banned &&
    			is_scalar( $id ) &&
    			isset( $ms_rule->rule_value[ $id ] )
    		)
    		{
    			$value = false;
    		}
    	}
    
    	return $value;
    }, 20, 4 );

    Here is a simple sample snippet, providing a simple checkbox, to handle that meta field from a user's profile page in admin:

    function wpmudev_ms_banned_meta_field( $user ) {
    
    	if ( ! current_user_can( 'manage_options' ) ) {
    		return;
    	}
        ?>
        <h3>Ban member's access from protected pages</h3>
        <table class="form-table">
            <tr>
                <th>
                    <label for="ms_is_banned">Ban this member</label>
                </th>
                <td>
                    <input type="checkbox"
                           class="regular-text ltr"
                           id="ms_is_banned"
                           name="ms_is_banned"
                           value="1"
                           <?php checked( get_user_meta( $user->ID, 'ms_is_banned', true ), true ); ?> >
                    <p class="description">
                        If banned, member will not have access to protected content
                    </p>
                </td>
            </tr>
        </table>
        <?php
    }
    
    function wpmudev_ms_banned_meta_field_update( $user_id )
    {
    
        if ( ! current_user_can('edit_user', $user_id ) ) {
            return false;
        }
    
        $ban_user = isset( $_POST['ms_is_banned'] ) && $_POST['ms_is_banned'];
        if ( $ban_user ) {
        	return update_user_meta(
    	        $user_id,
    	        'ms_is_banned',
    	        true
    	    );
        }
        else {
        	delete_user_meta( $user_id, 'ms_is_banned' );
        }
    
    }
    
    add_action(
        'edit_user_profile',
        'wpmudev_ms_banned_meta_field'
    );
    
    add_action(
        'show_user_profile',
        'wpmudev_ms_banned_meta_field'
    );
    
    add_action(
        'personal_options_update',
        'wpmudev_ms_banned_meta_field_update'
    );
    
    add_action(
        'edit_user_profile_update',
        'wpmudev_ms_banned_meta_field_update'
    );

    You can paste the above snippets in mu-plugin. If you are not familiar with mu-plugins you can read about them here :
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Hope this was helpful!

    Kind regards!

  • Simon
    • Flash Drive

    Hi Panos,

    I had had confirmation that we need to go ahead with this so I just have one question.

    If I hire a developer to do this, can you please explain what you mean by 'it needs to be repeated on each plugin update'?

    What exactly will need to be repeated?

    Are we able to complete this and not update the plugin? Or would this cause issues?

  • Predrag Dubajic
    • Support

    Hi Simon,

    If you decide to go with the approach by hiring a developer that will make the changes, that means that he will need to edit plugin core files.
    So once the plugin has an update those changes will be overwritten and would need to be applied again, or as Panos said you will need to repeat the changes.

    Best regards,
    Predrag

  • Predrag Dubajic
    • Support

    Hi Simon,

    If you provide us with a code we can forward it to our developers for a review so they can check if it's something that can be included in the plugin core.

    There are multiple things going on within the plugin updates, some are related to security and stability, some are bug fixes, some are for compatibility with WordPress and plugins/themes so if you keep working with an outdated plugin we couldn't guarantee that it would work properly and couldn't offer you proper support for it.

    Best regards,
    Predrag

  • Simon
    • Flash Drive

    Hi Ash,

    Yeah it's working well thanks.

    With the new private memberships I can creating, how can I make these memberships unable to access any restricted content.

    For example with deceased, obviously that person no longer needs to access the content. It just protects from other people using the login.

  • Ash
    • WordPress Hacker

    Hi Simon

    If you have multiple memberships assigned to a member, and a post is not protected with a membership, and protected with another membership - the member will be able to access that post.

    So, it's better to remove previous membership and assign "deceased" membership to that member and then he won't be able to access.

    Hope it helps! Have a nice day :slight_smile:

    Cheers,
    Ash

  • Simon
    • Flash Drive

    Sorry Ash,

    I probably didn't explain myself well enough.

    I want the membership named 'Deceased' to have ZERO access at all.

    The whole reason we are doing this is just a workaround way of putting a note next to someone which explains why they are NO LONGER A MEMBER.

    So effectively I want this DECEASED membership to work as EXPIRED (No access to anything).

    Hope this makes sense!

  • Ash
    • WordPress Hacker

    Hello Simon

    Please try the following code:

    add_action( 'template_redirect', function() {
    	if( ! is_user_logged_in() ) return;
    
    	$restricted_membership_id = 5061;
    	$protected_page_id = 17;
    
    	global $post;
    	if( isset( $post->ID ) && $post->ID == $protected_page_id ) return;
    
    	$member = MS_Factory::load( 'MS_Model_Member', get_current_user_id() );
    	if( $member->has_membership( $restricted_membership_id ) ) {
    		wp_redirect( get_the_permalink( $protected_page_id ) );
    		exit;
    	}
    } );

    You need to set the deceased membership ID and protected content page ID in the above code. You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Simon
    • Flash Drive

    Hi Ash,

    Sorry for the delayed reply, I have just got round to trying this.

    I added your code to the functions.php file but on a demo link (it's an exact replica of the live site). This is the demo link: https://masterpainters.asn.au/demo1/

    I set the page ID to the membership page, and the Membership ID for the 'Deceased' Membership type.

    Unfortunately it has not worked. I created myself a deceased membership for testing and I am still able to access the restricted content page.

    Can you please have a look at this for me? I have enabled support on the demo link so you are welcome to create yourself a deceased membership, then login from the home page and you will see you can still access the page.

    Any further assistance would be greatly appreciated.

    Kind Regards,
    Simon Thomas

  • Ash
    • WordPress Hacker

    Hello Simon

    Please create a membership called deceased and let me know the ID of the membership. Then create a user and assign to that membership. Send me login details of that user. Also, send me admin login of the site. I will also need your cPanel details.

    If you send the above information of the demo site, that's fine too. But let me know the directory path to the demo site folder.

    You can send me privately in the following format:
    1. Please go to https://premium.wpmudev.org/contact/#i-have-a-different-question
    2. Select "I have a different question" if not selected
    3. In subject line put "Attn-Ashok" (this will ensure that the email is assigned to me)
    4. Provide the wanted details.
    5. Add the thread link in the message so that I can track.

    I will take a look. Have a nice day!

    Cheers,
    Ash

  • Simon
    • Flash Drive

    Hi Ash,

    Actually those are the front end pages. Anyone should have access to those pages, you do not need to be logged in to view these pages.

    The only pages which are meant to be protected are the ones you can only see from the 'my account' page when you login.

    Here is a screenshot of where you can login from the home page, make note to login with that deceased membership and you will see that you have access: https://prnt.sc/m1ia62

  • Simon
    • Flash Drive

    Hi Ash,

    Yes thats correct. The parent member center page and all those links inside it should all be protected.

    They should not have access to the website backend, I am 99% sure they don't have access to the backend anyway.

  • Ash
    • WordPress Hacker

    Hello Simon

    Please check the first issue, I left the code uncommented as this is demo site and so that you can check.

    What we really need is for all NON MEMBERS to be set as either cancelled, or expired. They are not paying fees so they should not show in the search results.

    This has to be quite tricky. I don't know which plugin is used to make this search result, but you have to modify the search result. If they provide and hook and you can use the hook to exclude the member from the result.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.