Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  2. if ( $form_id == 'comment_form') {
  3. global $user;
  4. if (!user_role('Premium'){
  5. // Form alter here to unset comment form and show "only premium members can comment"
  6. unset($form['author']);
  7. unset($form['subject']);
  8. unset($form['comment_body']);
  9. unset($form['actions']['submit'] );
  10. unset($form['actions']['preview'] );
  11. print "Only Premium members can comment";
  12. }
  13. }
  14. };
  15.  
  16. function MODULE_form_alter(&$form, &$form_state, $form_id) {
  17. global $user;
  18. $node = $form['#node'];
  19. // a custom function to do your logic
  20. if (comment_should_be_restricted($user, $node)) {
  21. // unset form elements, you can fetch them easily by print_r(array_keys($form));
  22. unset($form['comment_body'], $form['actions'], $form['author'], $form['subject']); // etc.
  23. // add a optional message for user.
  24. $form['no_access'] = array(
  25. '#markup' => t('You have no access to comment on this content.')
  26. );
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement