最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - How to block access to certain WordPress pages using a snippet

matteradmin7PV0评论

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?

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?

Share Improve this question edited Apr 6, 2019 at 16:54 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Apr 6, 2019 at 16:11 Greg.SAGreg.SA 1
Add a comment  | 

1 Answer 1

Reset to default 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>');

}
Post a comment

comment list (0)

  1. No comments so far