Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Last active October 3, 2015 22:45
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 AaronRutley/2e99f17df614c74ef95c to your computer and use it in GitHub Desktop.
Save AaronRutley/2e99f17df614c74ef95c to your computer and use it in GitHub Desktop.
ar_user_login.php
<?php
// ar_user_login : on WordPress login, post a message to slack
function ar_user_login($user_login) {
// get the user info
$user = get_user_by('login',$user_login);
// get the user ID
$user_id = $user->ID;
// get the user's slack username (this is custom meta)
$user_slackname = get_user_meta($user_id, 'slack_username',true);
// get the current site url
$site_url = get_bloginfo('url');
// prepare a message to be posted to slack
$message = '@'.$user_slackname.' just logged in to '.$site_url;
// post the message to slack in the general channel
ar_post_to_slack($message,'#general','WordPress bot',':taco:');
}
add_action('wp_login', 'ar_user_login', 99, 2);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment