Last active
March 6, 2019 21:09
-
-
Save tripflex/0e8a4f19c48962f6d6fb26588268c857 to your computer and use it in GitHub Desktop.
Click Apply button automatically after user selects user package to contact Job Listing/Listinig (for WP Job Manager Packages)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'job_manager_packages_form_user_package_add_post_redirect', 'smyles_click_contact_btn_after_select_contact_pkg', 10, 5 ); | |
add_action( 'job_application_start', 'smyles_check_click_apply_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. | |
* | |
* @param $redirect | |
* @param $result | |
* @param $listing_id | |
* @param $user_package_id | |
* @param $form_type | |
* | |
* @return string | |
* @author Myles McNamara | |
* | |
*/ | |
function smyles_click_contact_btn_after_select_contact_pkg( $redirect, $result, $listing_id, $user_package_id, $form_type ) { | |
if ( $form_type === 'apply' && get_post_type( $listing_id ) === 'job_listing' ) { | |
setcookie( 'jmp-pending-click-apply', $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 | |
*/ | |
function smyles_check_click_apply_btn() { | |
if ( array_key_exists( 'jmp-pending-click-apply', $_COOKIE ) && ! empty( $_COOKIE['jmp-pending-click-apply'] ) ) { | |
// 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 () { $( '.job_application > a' ).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-apply', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment