If someone is interested, here is a code for the functions.php that adds a button and functionality to the job dashboard to deactivate the job
<?php
/**
* Function to add deactivate Button toJob Dashboard
* Works with WP Job Manager 2.4.0 and WC Paid Listings 3.0.3
*/
// add Button
add_action('job_manager_my_job_actions', 'custom_add_deactivate_button', 10, 2);
function custom_add_deactivate_button($actions, $job) {
if ($job->post_status === 'publish') {
// Basie-URL Dashboards
$dashboard_url = get_permalink(get_option('job_manager_job_dashboard_page_id'));
// URLwith correct parameters
$actions['deactivate'] = array(
'label' => __('Deactivate', 'wp-job-manager'),
'url' => add_query_arg(array(
'action' => 'deactivate',
'job_id' => $job->ID
), $dashboard_url)
);
}
return $actions;
}
// prepare deactivate
add_action('wp', 'custom_process_job_deactivation');
function custom_process_job_deactivation() {
if (!isset($_GET['action']) || $_GET['action'] !== 'deactivate') {
return;
}
if (empty($_GET['job_id'])) {
return;
}
$job_id = absint($_GET['job_id']);
// check permission
$job = get_post($job_id);
if (!$job || $job->post_author != get_current_user_id()) {
wp_die(__('You do not have the permission to deactivate', 'wp-job-manager'));
}
// update Job Status
wp_update_post(array(
'ID' => $job_id,
'post_status' => 'expired'
));
// WC Paid Listings
if (class_exists('WC_Paid_Listings')) {
delete_post_meta($job_id, '_package_id');
delete_post_meta($job_id, '_package_subscription_id');
delete_post_meta($job_id, '_featured');
}
// clear Cache
clean_post_cache($job_id);
// redirect to job dashboard
wp_redirect(add_query_arg('msg', 'deactivated', get_permalink(get_option('job_manager_job_dashboard_page_id'))));
exit;
}
// success message
add_action('job_manager_job_dashboard_before', 'custom_show_deactivation_notice');
function custom_show_deactivation_notice() {
if (isset($_GET['msg']) && $_GET['msg'] === 'deactivated') {
echo '<div class="job-manager-message">' .
esc_html__('Success.', 'wp-job-manager') .
'</div>';
}
}
-
This reply was modified 8 hours, 37 minutes ago by braehler.