• Resolved khrovatin

    (@khrovatin)


    I tried adding a hook (see below) when I submit a new post. The post is submitted and I get the “Success” message in the webpage, but my hook action does not seem to be activated (no redirect and no console log). Any suggestions?

    function usp_submit_success_email($redirect_url) {
    
    	// my_url is a real url, replaced here
    	wp_redirect('my_url' );
    	echo "<script>console.log('usp_submit_success_email function was executed.');</script>";
    	//error_log('my_custom_hook was executed!');
    }
    
    add_action( 'usp_submit_success', 'usp_submit_success_email', 10, 1);
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Glad to help. I’m not sure what might be happening, do you know if the hook is firing at all?

    Thread Starter khrovatin

    (@khrovatin)

    Yes, I assume that the hook may not be firing since nothing is printed out in the console and no redirect happens. Also tried with echo statements before, but no change. Do you have any ideas why that may be the case since I get the post success message?

    Plugin Author Jeff Starr

    (@specialk)

    I added this to theme functions.php and it is working as expected:

    function usp_submit_success_email($redirect_url) {
    
    	error_log('usp'); // log to WP debug
    	
    }
    add_action('usp_submit_success', 'usp_submit_success_email', 10, 1);

    Also the hook is an action, so it’s not returning any URL to the plugin function.

    Thread Starter khrovatin

    (@khrovatin)

    Thank you very much. Adding it to log worked.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Action hook usp_submit_success not working’ is closed to new replies.