Skip to content

Instantly share code, notes, and snippets.

@jonasvogel
Created March 16, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonasvogel/fb9a10b77c75df0da82645cf6ea20975 to your computer and use it in GitHub Desktop.
Save jonasvogel/fb9a10b77c75df0da82645cf6ea20975 to your computer and use it in GitHub Desktop.
WP Job Manager: Test new filter for job dashboard actions which allows success message
<?php
namespace JobManager;
add_filter( 'job_manager_my_job_actions', __NAMESPACE__ . '\\add_expire_action', 10, 2 );
function add_expire_action( $actions, $job_id ) {
if ( ! function_exists( __NAMESPACE__ . '\\handle_expire_action' ) ) {
return $actions;
}
$job = get_post( $job_id );
if ( $job->post_status === 'publish' ) {
$actions['expire'] = array(
'label' => __( 'Expire', 'wp-job-manager' ),
'nonce' => true
);
}
return $actions;
}
add_filter( 'job_manager_job_dashboard_do_action', __NAMESPACE__ . '\\handle_expire_action', 10, 3 );
function handle_expire_action( $success_message, $action, $job_id ) {
if ( $action !== 'expire' ) {
return $success_message;
}
$job = get_post( $job_id );
// Check status
if ( $job->post_status === 'expired' ) {
throw new \Exception( __( 'This job is already expired.', 'wp-job-manager' ) );
}
// Update
$job->post_status = 'expired';
$updated = wp_update_post( $job );
if ( ! $updated || is_wp_error( $updated ) ) {
throw new \Exception( __( 'Job could not be changed.', 'wp-job-manager' ) );
}
// Message
return sprintf( __( '%s has expired', 'jobwrk' ), wpjm_get_the_job_title( $job ) );
}
@kibus90
Copy link

kibus90 commented May 30, 2020

Hello,

I know that it was posted 2 years ago.... and unfortunately it does not work with the current version of WPJM.

Would you like to help me with update this code for me?

I tried to make it workable but unfortunately it is not working... what else... it crashes my website.

Thank you in advance!

@jonasvogel
Copy link
Author

I'm so sorry… but I can't find the time right now to check this out again.
Good luck!

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