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 JarrydLong/c6a1f8390fe03e9bf7ddf33bb6a9dd4f to your computer and use it in GitHub Desktop.
Save JarrydLong/c6a1f8390fe03e9bf7ddf33bb6a9dd4f to your computer and use it in GitHub Desktop.
Choose which page a specific agent's profile picture will display on.
add_action("wplc_hook_push_js_to_front", "my_function"); //Our Hook
function my_function(){ //Our Function
$post_id = url_to_postid($url); //Get Post ID
if($post_id === 3){ //Post ID matches '3'
//More complicated logic could be added
$user_id = 5; //Set the new user ID - You would need your own logic here
change_active_agent($user_id); //Set the active agent to '$user_id'
}
//More logic branches here
}
function change_active_agent($user_id){
//Get all users
$user_array = get_users(array(
'meta_key' => 'wplc_ma_agent',
));
//Remove all users 'Agent' role
if ($user_array) {
foreach ($user_array as $user) {
$uid = $user->ID;
$wplc_ma_user = new WP_User( $uid );
$wplc_ma_user->remove_cap( 'wplc_ma_agent' );
delete_user_meta($uid, "wplc_ma_agent");
delete_user_meta($uid, "wplc_chat_agent_online");
}
}
//Set the user with '$uid' to the active agent
$uid = intval($user_id);
$wplc_ma_user = new WP_User( $uid );
$wplc_ma_user->add_cap( 'wplc_ma_agent' );
update_user_meta($uid, "wplc_ma_agent", 1);
update_user_meta($uid, "wplc_chat_agent_online", time());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment