admin管理员组

文章数量:1025270

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>');

}

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>');

}

本文标签: pluginsHow to block access to certain WordPress pages using a snippet