0

I would like to block access to certain users on my WordPress site. I want only users with the "employers" user role to be allowed access to certain pages, so I tried creating the following snippet, but it's not working.

 add_action( 'job_posting_access', function() {
if ( current_user_can( 'employer' ) )
     else (class="job-manager-error"(Sorry, you do not have permission to post jobs.)
           }

Could someone out there please assist with my problem above, not sure what I missed?

0

Try this, assuming that job_posting_access is a valid hook defines by some plugin:

add_action( 'job_posting_access', function() {

    // $pages is  Page ID, title, slug, or array of these for which access is restricted

    $pages = ( array ('page 1', 42, 'page-2')  );

    if ( ! current_user_can( 'employer' ) && is_page( $pages ) ) 

          wp_die('<div class="job-manager-error">Sorry, you do not have permission to post jobs.</div>');

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.