Plugin Directory

Changeset 1487628


Ignore:
Timestamp:
09/01/2016 03:07:17 AM (10 years ago)
Author:
guruitengineer
Message:

1.2 Released

Location:
approved-comments-only
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • approved-comments-only/trunk/approved-comments-only.php

    r1484409 r1487628  
    11<?php
    22/*
    3   Plugin Name: Approved Comments Only
    4   Plugin URI: https://wordpress.org/plugins/approved-comments-only/
    5   Description: With this plugin you can restrict your users to view the unapproved comments in dashboard of multi-user site. Even you can restrict administrator and editor also. So, only the approved comments will be visible in the dashboard.
    6   Version: 1.0.1
    7   Author: Gurmeet Singh
    8   Author URI: http://guruitengineer.in/
    9   License: GPLv2+
     3Plugin Name: Approved Comments Only
     4Plugin URI: https://wordpress.org/plugins/approved-comments-only/
     5Description: With this plugin you can restrict your users to view the unapproved comments in dashboard of multi-user site. Even you can restrict administrator and editor also. So, only the approved comments will be visible in the dashboard.
     6Version: 1.2
     7Author: Gurmeet Singh
     8Author URI: http://guruitengineer.in/
     9License: GPLv2+
    1010*/
    1111if (!defined('ABSPATH')) die();
     
    1313class Approved_Comments_Only{
    1414
    15     function __construct() {
    16 
    17         add_action('admin_menu', array( $this, 'aco_add_menu' ));
    18         add_action('plugins_loaded', array( $this, 'get_user_info' ));
    19         register_activation_hook( __FILE__, array( $this, 'aco_install' ) );
    20         register_deactivation_hook( __FILE__, array( $this, 'aco_uninstall' ) );
    21 
    22     }
    23 
    24     function aco_hide_comment_status_links()
     15  function __construct() {
     16    add_action('admin_menu', array( $this, 'aco_add_menu' ));
     17    add_action('plugins_loaded', array( $this, 'aco_get_user_info' ));
     18    register_activation_hook( __FILE__, array( $this, 'aco_install' ) );
     19    register_deactivation_hook( __FILE__, array( $this, 'aco_uninstall' ) );
     20  }
     21
     22  /*
     23  * Actions perform at loading of admin menu
     24  */
     25  function aco_add_menu() {
     26
     27    add_menu_page( 'Approved Comments Only', 'Approved Comments Only', 'manage_options', 'aco_setting_page',
     28      array(__CLASS__,'aco_setting_page'));
     29    add_action( 'admin_init', array($this,'aco_register_settings' ));
     30  }
     31
     32  /*
     33  * Actions perform on loading of menu pages
     34  */
     35  function aco_setting_page()
     36  {
     37    require_once("includes/aco-custom-settings.php");
     38  }
     39
     40  /*
     41  * Actions to get the user information and perform task as per the user's role.
     42  */
     43  public function aco_get_user_info()
     44  {
     45    $user = wp_get_current_user();
     46    $aco_user_level=(array)get_option('aco_user_level');
     47
     48    if(in_array($user->roles[0],$aco_user_level))
    2549    {
    26       return $null;
    27     }
    28 
    29     function aco_filtered_comment($comments)
     50      add_filter('the_comments', array( $this, 'aco_filtered_comments' ));
     51      add_filter('comments_per_page', array( $this, 'aco_hide_default_pagination'));
     52      add_filter('manage_comments_nav', array( $this, 'aco_add_custom_pagination' ));
     53      add_filter( 'comment_status_links', array($this,'aco_hide_comment_status_links') );
     54      wp_enqueue_style( 'approved-comments-only', plugins_url().'/approved-comments-only/assets/css/approved-comments-only.css');
     55    }
     56  }
     57
     58  /*
     59  * Actions to get filter comments.
     60  */
     61  function aco_filtered_comments($comments)
     62  {
     63   
     64    $published_comment=array();
     65    $current_user_id=(int)get_current_user_id(); 
     66    $enable=get_option('aco_user_own_comments');
     67 
     68    if(is_admin())
    3069    {
    31       $published_comment=array();
    3270      foreach ($comments as $comment) {
     71      switch ($enable) {
     72        case '1':
     73        if($comment->comment_approved=='1' && $comment->user_id==$current_user_id)
     74          array_push($published_comment,$comment);
     75        break; 
     76        default:
    3377        if($comment->comment_approved=='1')
    3478          array_push($published_comment,$comment);
    35       }
    36       return $published_comment;
    37     }
     79        break;
     80        }     
     81      }
     82    }
     83    else
     84    {
     85      $published_comment=$comments;
     86    }
     87    return $published_comment;
     88  }
     89  /*
     90  * Actions to hide the default pagination.
     91  */
     92  function aco_hide_default_pagination($comments_per_page)
     93  {
     94    return $comments_per_page;
     95  }
     96  /*
     97  * Actions to add custom pagination.
     98  */
     99  function aco_add_custom_pagination($view)
     100  {
     101    $published_comment_count=count(get_comments());
     102
     103    // if ( empty( $this->_pagination_args ) ) {
     104    //   return;
     105    // }
    38106   
    39 
    40     public function get_user_info()
    41     {
    42       $user = wp_get_current_user();
    43      
    44       //$aco_user_level=array();
    45       $aco_user_level=(array)get_option('aco_user_level');
    46 
    47       if(in_array($user->roles[0],$aco_user_level))
    48       {
    49         add_filter('the_comments', array( $this, 'aco_filtered_comment' ));
    50         add_filter( 'comment_status_links', array($this,'aco_hide_comment_status_links') );
    51       }
    52     }
    53     /*
    54     * Actions perform at loading of admin menu
    55     */
    56     function aco_add_menu() {
    57 
    58         add_menu_page( 'Approved Comments Only', 'Approved Comments Only', 'manage_options', 'aco_setting_page',
    59           array(__CLASS__,'aco_setting_page'));
    60         add_action( 'admin_init', array($this,'aco_register_settings' ));
    61     }
    62     /**
    63      * Register the settings
    64      */
    65     function aco_register_settings() {
    66          register_setting(
    67               'aco_options',  // settings section
    68               'aco_user_level' // setting name
    69          );
    70     }
     107    $total_items = $published_comment_count;
     108    global $wp_list_table;
    71109   
    72     /*
    73      * Actions perform on loading of menu pages
    74      */
    75     function aco_setting_page()
    76     {
    77           require_once("includes/aco-custom-settings.php");
    78     }
    79    
    80 
    81     /*
    82      * Actions perform on activation of plugin
    83      */
    84     function aco_install() {
    85 
    86 
    87 
    88     }
    89 
    90     /*
    91      * Actions perform on de-activation of plugin
    92      */
    93     function aco_uninstall() {
    94 
    95 
    96 
    97     }
     110    $comments_per_page=(int)get_user_option('edit_comments_per_page');
     111    if(empty($comments_per_page))
     112      $comments_per_page=20;
     113    $total_pages = ceil($total_items/$comments_per_page);
     114
     115    $infinite_scroll = false;
     116    if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
     117      $infinite_scroll = $this->_pagination_args['infinite_scroll'];
     118    }
     119
     120    if ( 'top' === $which && $total_pages > 1 ) {
     121      $this->screen->render_screen_reader_content( 'heading_pagination' );
     122    }
     123
     124     $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
     125
     126     $current = $wp_list_table->get_pagenum();
     127     $removable_query_args = wp_removable_query_args();
     128
     129     $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
     130
     131     $current_url = remove_query_arg( $removable_query_args, $current_url );
     132     $page_links = array();
     133
     134     $total_pages_before = '<span class="paging-input">';
     135     $total_pages_after  = '</span></span>';
     136
     137     $disable_first = $disable_last = $disable_prev = $disable_next = false;
     138
     139    if ( $current == 1 ) {
     140      $disable_first = true;
     141      $disable_prev = true;
     142    }
     143    if ( $current == 2 ) {
     144      $disable_first = true;
     145    }
     146    if ( $current == $total_pages ) {
     147      $disable_last = true;
     148      $disable_next = true;
     149    }
     150    if ( $current == $total_pages - 1 ) {
     151      $disable_last = true;
     152    }
     153
     154    if ( $disable_first ) {
     155      $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
     156    } else {
     157      $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     158        esc_url( remove_query_arg( 'paged', $current_url ) ),
     159        __( 'First page' ),
     160        '&laquo;'
     161      );
     162    }
     163
     164    if ( $disable_prev ) {
     165      $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
     166    } else {
     167      $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     168        esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
     169        __( 'Previous page' ),
     170        '&lsaquo;'
     171      );
     172    }
     173
     174    if ( 'bottom' === $which ) {
     175      $html_current_page  = $current;
     176      $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
     177    } else {
     178      $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
     179        '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
     180        $current,
     181        strlen( $total_pages )
     182      );
     183    }
     184    $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
     185    $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
     186
     187    if ( $disable_next ) {
     188      $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
     189    } else {
     190      $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     191        esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
     192        __( 'Next page' ),
     193        '&rsaquo;'
     194      );
     195    }
     196
     197    if ( $disable_last ) {
     198      $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
     199    } else {
     200      $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     201        esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
     202        __( 'Last page' ),
     203        '&raquo;'
     204      );
     205    }
     206
     207    $pagination_links_class = 'pagination-links';
     208    if ( ! empty( $infinite_scroll ) ) {
     209      $pagination_links_class = ' hide-if-js';
     210    }
     211    $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
     212
     213    if ( $total_pages ) {
     214      $page_class = $total_pages < 2 ? ' one-page' : '';
     215    } else {
     216      $page_class = ' no-pages';
     217    }
     218    $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
     219
     220    echo $this->_pagination;
     221  }
     222  /*
     223  * Actions to hide comment status links All/Pending/Approved/Spam/Trash
     224  */
     225  function aco_hide_comment_status_links()
     226  {
     227    return $null;
     228  }
     229
     230  /*
     231  * Register the settings
     232  */
     233  function aco_register_settings() {
     234      register_setting(
     235      'aco_options',  // settings section
     236      'aco_user_level' // setting name
     237    );
     238      register_setting(
     239      'aco_options',  // settings section
     240      'aco_user_own_comments' // setting name
     241    );
     242  }
     243
     244  /*
     245  * Actions perform on activation of plugin
     246  */
     247  function aco_install() {
     248
     249
     250
     251  }
     252 
     253  /*
     254  * Actions perform on de-activation of plugin
     255  */
     256  function aco_uninstall() {
     257
     258
     259
     260  }
    98261}
    99262new Approved_Comments_Only();
    100 
    101263?>
  • approved-comments-only/trunk/includes/aco-custom-settings.php

    r1484400 r1487628  
    11<?php if( isset($_GET['settings-updated']) ) { ?>
    2     <div id="message" class="updated">
    3         <p><strong><?php _e('Settings Saved.') ?></strong></p>
    4     </div>
     2<div id="message" class="updated">
     3  <p><strong><?php _e('Settings Saved.') ?></strong></p>
     4</div>
    55<?php } ?>
    66
    77<h1>Approved Comments Only Settings</h1>
    8         <form method="post" action="../wp-admin/options.php">
    9           <?php settings_fields( 'aco_options' ); ?>
    10           <?php do_settings_sections( 'aco_options' ); ?>
    11           <table class="form-table">
    12             <tr valign="top">
    13             <th scope="row">Select User Level:</th>
    14             <td><!-- <input type="text" name="aco_user_level" value=""/> -->
    15               <?php $aco_user_level=get_option( 'aco_user_level' ); ?>
    16               <select name="aco_user_level[]" multiple>
    17                 <option value="subscriber" <?php if(in_array("subscriber", (array)$aco_user_level)) echo 'selected'?> >Subscriber</option>
    18                 <option value="contributor" <?php if(in_array("contributor", (array)$aco_user_level)) echo 'selected'?> >Contributor</option>
    19                 <option value="author" <?php if(in_array("author", (array)$aco_user_level)) echo 'selected'?> >Author</option>
    20                 <option value="editor" <?php if(in_array("editor", (array)$aco_user_level)) echo 'selected'?> >Editor</option>
    21                 <option value="administrator" <?php if(in_array("administrator", (array)$aco_user_level)) echo 'selected'?> >Administrator</option>
    22               </select>
    23             </td>
    24             </tr>
    25           </table>
    26           <?php
    27           print('Please use CTRL to select multiple values');
    28           submit_button(); ?>
    29         </form>
     8<form method="post" action="../wp-admin/options.php">
     9  <?php settings_fields( 'aco_options' ); ?>
     10  <?php do_settings_sections( 'aco_options' ); ?>
     11  <table class="form-table">
     12    <tr valign="top">
     13      <th scope="row">Select User Level:</th>
     14      <td><!-- <input type="text" name="aco_user_level" value=""/> -->
     15        <?php $aco_user_level=get_option( 'aco_user_level' ); ?>
     16        <select name="aco_user_level[]" multiple>
     17          <option value="subscriber" <?php if(in_array("subscriber", (array)$aco_user_level)) echo 'selected'?> >Subscriber</option>
     18          <option value="contributor" <?php if(in_array("contributor", (array)$aco_user_level)) echo 'selected'?> >Contributor</option>
     19          <option value="author" <?php if(in_array("author", (array)$aco_user_level)) echo 'selected'?> >Author</option>
     20          <option value="editor" <?php if(in_array("editor", (array)$aco_user_level)) echo 'selected'?> >Editor</option>
     21          <option value="administrator" <?php if(in_array("administrator", (array)$aco_user_level)) echo 'selected'?> >Administrator</option>
     22        </select>
     23      </td>
     24      <?php print('Please use CTRL to select multiple values');?>
     25    </tr>
     26    <tr>
     27      <th scope="row">Show user's own comments only in Dashboard.</th>
     28      <td>
     29        <?php $aco_user_own_comments=get_option( 'aco_user_own_comments'); ?>
     30        <input type="checkbox" name="aco_user_own_comments" value="1"
     31        <?php
     32          if($aco_user_own_comments=='1') echo 'checked'
     33        ?>
     34        >
     35      </td>
     36    </tr>
     37  </table>
     38  <?php
     39  submit_button(); ?>
     40</form>
  • approved-comments-only/trunk/readme.txt

    r1484409 r1487628  
    22Contributors: Gurmeet Singh
    33Donate link: https://www.paypal.me/guruitengineer
    4 Tags: comments,approved,control,hide
     4Tags: comments,approved,control,hide,approved comments, moderated comments, restrict user,own comments
    55Tested up to: 4.6
    6 Stable tag: 1.0.1
     6Stable tag: 1.2
     7License: GPLv2
     8License URI: http://www.gnu.org/licenses/gpl-2.0.html
    79
    810Restrict user to view the unapproved comments in dashboard.
     
    4042== Screenshots ==
    4143
    42 1. The meta box in nav menu admin page
     441. Approved Comments Only Admin menu added.
     452. Approved Comments Only Settings page.
    4346
    4447== Changelog ==
    4548
     49= 1.2 =
     50* 1 Sept 2016
     51* A Selection to show only user's comments in dashboard has been added.
     52* Comments pagination bug fixed.
     53
    4654= 1.0.1 =
    4755* 28 Aug 2016
    48 * Second release
     56* Minor Bug fixed
    4957
    5058= 1.0 =
     
    5563== Upgrade Notice ==
    5664
     65= V1.2 =
     661. A Selection to show only user's comments in dashboard has been added.
     672. Comments pagination bug fixed.
     68
    5769= V1.0.1 =
    58701. Hidden Comment table filter All/Pending/Approved/Trash/Spam removed.
Note: See TracChangeset for help on using the changeset viewer.