Set expired JobAdder jobs to draft
By default, when a job is removed from the JobAdder feed, either because it was deleted or the job expired, JobRelay will delete this job from WordPress.
Some customers, rather than have the job removed from WordPress, would like to keep it, but change its status.
When a job is marked to be deleted, JobRelay fires a WordPress action (like an event) named jobrelay_jobadder_delete_job
. Hooked to this action is a function which deletes the job.
You could use the following code, in the themes functions.php
file or in a plugin to remove this function from running when the action is fired, this prevent jobs from being deleted.
/**
* Removes the function which deletes JobAdder jobs.
*/
function hd_prevent_jobadder_job_deletion() {
remove_action( 'jobrelay_jobadder_delete_job', 'jobrelay_delete_jobadder_jobs', 10, 2 );
}
add_action( 'init', 'hd_prevent_jobadder_job_deletion' );
If you wanted to take a different action for jobs which would otherwise be deleted, you code write your own function, hooked into the jobrelay_jobadder_delete_job
action to handle this.
The example below, shows how you could change the post_status
of the jobs to set them to draft.
/**
* Sets the posts status of JobAdder jobs to delete, to draft.
*
* @param int $job_id The ID of the job post.
* @param array $job_data The data of the job post.
*/
function hd_set_jobadder_deleted_jobs_to_draft( $job_id, $job_data ) {
/**
* You could of course do anything here.
* Set meta / custom fields etc.
*/
// update the post, changing the status.
wp_update_post(
[
'ID' => $job_id,
'post_status' => 'draft',
]
);
}
add_action( 'jobrelay_jobadder_delete_job', 'hd_set_jobadder_deleted_jobs_to_draft', 20, 2 );