WordPress comments_open for specific user role or post type
-
comments_open is used for both post types, posts and products, the snippet below worked and allowed only (example) role users to comment
<!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> 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' ); } ); <!-- end snippet -->
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<!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> 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' ); } ); <!-- end snippet -->
But still, other roles cannot review products, only (example) role users can, how do I do this? Thank you in advance
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘WordPress comments_open for specific user role or post type’ is closed to new replies.