BuddyDev

Search

[Resolved] automatic change of type with Member Types Pro

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #11985

    Hi Herver,
    Please use backticks(`) to post the code here.

    1. No conflict with Force Profile. It does have a bit of that plugin but both will work.
    2. You will see this code

    
    bp_set_member_type( $user_id, 'member_type_unique_name', $append ); // change it.
    

    Change it to

    
    bp_set_member_type( $user_id, 'student', $append ); // change 'student' with your own unique name.
    
    

    3. Sorry, this code does not cover that. I am not sure what you mean by switching membership. I thought your goal was to set the member type when avatar is uploaded & required fields completed.

    4. I haven’t added the code for showing the notice. You can use the method ‘has_required_field_data( $user_id)’ to check for it and show the message.

    If you want me to add it, please let me know and I will add it.

    Also, if you are not comfortable with the code, please post me the message and the member type name and I will update it.

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #11989

    Hi Brajesh

    1 / super

    2 / I understood that :-). My request was to put a variable in place to put at the beginning of the file, all my variables. Is it correct ?

    3 / when everything is good, there is a change of state of the member (role, type and plan). I did not say it at first because I thought to adapt my initial code. But it seems to me that this is the right place to put a do_action . Is it
    correct ?

    4 / I look at this. Probably I will need help to finalize the code … by paying

    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #12152

    Hi Herve,
    Thank you for the patience.

    I have updated the gist
    https://gist.github.com/sbrajesh/238153f70f770f957fd1c4b2ba60be77

    Now, I have placed placeholder for the member type and message there. Please update that.

    About your other membership etc, I will suggest either hooking to “buddydev_bp_user_profile_completed” action or just put all the code in the set_member_type() method. That will be sufficient.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13880

    Hi Brajesh
    I’m sorry but I’m going to need help again
    I have a big problem with the program.
    When a member changes their profile picture, the program immediately puts it back in the base role.
    I just checked it.
    I updated the version on https://gist.github.com/sbrajesh/238153f70f770f957fd1c4b2ba60be77
    Regards

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13881

    Re
    I believe this comes from the code, to handle the case where the member removes his photo :

    
    public function mark_incomplete_profile( $user_id ) {
    		do_action( 'arm_apply_plan_to_member', 1, $user_id); // 10/01/18: HD AJOUT pour rejoindre plan sans profil finalisé (& role: subscriber)
    		return delete_user_meta( $user_id, '_has_complete_profile' );
    	}

    If a member changes their profile picture, does buddypress use an event believing that the profile picture has been deleted?

    This request is more important than my other request because there are several people who have seen their role / plan changed abnormally
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #13892
  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13955

    Hi Brajesh,

    OK it works, unfortunately if the member deletes his picture, his role is not changed to “subscriber”
    Is it possible to tell when a member changes their photo or deletes their photo?
    If it’s not possible, I stay with this mofiication
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #13959

    Hi Herve,
    I am sorry but I believe I am not sure of the original goals anymore and the modification may cause issues.

    1. You can uncomment the previous modification I have suggested
    2. and then, you can change the log_deleted function to this

    
    /**
     * On Delete Avatar, delete the user meta to reflect the change
     *
     * @param array $args see args array.
     */
    public function log_deleted( $args ) {
    
    	if ( $args['object'] != 'user' ) {
    		return;
    	}
    
    	$user_id = empty( $args['item_id'] ) ? 0 : absint( $args['item_id'] );
    
    	if ( ! $user_id ) {
    		if ( bp_is_user() && ( bp_is_my_profile() || is_super_admin() ) ) {
    			$user_id = bp_displayed_user_id();
    		} else {
    			$user_id = bp_loggedin_user_id();
    		}
    	}
    
    	$user = get_user_by( 'id', $user_id );
    	if( $user && ! is_super_admin( $user_id ) ) {
    		$user->set_role('subscriber' );
    	}
    }
    
    

    PS: should I modify the repost the gist?

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #13965

    Hello Brajesh

    Yes I understand. I explain the context:
    I want to force a new member to fill out mandatory fields and upload a profile picture.
    * If ok role change: member0 (plan0 with another plugin)
    * Otherwise role subscriber

    With a member management plugin:
    * If role subscriber: he can not have access to some pages (including groups, activity …)

    If he changes his picture no change to the wordpress role
    If it removes the photo back to the subscriber role

    I have an error:
    Parse error: syntax error, unexpected ‘public’ (T_PUBLIC), expecting end of file in/
    public function log_deleted( $args )

    I submitted last version on gist

    If too difficult, is there a way to remove with a hook the button “delete the photo” if not by css

    Regards

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #14001

    Hello Brajesh

    Is there a possibility to hide the “remove” button by program (hook)?
    otherwise I look to do it with css (less well I do)!
    Regards

You must be logged in to reply to this topic.

This topic is: resolved