Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active April 17, 2023 00:42
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 KaineLabs/16993b4f62996a5082bea6a935a0d9f3 to your computer and use it in GitHub Desktop.
Save KaineLabs/16993b4f62996a5082bea6a935a0d9f3 to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Make all Users Friend With Admin
<?php
/**
* Youzify - BuddyPress Make all Users Friend With Admin
* **/
function yzc_make_all_accounts_friend_with_admin() {
$option_name = 'yzc_make_all_admin_friends';
if ( ! get_option( $option_name ) && bp_is_active( 'friends' ) ) {
// Admin ID
$accounts = array( 1, 2 );
// Get All users Id's
$users = get_users( array( 'fields' => 'id', 'exclude' => $accounts ) );
foreach ( $users as $user_id ) {
foreach ( $accounts as $account_id ) {
friends_add_friend( $account_id, $user_id, true );
}
}
update_option( $option_name, 1 );
}
}
add_action( 'init', 'yzc_make_all_accounts_friend_with_admin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment