Created
October 10, 2016 09:12
-
-
Save JarrydLong/c6a1f8390fe03e9bf7ddf33bb6a9dd4f to your computer and use it in GitHub Desktop.
Choose which page a specific agent's profile picture will display on.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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