Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Retrieves affiliate id for the given user.
- *
- * @param int $user_id user id.
- *
- * @return string|null
- */
- function bdx_get_affiliate_id( $user_id ) {
- global $wpdb;
- $table = $wpdb->prefix . 'uap_referrals';
- return $wpdb->get_var( $wpdb->prepare( "SELECT affiliate_id FROM {$table} WHERE refferal_wp_uid =%d", $user_id ) );
- }
- /**
- * Make all newly signing user's folllow their sponsor automatically(the affiliate who invited them).
- */
- add_action( 'user_register', function ( $user_id ) {
- // 1. check if follow exists.
- if ( ! function_exists( 'bp_follow_is_following' ) ) {
- return;
- }
- global $indeed_db;
- if ( empty( $indeed_db ) || ! method_exists( $indeed_db, 'get_uid_by_affiliate_id' ) ) {
- return;
- }
- // check if wp affiliates pro exists.
- $affiliate_id = bdx_get_affiliate_id( $user_id );
- if ( ! $affiliate_id ) {
- return;
- }
- $affiliate_wp_user_id = $indeed_db->get_uid_by_affiliate_id( $affiliate_id );
- if ( ! $affiliate_wp_user_id ) {
- return;
- }
- $args = array(
- 'leader_id' => absint( $affiliate_wp_user_id ),
- 'follower_id' => $user_id,
- );
- if ( ! bp_follow_is_following( $args ) ) {
- bp_follow_start_following( $args );
- }
- }, 100 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement