admin管理员组文章数量:1336631
comments_open is used for both post types, posts and products, the snippet below worked and allowed only (example) role users to comment
enter code here
add_action( 'init', function(){
$u = wp_get_current_user();
if( $u->exists() && in_array( 'example', (array) $u->roles, true ) ) return; add_filter( 'comments_open', '__return_false' );} );
But it also made the product reviews appear only for (example) role users and other roles cannot review products. I have tried modifying the snippet to remove post_type =='product' from the rule
enter code here add_action( 'init', function() {$u = wp_get_current_user();
if( $u->exists() && in_array( 'example', (array) $u->roles, true ) OR $post->post_type == 'product' ){return;} add_filter( 'comments_open', '__return_false' );} );
But still, other roles cannot review products, only (example) role users can, how do I do this? Thank you in advance
本文标签: commentsWordpress commentsopen for specific user role or post type
版权声明:本文标题:comments - Wordpress comments_open for specific user role or post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742407912a2469198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论