BuddyDev

Search

[Resolved] automatic change of type with Member Types Pro

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

    Hi,

    As we had discussed by email, I want to use your plugin Member Types Pro to pass
    a member to => type “member0”, when it has completed all the required fields of buddypress
    How to do ?
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #11637

    Hi Herve,
    Thank you for posting.

    I will post the code on the Member types pro documentation site and link here later in the day.

    Thank you
    Brajesh

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

    Hi Brajesh
    It is not very urgent but thank you not to forget 🙂
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #11697

    Hi Herve,
    I am sorry for the delay. Please provide me till tomorrow. Got caught in another plugin release and could not work on it.

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #11816

    Just wanted to post an update. It is still in my list. It needs a little more than I expected(A way to trigger the all required fields complete action only once). I will be posting a proper solution and most probably a small plugin in next couple of days.

    Thank you
    Brajesh

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

    Good evening Brajesh

    If there are few interested members, I do not know if it is necessary to make another plugin!
    In this case I would rather just need a function because my need is rather simple.
    I want to automatically change member type / role when the new member has a profile photo AND enter all required fields.
    [Otherwise, he does not have access to buddypress pages (and a wordpress page) but to all other pages, articles …]

    For now I use your plugin and the following code to display a message :

    `
    add_filter( ‘bp_force_profile_photo_skip’, ‘buddydev_skip_redirect_on_non_bp_pages’ );
    function buddydev_skip_redirect_on_non_bp_pages( $skip ) {/* voir plus tard si beson d’autoriser les membre0 a ne pas avoir de photos */
    if ( !is_buddypress() ) { // OR !is_page(‘tableau-de-bord’) NE FONCTIONNE PAS
    $skip = true;
    }
    return $skip;
    }

    add_action(‘bp_before_member_body’, ‘my_bp_before_member_body’, 10, 0);
    function my_bp_before_member_body()
    {
    if (is_user_logged_in())
    {
    $user_id = wp_get_current_user()->ID;

    if($user_id == bp_displayed_user_id())
    {
    global $wpdb;
    $bp_prefix = bp_core_get_table_prefix();
    $xprofile_fields = $wpdb->get_results(“SELECT xf.name field_name, xg.name group_name FROM {$bp_prefix}bp_xprofile_fields xf”
    . ” join {$bp_prefix}bp_xprofile_groups xg on xg.id = xf.group_id”
    . ” WHERE parent_id = 0 AND is_required = 1 AND xf.id NOT IN (SELECT field_id FROM {$bp_prefix}bp_xprofile_data WHERE user_id = {$user_id} AND value IS NOT NULL AND value != ”)”);
    $xprofile_fields_count = count($xprofile_fields);
    /*$picture = get_user_meta($user_id, ‘picture’);

    if (empty($picture)) {
    $xprofile_fields_count++;
    }*/

    if ($xprofile_fields_count > 0 ) { //|| empty($picture)
    $message = ‘[su_note note_color=”#ff6668″ radius=”5″]’ .'(‘ . $xprofile_fields_count . __(‘ donnée(s) manquante(s)’, ‘bp-force-profile’) . __(‘). Merci de compléter votre profil pour devenir membre et accéder à toutes les fonctionnalités du site.’, ‘bp-force-profile’) .'<br />Sauvegardez avant de passer à un autre onglet.’;
    $message .= ‘<ul”>’;
    /*if (empty($picture)) {
    $message .= ‘<li>Photo de profil</li>’; Texte de la note
    }*/
    if ($xprofile_fields_count > 0) {
    foreach ($xprofile_fields as $field) {
    $message .= ‘<li>’ . $field->field_name . ‘ (Onglet: ‘ .$field->group_name . ‘) </li>’;
    }
    }
    $message .= ‘</ul>’;
    echo $message . ‘[/su_note]’;
    }
    }
    }
    }
    `

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

    Hello Brajesh,
    little reminder to see when you will be able to do it and if that can help me solve my problem ?
    Regards

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #11978

    HI Herve,
    My apologies for the delayed reply.

    Here is the code
    https://gist.github.com/sbrajesh/238153f70f770f957fd1c4b2ba60be77

    you should put it in bp-custom.php

    Please make sure to update the set_member_type() method with the actual member type.

    I haven’t tested it but it should work. I hope you can extend further in any way you want.

    Regards
    Brajesh

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

    Hello Brajesh,

    Wow 🙂 , I did not expect such a complete program!!

    
    Some questions:
    1/ if there will be no conflict using the BP force profile plugin at the same time?
    
    It's a pretty different programming. To avoid breaking the code, I want to know where to put my codes
    
    2/ where put in variable of the type of member (not to forget it and ... no problem):
    $member_type_unique_name='membre0'; // ??????? OK ????????
    class BuddyDev_Profile_Field_Completion_Helper {
    ...
    public function set_custom_member_type( $user_id ) {
    		$append = false; // set it to true if you just want to append this member type.
    		bp_set_member_type( $user_id, $member_type_unique_name, $append ); 
    	}
    ...
    
    3/ when I switch from member type, I have to switch also with the armember plugin:
    	public function check_on_update( $user_id ) {
    		if ( $this->has_incomplete_profile( $user_id ) && $this->has_required_field_data( $user_id ) && $this->has_uploaded_avatar( $user_id ) ) {
    			$this->mark_complete_profile( $user_id );
    			do_action( 'buddydev_bp_user_profile_completed', $user_id );
    do_action( 'arm_apply_plan_to_member', 2, $user_id); // ??????? OK ????????
    		}
    	}
    
    4/ where put my message for mandatory fields not entered:
    public function has_required_field_data( $user_id ) {
    ...
    // not all fields are set.
    		if ( $count != count( $required_fields ) ) {
    			// unset flag.
    			delete_user_meta( $user_id, '_has_required_field_data' );
    ***********// ??????? OK ????????
                    $message = '[su_shadow style="horizontal"][su_note note_color="#ff6668" radius="5"]' .'(' . $xprofile_fields_count . __(' donnée(s) manquante(s)', 'bp-force-profile') . __('). Merci de compléter votre profil pour 						 devenir membre et accéder à toutes les fonctionnalités du site.', 'bp-force-profile') .'<br />Sauvegardez avant de passer à un autre onglet.';
                    $message .= '<ul">';
                    /*if (empty($picture)) {
                        $message .= '<li>Photo de profil</li>'; Texte de la note
                    }*/
                    if ($xprofile_fields_count > 0) {
                        foreach ($xprofile_fields as $field) {
                        	 $message .= '<li>' . $field->field_name . ' (Onglet: ' .$field->group_name . ') </li>';
                        }
                    }
                    $message .= '</ul>';                
                    echo  $message . '[/su_note][/su_shadow]';
    ***********
    

    Regards

    • This reply was modified 4 years, 8 months ago by Brajesh Singh. Reason: updated to use backtick
  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on #11981

    Oups
    Sorry, I think the code on the forum is not working well.
    I copied it in https://gist.github.com/sbrajesh/238153f70f770f957fd1c4b2ba60be77

You must be logged in to reply to this topic.

This topic is: resolved