BuddyDev

Search

Buddypress Auto-Follow from other registeration page

  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #42921

    Buddypress Auto-Follow from a different registeration page

  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #42922
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24250
    Brajesh Singh on #42956

    Hi Iken,
    Thank you for the questions.

    1. The plugin does not restrict number of followers.

    2. Yes, you can make a user follow if another user registers.

    Just saw, you are not using BuddyPress registration and You will not need the auto friendship plugin.

    As a token of thank you, I will check with my team and hopefully supply you code to achieve it next week.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #42964
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #43037
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #43137
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24250
    Brajesh Singh on #43149
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #43219
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 69
    evil lizard on #43233
    This reply has been marked as private.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2953
    Ravi on #43247

    Hello,

    Please try the following code:

    
    /**
     * Get affiliates users
     *
     * @return array
     */
    function buddydev_get_affiliates_users() {
    
    	if ( ! class_exists( 'UAP_Main' ) ) {
    		return array();
    	}
    
    	global $indeed_db;
    
    	$affiliates = $indeed_db->get_affiliates( - 1, - 1, false, '', '', array() );
    
    	if ( ! $affiliates ) {
    		return array();
    	}
    
    	$users = array();
    	foreach ( $affiliates as $affiliate ) {
    		$users[ $affiliate['uid'] ] = $affiliate['name'];
    	}
    
    	return $users;
    }
    
    add_action( 'uap_register_form_before_submit_button', function () {
    	$affiliate_users = buddydev_get_affiliates_users();
    	?>
    	<div class="uap-form-line-register uap-form-uap_affiliate_user">
    	<?php if ( $affiliate_users ) : ?>
    		<label for="uap_affiliate_user" class="uap-labels-register"><?php _e( 'Affiliate User' ); ?></label>
    		<select name="uap_affiliate_user" id="uap_affiliate_user" class="uap-form-element uap-form-element-select" tabindex="-1" aria-hidden="true">
    			<option value=""><?php _e( 'Choose from affiliate users' ) ?></option>
    			<?php foreach ( $affiliate_users as $user_id => $name ) : ?>
    			<option value="<?php echo esc_attr( $user_id ); ?>"><?php echo esc_html( $name ); ?></option>
    			<?php endforeach; ?>
    		</select>
    	<?php endif; ?>
    	</div>
    	<?php
    } );
    
    add_action( 'uap_on_register_action', function ( $user_id ) {
    	// No checking nonce as action fire after checking nonce.
    	if ( empty( $_POST['uap_affiliate_user'] ) || ! function_exists( 'bp_follow_start_following' ) ) {
    		return;
    	}
    
    	$args = array(
    		'leader_id'   => absint( $_POST['uap_affiliate_user'] ),
    		'follower_id' => $user_id,
    	);
    
    	if ( ! bp_follow_is_following( $args ) ) {
    		bp_follow_start_following( $args );
    	}
    } );
    
    

    For automatically follow selected affiliate user on the register.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved