Drupal 6 Block to Show the Super User How Many Comments are Waiting Approval

The post will show you how in Drupal 6 to display a block for the administrator showing how many comments by anonymous users are waiting approval and also provide a link to the approval list.

Pre-setup

This post assumes you have your permissions set so anonymous users can post comments (with approval), and you also have the core module PHP filter installed.

Please comment if you need any help with the Pre-setup

Creating the Block

Go into Admin => Blocks => Add block

Enter a description such as Comments Waiting

Enter the following code into the Block body

<?php
  global $user;
 
  if ($user->uid == 1) {
 
  $sql = 'SELECT COUNT(c.cid) FROM {comments} c WHERE c.status = 1';
 
  $num_comments = db_result(db_query($sql));
 
  return "<div align='center'>
          <p>There are <strong>$num_comments</strong> comment(s) waiting to be 
          <a href='?q=admin/content/comment/approval'>approved</a></p></div>";
  }
?>

Change the Input format to PHP

Under specific visibility settings select “Select the option Show if the following PHP code returns TRUE (PHP-mode, experts only). “ and enter the following code.

<?php
  global $user;
 
  if ($user->uid == 1) { 
 	return true;
  }
?>

 

 

Save the block

Remember to assign your new block to a region

6 thoughts on “Drupal 6 Block to Show the Super User How Many Comments are Waiting Approval”

  1. Thanks for the post, this is what I was needing.

     Is there a way to not show the block if there is not any comments waiting to be approved?

    Reply
    • Glad you found it useful.
       
      Glad you found it useful.
      If you change the specific visibility code to the below that should do the trick.
      The code is just doing a count of the number of comments waiting and then only displaying the block (returning true) if the user is admin and there are some comments
       

      <?php
      global $user;
       
      $sql = ‘SELECT COUNT(c.cid) FROM {comments} c WHERE c.status = 1’;
       
      $num_comments = db_result(db_query($sql));
       
       
      if ($user->uid == 1 && $num_comments > 0) {
      return true;
      }
      ?>
       
       

       
       

      Reply
      • I recently expanded my block to show both number of comments waiting to be approved and also to show the number of node entries waiting to be approved, here is the code if it of use to anyone.
         

        <?php
        global $user;
         
        if ($user->uid == 1) {
         
        $sql = ‘SELECT COUNT(c.cid) FROM {comments} c WHERE c.status = 1’;
         
        $num_comments = db_result(db_query($sql));
         
        $sql = ‘SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 0′;
         
        $num_nodes = db_result(db_query($sql));
         
        return "<div align=’center’> <p>There are <strong>$num_comments</strong> comment(s) waiting to be <a href=’?q=admin/content/comment/approval’>approved</a></p> <p>There are <strong>$num_nodes</strong> node(s) waiting to be <a href=’?q=admin/content/node’>approved</a></p> </div>";
         
         
        }
        ?>

         

        Reply
  2. Hi.

    The users posted comments on my site, but the comments can't be

    seen. I can see them in phpMyadmin. How to fix this?

    Thanks for response.

    Kate

    Reply

Leave a Reply to Sam Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.