BuddyDev

Search

Replies

  • Participant
    Level: Enlightened
    Posts: 126

    Hello Brajesh
    Unfortunately it does not work!
    I do not have an error message After a new registration, I do not have a message telling me that I did not fill in the required fields or the photo.
    I put my code https://gist.github.com/sbrajesh/3d7ab3f50dff9bc1ef2df1e9c5a28c53 with my previous modifications of the old program

    To avoid complicating, I unfortunately did not explain that I wanted to make a second program that uses your first program (a member must always have entered all the fields and put his picture).
    I do not want to modify your program or ask you (several times) to modify it so as not to disturb you

    This 2nd program will be the basis of many others that I must be able to do alone

    Today your program is working well

    Tomorrow I want to use your program class BuddyDev_Profile_Field_Completion_Helper (improved?) AND function change
    I will need to create and modify small programs function change1, function change2 …. for different contexts. examples (I know it’s not a valid code, just structures)
    CODE:

    
     
    IF the member has entered all the required fields and upload his photo (it's a simple!? 
    Check after using class BuddyDev_Profile_Field_Completion_Helper , to avoid giving rights.If it's too complicated, it is possible not to do the test
      
      add_action('wp_login', 'change1', '99', 2); 
      function change1($user_login, $user) { 
        $user_id = $user->ID; 
        $field_jesuis = '57'; 
        $jesuis = xprofile_get_field_data($field_jesuis,$bp->loggedin_user->id ); //  $user_id );
        if ( $user->has_cap('membre0') && ($jesuis='Une Femme')) {  
           ..
           do_action ...
           $user_id->add_role( 'membre1' ); 	}
       }
    
     add_action('wp_login', 'change2', '99', 2); 
     function change2($user_login, $user) { 
       $user_id = $user->ID; 
       $field_XYZ = 'XYZ'; 
       $XYZ = xprofile_get_field_data($field_XYZ,$bp->loggedin_user->id ); //  $user_id );
       if ( $user->has_cap('membre1') && ($XYZ='fsdfdsfd')) {
         ..
         do_action ...
         $user_id->add_role( 'membre2' ); 	}
      }
    
    IF END
    
    

    My 2 problems were to a) test the role at the connection of a member and b) if possible to check at the same time the mandatory entries

    If you want to stop, I understand.
    Otherwise please tell me how I can integrate very simply these different functions in your program (no risk of problem) or so give me the CODE
    Thanks

    • This reply was modified 6 years, 6 months ago by Hervé.
  • Participant
    Level: Enlightened
    Posts: 126

    I,
    In fact
    Your first code works well
    My code does not work He does not do the role change
    I wanted to have a function at the time of the connection (event: wp_login?), Which

    1 / tests the variables (equivalent of your program that works) of a member who connects and who does not have the right role (I can not explain why because it would be difficult):
    a) User must have a photo
    b) User must have all required fields
    c) subscriber rôle

    2/ If everything is ok, the member moves to the new role
    Regards

  • Participant
    Level: Enlightened
    Posts: 126

    Hi
    Thank you I understand why it has been long. You wanted to completely change your first function!!
    Now I am very embarrassed because I did not want to change it (it seems to work well).

    I just wanted a correction of my program prov_transfert($user_login, $user) [in wp_login] that did not work 🙁
    As we have trouble understanding ourselves, I did not want detailed. I then want to do several small functions for different cases.
    Regards

  • Participant
    Level: Enlightened
    Posts: 126

    Hello Brajesh
    Can you help me ?
    Regards

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on in reply to: filter the buddypress members in the list of members #15332

    Hello Brajesh

    On a site, only the filter on the photo is not taken filtered (with same id and same program)
    On another site, everything works well.
    Regards

  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on in reply to: filter the buddypress members in the list of members #15316

    Hello Brajesh

    Have there been any changes with buddypress 3.0!
    I just put
    1 / the field with a numeric field instead of a select field
    2 / the program below
    like what worked a few months ago

    Results:
    I have the first filter that works.
    2nd filter on photo_note no longer works
    Regards

    function buddydev_filter_members_list_herve( $query ) {
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	$user_id = get_current_user_id();
    	// get the value for the field.
    	// Use field id for better performance.
    	$searching_for = xprofile_get_field_data( 'Je recherche', $user_id, 'comma' );
    
    	if ( empty( $searching_for ) ) {
    		return;
    	}
    
    	if ( bp_is_user_friends() ) {
    		return;// do not filter on the friends page. It will be problemetic as it won't filter the widget/shortcode on the friends page.
    	}
    
    	$xprofile_query = isset( $query->query_vars['xprofile_query'] ) ? $query->query_vars['xprofile_query'] : array();
    
    	$xprofile_query[] = array(
    		'field'   => 'Je suis', // I suggest using field id for more efficiency.
    		'value'   => $searching_for, 
    		'compare' => '=',
    	);
    
    	if ( bp_is_members_directory() ) {
    		//photo_priorite
    		$xprofile_query[] = array(
    			'field'   => 'photo_note',
    			'value'   => 5,
    			'compare' => '>=',
    			'type'    => 'NUMERIC',
    		);
    	}
    
    	if ( ! empty( $xprofile_query ) ) {
    		$query->query_vars['xprofile_query'] = $xprofile_query;
    	}
    
    	return $query;
    }
    
    add_action( 'bp_pre_user_query_construct', 'buddydev_filter_members_list_herve', 0 );
    
  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on in reply to: filter the buddypress members in the list of members #15311

    Hello Brajesh
    https://screenshots.firefox.com/ThmtLfhSwYgeZo0A/null
    thank you for your patience
    Have a good day

    
    add_action( 'bp_pre_user_query_construct', 'buddydev_filter_members_list_herve', 0 );
    function buddydev_filter_members_list_herve( $query ) {
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
       $user_id = get_current_user_id();	
    	$field_jesuis = '57'; 
    	$field_jerecherche = '60'; 
    	$recherche_de = xprofile_get_field_data( $field_jerecherche, $user_id );	
    
    	if ( empty( $recherche_de ) ) {
    		return;
    	}
    
    	if ( bp_is_user_friends() ) {
    		return;// non appliqué si page amis (ne filtre pas sur la page des amis. Ce sera problématique car il ne filtrera pas le widget / shortcode sur la page des amis).
    	}
    
    	$xprofile_query = isset( $query->query_vars['xprofile_query'] ) ? $query->query_vars['xprofile_query'] : array();
    	$xprofile_query[] = array(
    		'field'   => $field_jesuis, 
    		'value'   => $recherche_de,
    		'compare' => '=',
    	);
    
    /* 	if ( bp_is_members_directory() ) { // DOES NOT WORK
    		$xprofile_query[] = array(
    			'field'   => 'photo_note',
    			'value'   =>  4,
    			'compare' => '>=',
    			'type'    => 'SELECT',
    		);
    	} 
    	
      if ( bp_is_members_directory() ) { // WORKS
    		$xprofile_query[] = array(
    			'field'   => 'photo_note',
    			'value'   => 4,
    			'compare' => '>=',
    			'type'    => 'NUMERIC',
    		);
    	} */
    
    	if ( ! empty( $xprofile_query ) ) {
    		$query->query_vars['xprofile_query'] = $xprofile_query;
    	}
    
    	return $query;
    }
    
  • Participant
    Level: Enlightened
    Posts: 126
    Hervé on in reply to: filter the buddypress members in the list of members #15303

    Hello Brajesh

    I changed the type of numeric field to a select (to enter only certain values
    I put in the program
    $ xprofile_query [] = array (
    ‘field’ => ‘photo_note’,
    ‘value’ => 4,
    ‘compare’ => ‘> =’,
    ‘type’ => ‘SELECT’,
    It does not work. I imagine that it is the type of field or the comparator which is not correct

    Thanks for your help*
    Regards
    Hervé

    * and for the other 🙂
    https://buddydev.com/support/forums/topic/to-the-connection-of-an-existing-member-change-role-plan/#post-15065

  • Participant
    Level: Enlightened
    Posts: 126

    Hello,
    I removed the part related to another plugin.It remains the part with your other program. Is it clearer now?
    Can you help me ?
    Regards

  • Participant
    Level: Enlightened
    Posts: 126

    Hello Brajesh
    So all is well If I talked about the other plugin, it was to explain why I developed this program. We can forget it.
    My problem is related to the connection sequence with wordpress buddypress. To be clearer, the only important code that does not work is

    
    
    add_action('wp_login', 'prov_transfert', '99', 2); 
    function prov_transfert($user_login, $user) { 
    	$user_id = $user->ID;
    	$num_plan_abonne='1';
    	$num_plan_payant_1an='4'; 
    	$field_jesuis = '57'; 
    	$jesuis = xprofile_get_field_data($field_jesuis,$bp->loggedin_user->id ); //  $user_id );
    	
    	$has_fields_complete = get_user_meta( $user_id, '_has_required_field_data', true );
    	$has_photo = $this->has_uploaded_avatar( $user_id );
    
    	if ( $has_photo && $has_fields && $user->has_cap('subscriber') && ($jesuis='Une Femme')) {
    				$this->mark_complete_profile( $user_id );
    				$incomplete = false;
    				do_action( 'buddydev_bp_user_profile_completed', $user_id );
    				
    				$user_id->add_role( 'membre0' ); // change role
    	}
    }
    
    

    The idea is at the moment of connection (That’s when I can not do it, I think), check if the member has
    * a photo
    * all mandatory fields filled
    * a subscriber role
    * a special value for an xprofile field

    If yes I change the role of the member (member0)
    Is this good?
    Regards

    • This reply was modified 6 years, 7 months ago by Hervé.
    • This reply was modified 6 years, 7 months ago by Hervé.