// Hook into WordPress action for password reset request add_action('lostpassword_post', 'slack_alert_lost_password_action'); function slack_alert_lost_password_action() { if (isset($_POST['woocommerce-lost-password-nonce'])) { $user_email = sanitize_email($_POST['user_login']); $user_data = get_user_by('email', $user_email); if ($user_data) { $user_id = $user_data->ID; $user_display_name = $user_data->display_name; $current_time = current_time('Y-m-d g:i:s A'); $slack_message = "Password reset requested for user: $user_display_name ($user_email) at $current_time"; $slack_webhook_url = 'SLACK_WEBHOOK_URL'; $payload = json_encode(array( 'text' => $slack_message )); $args = array( 'body' => $payload, 'headers' => array('Content-Type' => 'application/json'), 'timeout' => 5, 'redirection' => 5, 'blocking' => true, 'sslverify' => false, ); $response = wp_remote_post($slack_webhook_url, $args); // Uncomment below to debug response // if (is_wp_error($response)) { // $error_message = $response->get_error_message(); // error_log("Error sending Slack alert: $error_message"); // } } } }