Gform_after_submission_ does not seem to be firing

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);


    }

}

Your hook isn’t firing because private methods aren’t callable by external functions. If you make the method public, the hook should properly execute.

1 Like

:see_no_evil:

Staring at code for too long, didn’t even see that!

Thank you!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.