• Resolved braehler

    (@braehler)


    Hey there,

    is it in some way possible to deactivate an active listing via the job dahsboard? Currently there are the options to delete, renew, mark filled etc. But deactivating the listing would be very helpfull for the customer. In case, when the job offer is already filled, there is no need for the listing to be online. So the customer can just deactivate the listing and then relist it the next time he needs it.

    Anyone a good solution for that?

    • This topic was modified 4 weeks ago by braehler.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Cara

    (@dcka)

    @braehler We don’t currently have a solution for that, but it may be possible with custom code.

    Thread Starter braehler

    (@braehler)

    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.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.