WordPress.org

Ready to get started?Download WordPress

Forums

myCRED
[resolved] Exclude type of membership (7 posts)

  1. PaulMRivera
    Member
    Posted 8 months ago #

    Is it possible to exclude a membership level? I use the plugin, Paid Memberships Pro, and I want to exclude a certain membership from having to use the creds.

    Thanks

    http://wordpress.org/plugins/mycred/

  2. Gabriel
    Member
    Plugin Author

    Posted 8 months ago #

    Hey.

    I have never used the Paid Memberships Pro plugin so I had to read up on the documentations and there are functions we could use for this.

    But first, in the current version of myCRED (1.3.2) there is no simple way to accomplish this. In the next version however there will be several filters added that allows you to do this much easier.

    So if you want, you can do this by first modifing the mycred-functions.php file.
    If you open this file which is located in wp-content/plugins/mycred/includes/ and on line 714 replace the current Exclude User function with the following:

    /**
     * Exclude User
     * Checks is the given user id should be excluded.
     *
     * @param $user_id (int), required user id
     * @returns boolean true on user should be excluded else false
     * @since 0.1
     * @version 1.0.1
     */
    public function exclude_user( $user_id = 0 ) {
    	if ( apply_filters( 'mycred_exclude_user', false, $user_id ) === true ) return true;
    	if ( $this->exclude_plugin_editors() == true && $this->can_edit_plugin( $user_id ) == true ) return true;
    	if ( $this->exclude_creds_editors() == true && $this->can_edit_creds( $user_id ) == true ) return true;
    	if ( $this->in_exclude_list( $user_id ) ) return true;
    
    	return false;
    }

    The above change will be included in the next update of myCRED so you will not loose any changes once you update.

    Now we just need to hook into the mycred_exclude_user filter:
    Example: Check if the user has membership "Gold", if they do, exclude them:

    add_filter( 'mycred_exclude_user', 'check_membership_exclusion', 10, 2 );
    function check_membership_exclusion( $result, $user_id ) {
    	// If the user has membership "Gold", exclude
    	if ( pmpro_hasMembershipLevel( 'Gold', $user_id ) ) return true;
    	return $result;
    }

    You exclude by returning true. Else return the result.

    You can find more information about the pmpro_hasMembershipLevel function here (login required).

  3. PaulMRivera
    Member
    Posted 8 months ago #

    wow you are freaking amazing. I'll test it out. thank you so much

  4. PaulMRivera
    Member
    Posted 8 months ago #

    it worked flawlessly! You are great. Thank you.

  5. PaulMRivera
    Member
    Posted 8 months ago #

    resolved

  6. Gabriel
    Member
    Plugin Author

    Posted 8 months ago #

    Here is an updated version, as I forgot to check to make sure the Paid Memberships Pro is enabled for this to work. Right now the above code will cause your site to crash if you ever disable this plugin. To avoid this we would need to make sure Paid Memberships Pro is installed:

    add_filter( 'mycred_exclude_user', 'check_membership_exclusion', 10, 2 );
    function check_membership_exclusion( $result, $user_id ) {
    	// Make sure Paid Memberships Pro is installed
    	if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) return $result;
    
    	// If the user has membership "Gold", exclude
    	if ( pmpro_hasMembershipLevel( 'Gold', $user_id ) ) return true;
    	return $result;
    }
  7. PaulMRivera
    Member
    Posted 8 months ago #

    got it. thanks.

Reply

You must log in to post.

About this Plugin

About this Topic