PeepSo_USERFOLLOWSAUSER::user_follows_user( $data )

Validation function when the trigger action is hit


Parameters Parameters

$user_id

(Required)


Source Source

File: src/integrations/peepso/triggers/peepso-userfollowsauser.php

	public function user_follows_user( $data ) {

		$recipes       = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		$required_post = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );

		if ( ! $recipes ) {
			return;
		}

		if ( ! $required_post ) {
			return;
		}

		$follow_usr_id = 0;
		//Add where option is set to Any post / specific post
		foreach ( $recipes as $recipe_id => $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {
				$trigger_id    = $trigger['ID'];
				$follow_usr_id = intval( $required_post[ $recipe_id ][ $trigger_id ] );
				if ( $follow_usr_id ) {
					continue;
				}
			}
		}

		if ( 'followerajax.set_follow_status' === $data ) {
			//phpcs:ignore PeepSo.Native.Ajax.Methods
			if ( automator_filter_has_var( 'follow', INPUT_POST ) && 0 === automator_filter_input( 'follow', INPUT_POST ) ) {
				return;
			}

			$user_id       = automator_filter_has_var( 'uid', INPUT_POST ) ? absint( automator_filter_input( 'uid', INPUT_POST ) ) : false;
			$follower_id   = automator_filter_has_var( 'user_id', INPUT_POST ) ? absint( automator_filter_input( 'user_id', INPUT_POST ) ) : false;
			$follow_status = automator_filter_has_var( 'follow', INPUT_POST ) ? absint( automator_filter_input( 'follow', INPUT_POST ) ) : false;

			if ( false === $follow_status || false === $follower_id ) {
				return;
			}

			if ( intval( $follow_usr_id ) === intval( '-1' ) ) {
				$follow_usr_id = $follower_id;
			} else {
				if ( $follower_id !== $follow_usr_id ) {
					return;
				}
			}

			$peepso_user   = PeepSoUser::get_instance( $follow_usr_id );
			$peepso_c_user = PeepSoUser::get_instance( $user_id );

			$args = array(
				'code'           => $this->trigger_code,
				'meta'           => $this->trigger_meta,
				'post_id'        => - 1,
				'ignore_post_id' => true,
				'user_id'        => $user_id,
				'is_signed_in'   => true,
			);

			$args = Automator()->maybe_add_trigger_entry( $args, false );

			// Save trigger meta
			if ( $args ) {
				foreach ( $args as $result ) {
					if ( true === $result['result'] && $result['args']['trigger_id'] && $result['args']['get_trigger_id'] ) {

						$run_number = Automator()->get->trigger_run_number( $result['args']['trigger_id'], $result['args']['get_trigger_id'], $result['args']['user_id'] );
						$save_meta  = array(
							'user_id'        => $result['args']['user_id'],
							'trigger_id'     => $result['args']['trigger_id'],
							'run_number'     => $run_number, //get run number
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'ignore_user_id' => true,
						);

						$save_meta['meta_key']   = 'AVATARURL';
						$save_meta['meta_value'] = $peepso_user->get_avatar();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_USERID';
						$save_meta['meta_value'] = absint( $follow_usr_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_USERNAME';
						$save_meta['meta_value'] = $peepso_user->get_username();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_FIRST_NAME';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_name( $peepso_user->get_fullname(), 'first' );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_LAST_NAME';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_name( $peepso_user->get_fullname(), 'last' );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_GENDER';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_gender( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_BIRTHDATE';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_birthdate( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_FOLLOWERS';
						$save_meta['meta_value'] = PeepSoUserFollower::count_followers( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_FOLLOWING';
						$save_meta['meta_value'] = PeepSoUserFollower::count_following( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_PROFILEURL';
						$save_meta['meta_value'] = $peepso_user->get_profileurl();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_EMAIL';
						$save_meta['meta_value'] = $peepso_user->get_email();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_ABOUTME';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_bio( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_WEBSITE';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_website( $follower_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'FL_ROLE';
						$save_meta['meta_value'] = $peepso_user->get_user_role();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_AVATARURL';
						$save_meta['meta_value'] = $peepso_c_user->get_avatar();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_GENDER';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_gender( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_BIRTHDATE';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_birthdate( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_FOLLOWERS';
						$save_meta['meta_value'] = PeepSoUserFollower::count_followers( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_FOLLOWING';
						$save_meta['meta_value'] = PeepSoUserFollower::count_following( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_PROFILEURL';
						$save_meta['meta_value'] = $peepso_c_user->get_profileurl();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_ABOUTME';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_bio( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_WEBSITE';
						$save_meta['meta_value'] = Automator()->helpers->recipe->peepso->get_website( $user_id );
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_ROLE';
						$save_meta['meta_value'] = $peepso_c_user->get_user_role();
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'USR_USERROLE';
						$save_meta['meta_value'] = $peepso_c_user->get_user_role();
						Automator()->insert_trigger_meta( $save_meta );

						Automator()->maybe_trigger_complete( $result['args'] );
					}
				}
			}
		}
	}