Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULENAME_form_alter(&$form, &$form_state, $form_id) {
- if ( $form_id == 'comment_form') {
- global $user;
- if (!user_role('Premium'){
- // Form alter here to unset comment form and show "only premium members can comment"
- unset($form['author']);
- unset($form['subject']);
- unset($form['comment_body']);
- unset($form['actions']['submit'] );
- unset($form['actions']['preview'] );
- print "Only Premium members can comment";
- }
- }
- };
- function MODULE_form_alter(&$form, &$form_state, $form_id) {
- global $user;
- $node = $form['#node'];
- // a custom function to do your logic
- if (comment_should_be_restricted($user, $node)) {
- // unset form elements, you can fetch them easily by print_r(array_keys($form));
- unset($form['comment_body'], $form['actions'], $form['author'], $form['subject']); // etc.
- // add a optional message for user.
- $form['no_access'] = array(
- '#markup' => t('You have no access to comment on this content.')
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement