最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

comments - Wordpress comments_open for specific user role or post type

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论