Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author myCred

    (@designbymerovingi)

    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).

    Thread Starter PaulMRivera

    (@paulmrivera)

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

    Thread Starter PaulMRivera

    (@paulmrivera)

    it worked flawlessly! You are great. Thank you.

    Thread Starter PaulMRivera

    (@paulmrivera)

    resolved

    Plugin Author myCred

    (@designbymerovingi)

    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;
    }
    Thread Starter PaulMRivera

    (@paulmrivera)

    got it. thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclude type of membership’ is closed to new replies.