Every time I use wp_get_current_user() my plugin breaks

Question

I have been trying to make a sign-out plugin that allows users to sign out from military training activities that they should be at. After they fill out a form explaining why they are not going to be at an activity, they submit it, and it puts all the data into a mysql database. I am trying to save the user’s id to their other data so we can tell who is signing out, but everything I have tried breaks the plugin, and gives me the white screen of death.

Thanks for your help. Here is my code to get the users id:

function f2user() {
// Get the current user's info 
$current_user = wp_get_current_user(); 

if ( !($current_user instanceof WP_User) ) 
    return; 

return $current_user->ID;
}

$usersid = f2user();
$activity = $_POST['activity'];
$reason = $_POST['reason'];
$explanation = $_POST['explanation'];
0
, , , FriedRyan 4 years 0 Answers 90 views 0

Leave an answer