Only allowing certain users to post Job

Hi,

Is it possible to only show the add job button to users when they are logged in and have a certain role?

Thanks

  • Hoang Ngo

    Hi @Michelle,

    I hope you are well today.

    Please add this code to your theme functions.php or use mu-plugins

    add_filter('ig_view_file', 'custom_add_job_form_view', 10, 2);
    function custom_add_job_form_view($view_path, $view)
    {
        if ($view == 'job-form/main') {
            $roles = array('role_can_post_here');
            global $current_user;
            $can_add_job = false;
            foreach ($current_user->roles as $role) {
                if (in_array($role, $roles)) {
                    $can_add_job = true;
                }
            }
            if ($can_add_job == false) {
                $view_path = get_stylesheet_directory() . '/not_the_role.php';
            }
        }
        return $view_path;
    }

    In the code above, you will notice this variable
    $roles = array('role_can_post_here');
    This is where you can define the role, which can add new job. Example, here is the variable allow subscriber & editor can add new job
    $roles = array('subscriber','editor');
    And next, please download the attachment, and copy it to your current active theme.
    In the file you will see a very simple code like this
    <?php _e("Your message text here",'domain') ?>
    Please update the message text to your need.

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.