Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save champsupertramp/191a95ae3212ceb8085d to your computer and use it in GitHub Desktop.
Save champsupertramp/191a95ae3212ceb8085d to your computer and use it in GitHub Desktop.
Ultimate Member - Follower Extensions - Auto-follow specific users on registration
<?php
add_action('um_after_new_user_register','um_auto_follow_artists',10,2);
function um_auto_follow_artists( $user_id, $args ){
global $ultimatemember, $um_followers;
$follow_users = array(
'rjtmusic',
'james-peacock',
'carl-thomson',
'jonathan-proud',
'stu-dawson',
'carly-mckee',
);
foreach( $follow_users as $username ){
$follow_user = get_user_by( 'login', $username );
$um_followers->api->add( $follow_user->ID, $user_id );
}
}
?>
@champsupertramp
Copy link
Author

Updates for UM 2.0 compatibility

<?php
add_action('um_user_register','um_auto_follow_members',5,2);
function um_auto_follow_members( $user_id, $args ){
 
	 $follow_users = array( 
		'rjtmusic',
		'james-peacock',
		'carl-thomson',
		'jonathan-proud',
		'stu-dawson',
		'carly-mckee',
	 );

	 foreach( $follow_users as $username ){
	        $follow_user = get_user_by( 'login', $username );
	 	UM()->Followers_API()->api()->add( $follow_user->ID, $user_id );
	 }

 }

?>

@PJSAnd
Copy link

PJSAnd commented Jul 13, 2018

Hi Champ,

This is just what I was looking for.

How would I adjust the code to follow max 100 members ranked in order of how many friends they have?

Thanks
Patrick

@emmyloaded
Copy link

emmyloaded commented Dec 9, 2020

where will I paste this code? function.php ?

Please help me

@champsupertramp
Copy link
Author

Hi @emmyloaded

You can use this plugin to add the code snippet:
https://wordpress.org/plugins/code-snippets/

Regards,

@emmyloaded
Copy link

Hi @emmyloaded

You can use this plugin to add the code snippet:
https://wordpress.org/plugins/code-snippets/

Regards,

What will I edit here? the name of the special users I want other users to follow or user ID

@champsupertramp
Copy link
Author

champsupertramp commented Dec 10, 2020

Hi @emmyloaded,

IF you want the newly registered user to follow specific users by ID, you can try the following:

add_action('um_user_register','um_auto_follow_members',5,2);
function um_auto_follow_members( $user_id, $args ){
 
  $follow_users_IDs = array( 
		1,
               33,
               444,
	 );

	 foreach( $follow_users_IDs as $follow_user_id ){
	      UM()->Followers_API()->api()->add(  $follow_user_id, $user_id );
	 }
}

$user_id - this is the ID of the newly registered user
$follow_users_IDs - these are the user IDs who will be followed by the newly registered user.

Regards,

@emmyloaded
Copy link

Hi @emmyloaded,

IF you want the newly registered user to follow specific users by ID, you can try the following:

add_action('um_user_register','um_auto_follow_members',5,2);
function um_auto_follow_members( $user_id, $args ){
 
  $follow_users_IDs = array( 
		1,
               33,
               444,
	 );

	 foreach( $follow_users_IDs as $follow_user_id ){
	      UM()->Followers_API()->api()->add(  $follow_user_id, $user_id );
	 }
}

$user_id - this is the ID of the newly registered user
$follow_users_IDs - these are the user IDs who will be followed by the newly registered user.

Regards,

excatly what i'm saying... my special user IDs are 1, 2, 4,

thanks i really appriciate that. i have over 20,000 registerd users now, even the admin has only 50 followers is there anyway to do the old users ?

@emmyloaded
Copy link

Have tried it my follower is not increasing

@emmyloaded
Copy link

Hello

Hi @emmyloaded,

IF you want the newly registered user to follow specific users by ID, you can try the following:

add_action('um_user_register','um_auto_follow_members',5,2);
function um_auto_follow_members( $user_id, $args ){
 
  $follow_users_IDs = array( 
		1,
               33,
               444,
	 );

	 foreach( $follow_users_IDs as $follow_user_id ){
	      UM()->Followers_API()->api()->add(  $follow_user_id, $user_id );
	 }
}

$user_id - this is the ID of the newly registered user
$follow_users_IDs - these are the user IDs who will be followed by the newly registered user.

Regards,

Please explain this better please.. I don’t understand to use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment