Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created January 22, 2019 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/d0389a1cbf5fa12e93e07f6cf1182f52 to your computer and use it in GitHub Desktop.
Save tripflex/d0389a1cbf5fa12e93e07f6cf1182f52 to your computer and use it in GitHub Desktop.
Redirect to specific page after a new job application has been submitted when using WP Job Manager Field Editor (READ COMMENTS!!)
<?php
add_filter( 'new_job_application', 'smyles_redirect_after_new_job_application', 10, 2 );
function smyles_redirect_after_new_job_application( $application_id, $job_id ) {
// You must manually input the URL to redirect to below, currently there is no way to pull this value as it is not
// saved in any settings or configurations
// This also does not show any kind of notification to the user that their application has been submitted.
// It is recommended that you instead use a template override (https://wpjobmanager.com/document/template-overrides/)
// for the wp-content/plugins/wp-job-manager-applications/templates/application-submitted.php file (see comments below for more details)
if( wp_redirect('') ){
exit;
}
}
@tripflex
Copy link
Author

You must manually input the URL to redirect to below, currently there is no way to pull this value as it is not saved in any settings or configurations (I have opened an issue on main Applications addon to add this in an upcoming release)

This also does not show any kind of notification to the user that their application has been submitted.

It is recommended that you instead use a template override (https://wpjobmanager.com/document/template-overrides/) for the wp-content/plugins/wp-job-manager-applications/templates/application-submitted.php file and then add a redirect in that file, after say, 5 seconds or something.

You could do this by adding this HTML to that template override file:

<meta http-equiv="refresh" content="3;url=https://www.yourdomain.com/past-applications/" />

Or using vanilla javascript:

<script>
    window.setTimeout(function(){
        window.location.href = "https://www.yourdomain.com/past-applications/";
    }, 5000);
</script>

Or using jQuery:

<script>
jQuery(window).load(function () {
    window.setTimeout(function () {
        window.location.href = "https://www.yourdomain.com/past-applications/";
    }, 5000)
});
</script>

You could also use a template override for the past-applications.php file and use a redirect adding a query param to it to signify application was submitted:

add_filter( 'new_job_application', 'smyles_redirect_after_new_job_application', 10, 2 );
function smyles_redirect_after_new_job_application( $application_id, $job_id ) {
	if( wp_redirect('https://yourdomain.com/past-applications/?app_submitted=true') ){
		exit;
	}
}

And then in the template override check for that $_GET variable, and show the notice when it is set, replacing this code section:

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<table class="job-manager-past-applications">

with this:

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
if( array_key_exists( 'app_submitted', $_GET ) ):
?>
<p class="job-manager-message">
	<?php _e( 'Your job application has been submitted successfully', 'wp-job-manager-applications' ); ?>
</p>
<?php endif; ?>
<table class="job-manager-past-applications">

@DannyCare
Copy link

Thanks for this. I was wondering if the Applications addon has been updated yet, and if so how can we pull this value without using the above methods?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment