Hi All
Im trying to run some code after a form is submitted and before the redirect URL is returned to the client.
My form is in embedded into a learn dash course page and Im pretty sure its submitted via ajax.
My code is in a custom plugin file and the code works 100% if I call it directly. But doesn’t seem to fire when the hook is called.
Ive tried everything inside the callback function, print_r(), die(), echo(), nothing is working in there.
Tia for the help!
<?php
namespace PreActive\Hooks;
use PreActive\Courses\Knpcourse;
use PreActive\User\Knpuser;
class Knppa
{
public $sittingScore = [
'low' => 24,
'mid' => [24, 34],
'high' => 34
];
public $standingScore = [
'low' => 25,
'mid' => [25, 36],
'high' => 36
];
public function __construct()
{
//Run after the mobility form is submitted. NOT WORKING!
add_action('gform_after_submission_4', [$this, 'knp_process_welcomecourse'], 10, 1);
//Run directly from the browser (domain.com/?knoppys) works fine!
if (isset($_GET['knoppys'])) {
$this->knp_process_welcomecourse([18 => 'no']);
}
}
private function knp_process_welcomecourse($entry)
{
//Get current user data
$profile = new Knpuser();
//Create new course
$course = new Knpcourse();
$course->new_course(20096);
//Assign the new weeks
$sitstand = $entry[18] == 'yes' ? 'standing' : 'seated';
$course->assign_sit_stant_weeks($sitstand);
//Update user profile
$decodedData = $profile->get_user_profile();
$decodedData['sit_stand_status'] = $sitstand;
$profile->update_user_profile($decodedData);
}
}