admin管理员组文章数量:1434146
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 11 Answer
Reset to default 0Try 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
版权声明:本文标题:plugins - How to block access to certain WordPress pages using a snippet 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745620032a2666628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论