Created
March 16, 2018 15:13
-
-
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
This file contains hidden or 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 | |
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 ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm so sorry… but I can't find the time right now to check this out again.
Good luck!