Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active March 26, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/407a288611c3a4fba6528f9326243a14 to your computer and use it in GitHub Desktop.
Save tripflex/407a288611c3a4fba6528f9326243a14 to your computer and use it in GitHub Desktop.
Click contact resume button automatically after user selects user package to contact resume (for WP Job Manager Packages)
<?php
add_filter( 'job_manager_packages_form_user_package_add_post_redirect', 'smyles_click_contact_btn_after_select_contact_pkg', 10, 5 );
add_action( 'single_resume_start', 'smyles_check_click_contact_btn' );
/**
* Add cookie after user selects own package to contact resume
*
* This method will be called when a user selects a specific contact package to use to contact a resume, and it will
* set a cookie that will be read when the page reloads/redirects, and will automatically click the contact button.
*
* @author Myles McNamara
* @updated 3/26/2018
*
* @param $redirect
* @param $result
* @param $listing_id
* @param $user_package_id
* @param $form_type
*
* @return string
*/
function smyles_click_contact_btn_after_select_contact_pkg( $redirect, $result, $listing_id, $user_package_id, $form_type ){
if( $form_type === 'contact' && get_post_type( $listing_id ) === 'resume' ){
setcookie( 'jmp-pending-click-contact', $listing_id, time() + 300, COOKIEPATH, COOKIE_DOMAIN, false ); // 5 min max cookie
}
return $redirect;
}
/**
* Check for cookie to automatically click contact button
*
* @author Myles McNamara
* @updated 3/26/2018
*/
function smyles_check_click_contact_btn(){
if( array_key_exists( 'jmp-pending-click-contact', $_COOKIE ) && ! empty( $_COOKIE['jmp-pending-click-contact'] ) ){
// After 1 second (1000 milliseconds) the resume contact button will be clicked (to allow other jQuery plugins to register callbacks to button before clicking)
?>
<script>jQuery( function( $ ){ setTimeout( function(){ $('.resume_contact_button').click(); }, 1000 ); });</script>
<?php
// Set cookie to empty value with expiration of an hour ago (to remove on next page load)
setcookie( 'jmp-pending-click-contact', '', time()-3600, COOKIEPATH, COOKIE_DOMAIN, false );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment