Disable Comments - Version 1.11.0

Version Description

Download this release

Release Info

Developer Asif2BD
Plugin Icon 128x128 Disable Comments
Version 1.11.0
Comparing to
See all releases

Code changes from version 1.10.3 to 1.11.0

Files changed (3) hide show
  1. disable-comments.php +2 -2
  2. includes/tools-page.php +70 -10
  3. readme.txt +11 -5
disable-comments.php CHANGED
@@ -2,8 +2,8 @@
2
  /**
3
  * Plugin Name: Disable Comments
4
  * Plugin URI: https://wordpress.org/plugins/disable-comments/
5
- * Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type.
6
- * Version: 1.10.3
7
  * Author: WPDeveloper
8
  * Author URI: https://wpdeveloper.net
9
  * License: GPL-3.0+
2
  /**
3
  * Plugin Name: Disable Comments
4
  * Plugin URI: https://wordpress.org/plugins/disable-comments/
5
+ * Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. You could bulk delete comments using Tools.
6
+ * Version: 1.11.0
7
  * Author: WPDeveloper
8
  * Author URI: https://wpdeveloper.net
9
  * License: GPL-3.0+
includes/tools-page.php CHANGED
@@ -23,16 +23,31 @@ if ( $comments_count <= 0 ) {
23
  return;
24
  }
25
 
26
- $typeargs = array( 'public' => true );
 
27
  if ( $this->networkactive ) {
28
  $typeargs['_builtin'] = true; // stick to known types for network.
29
  }
30
- $types = get_post_types( $typeargs, 'objects' );
 
 
31
  foreach ( array_keys( $types ) as $type ) {
32
  if ( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) { // the type doesn't support comments anyway.
33
  unset( $types[ $type ] );
34
  }
35
  }
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
38
  check_admin_referer( 'delete-comments-admin' );
@@ -40,7 +55,7 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
40
  if ( $_POST['delete_mode'] == 'delete_everywhere' ) {
41
  if ( $wpdb->query( "TRUNCATE $wpdb->commentmeta" ) != false ) {
42
  if ( $wpdb->query( "TRUNCATE $wpdb->comments" ) != false ) {
43
- $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0" );
44
  $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
45
  $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );
46
  echo "<p style='color:green'><strong>" . __( 'All comments have been deleted.', 'disable-comments' ) . '</strong></p>';
@@ -50,7 +65,7 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
50
  } else {
51
  echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . '</strong></p>';
52
  }
53
- } else {
54
  $delete_post_types = empty( $_POST['delete_types'] ) ? array() : (array) $_POST['delete_types'];
55
  $delete_post_types = array_intersect( $delete_post_types, array_keys( $types ) );
56
 
@@ -78,6 +93,30 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
78
 
79
  echo "<h4 style='color:green'><strong>" . __( 'Comment Deletion Complete', 'disable-comments' ) . '</strong></h4>';
80
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
  $comments_count = $wpdb->get_var( "SELECT count(comment_id) from $wpdb->comments" );
@@ -107,8 +146,20 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
107
  <p class="indent" id="extradeletetypes"><?php _e( 'Only the built-in post types appear above. If you want to disable comments on other custom post types on the entire network, you can supply a comma-separated list of post types below (use the slug that identifies the post type).', 'disable-comments' ); ?>
108
  <br /><label><?php _e( 'Custom post types:', 'disable-comments' ); ?> <input type="text" name="delete_extra_post_types" size="30" value="<?php echo implode( ', ', (array) $this->options['extra_post_types'] ); ?>" /></label></p>
109
  <?php endif; ?>
110
- <p class="indent"><?php printf( __( '%s: Deleting comments will remove existing comment entries in the database and cannot be reverted without a database backup.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>' ); ?></p>
111
  </li>
 
 
 
 
 
 
 
 
 
 
 
 
112
  </ul>
113
 
114
  <?php wp_nonce_field( 'delete-comments-admin' ); ?>
@@ -119,11 +170,20 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
119
  <script>
120
  jQuery(document).ready(function($){
121
  function delete_comments_uihelper(){
122
- var toggle_bits = $("#listofdeletetypes, #extradeletetypes");
123
- if( $("#delete_everywhere").is(":checked") )
124
- toggle_bits.css("color", "#888").find(":input").attr("disabled", true );
125
- else
126
- toggle_bits.css("color", "#000").find(":input").attr("disabled", false );
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
  $("#delete-comments :input").change(function(){
23
  return;
24
  }
25
 
26
+ $publictypeargs = array( 'public' => true );
27
+ $privatetypeargs = array( 'public' => false );
28
  if ( $this->networkactive ) {
29
  $typeargs['_builtin'] = true; // stick to known types for network.
30
  }
31
+ $publictypes = get_post_types( $publictypeargs, 'objects' );
32
+ $privatetypes = get_post_types( $privatetypeargs, 'objects' );
33
+ $types = array_merge( $publictypes, $privatetypes );
34
  foreach ( array_keys( $types ) as $type ) {
35
  if ( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) { // the type doesn't support comments anyway.
36
  unset( $types[ $type ] );
37
  }
38
  }
39
+ $commenttypes = array();
40
+ $commenttypes_query = $wpdb->get_results( "SELECT DISTINCT comment_type FROM $wpdb->comments", ARRAY_A );
41
+ if ( ! empty( $commenttypes_query ) && is_array( $commenttypes_query ) ) {
42
+ foreach ( $commenttypes_query as $entry ) {
43
+ $value = $entry['comment_type'];
44
+ if ( '' === $value ) {
45
+ $commenttypes['default'] = __( 'Default (no type)', 'disable-comments' );
46
+ } else {
47
+ $commenttypes[$value] = ucwords( str_replace( '_', ' ', $value ) ) . ' (' . $value . ')';
48
+ }
49
+ }
50
+ }
51
 
52
  if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
53
  check_admin_referer( 'delete-comments-admin' );
55
  if ( $_POST['delete_mode'] == 'delete_everywhere' ) {
56
  if ( $wpdb->query( "TRUNCATE $wpdb->commentmeta" ) != false ) {
57
  if ( $wpdb->query( "TRUNCATE $wpdb->comments" ) != false ) {
58
+ $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0" );
59
  $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
60
  $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );
61
  echo "<p style='color:green'><strong>" . __( 'All comments have been deleted.', 'disable-comments' ) . '</strong></p>';
65
  } else {
66
  echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . '</strong></p>';
67
  }
68
+ } elseif ( $_POST['delete_mode'] == 'selected_delete_types' ) {
69
  $delete_post_types = empty( $_POST['delete_types'] ) ? array() : (array) $_POST['delete_types'];
70
  $delete_post_types = array_intersect( $delete_post_types, array_keys( $types ) );
71
 
93
 
94
  echo "<h4 style='color:green'><strong>" . __( 'Comment Deletion Complete', 'disable-comments' ) . '</strong></h4>';
95
  }
96
+ } elseif ( $_POST['delete_mode'] == 'selected_delete_comment_types' ) {
97
+ $delete_comment_types = empty( $_POST['delete_comment_types'] ) ? array() : (array) $_POST['delete_comment_types'];
98
+ $delete_comment_types = array_intersect( $delete_comment_types, array_keys( $commenttypes ) );
99
+
100
+ if ( ! empty( $delete_comment_types ) ) {
101
+ // Loop through comment_types and remove comments/meta and set posts comment_count to 0.
102
+ foreach ( $delete_comment_types as $delete_comment_type ) {
103
+ $wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID WHERE comments.comment_type = '$delete_comment_type'" );
104
+ $wpdb->query( "DELETE comments FROM $wpdb->comments comments WHERE comments.comment_type = '$delete_comment_type'" );
105
+
106
+ echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %s.', 'disable-comments' ), $commenttypes[$delete_comment_type] ) . '</strong></p>';
107
+ }
108
+
109
+ // Update comment_count on post_types
110
+ foreach( $types as $key => $value ) {
111
+ $comment_count = $wpdb->get_var( "SELECT COUNT(comments.comment_ID) FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$key'" );
112
+ $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment_count WHERE post_author != 0 AND post_type = '$key'" );
113
+ }
114
+
115
+ $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
116
+ $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );
117
+
118
+ echo "<h4 style='color:green'><strong>" . __( 'Comment Deletion Complete', 'disable-comments' ) . '</strong></h4>';
119
+ }
120
  }
121
 
122
  $comments_count = $wpdb->get_var( "SELECT count(comment_id) from $wpdb->comments" );
146
  <p class="indent" id="extradeletetypes"><?php _e( 'Only the built-in post types appear above. If you want to disable comments on other custom post types on the entire network, you can supply a comma-separated list of post types below (use the slug that identifies the post type).', 'disable-comments' ); ?>
147
  <br /><label><?php _e( 'Custom post types:', 'disable-comments' ); ?> <input type="text" name="delete_extra_post_types" size="30" value="<?php echo implode( ', ', (array) $this->options['extra_post_types'] ); ?>" /></label></p>
148
  <?php endif; ?>
149
+ <p class="indent"><?php printf( __( '%s: Deleting comments by post type will remove existing comment entries for the selected post type(s) in the database and cannot be reverted without a database backup.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>' ); ?></p>
150
  </li>
151
+ <?php if ( ! empty( $commenttypes ) ) : ?>
152
+ <li><label for="selected_delete_comment_types"><input type="radio" id="selected_delete_comment_types" name="delete_mode" value="selected_delete_comment_types" /> <strong><?php _e( 'For certain comment types', 'disable-comments' ); ?></strong>:</label>
153
+ <p></p>
154
+ <ul class="indent" id="listofdeletecommenttypes">
155
+ <?php
156
+ foreach ( $commenttypes as $k => $v ) {
157
+ echo "<li><label for='comment-type-$k'><input type='checkbox' name='delete_comment_types[]' value='$k' id='comment-type-$k'> {$v}</label></li>";}
158
+ ?>
159
+ </ul>
160
+ <p class="indent"><?php printf( __( '%s: Deleting comments by comment type will remove existing comment entries of the selected comment type(s) in the database and cannot be reverted without a database backup.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>' ); ?></p>
161
+ </li>
162
+ <?php endif; ?>
163
  </ul>
164
 
165
  <?php wp_nonce_field( 'delete-comments-admin' ); ?>
170
  <script>
171
  jQuery(document).ready(function($){
172
  function delete_comments_uihelper(){
173
+ var toggle_pt_bits = $("#listofdeletetypes, #extradeletetypes");
174
+ var toggle_ct_bits = $("#listofdeletecommenttypes");
175
+ if( $("#delete_everywhere").is(":checked") ) {
176
+ toggle_pt_bits.css("color", "#888").find(":input").attr("disabled", true );
177
+ toggle_ct_bits.css("color", "#888").find(":input").attr("disabled", true );
178
+ } else {
179
+ if( $("#selected_delete_types").is(":checked") ) {
180
+ toggle_pt_bits.css("color", "#000").find(":input").attr("disabled", false );
181
+ toggle_ct_bits.css("color", "#888").find(":input").attr("disabled", true );
182
+ } else {
183
+ toggle_ct_bits.css("color", "#000").find(":input").attr("disabled", false );
184
+ toggle_pt_bits.css("color", "#888").find(":input").attr("disabled", true );
185
+ }
186
+ }
187
  }
188
 
189
  $("#delete-comments :input").change(function(){
readme.txt CHANGED
@@ -1,15 +1,15 @@
1
  === Disable Comments ===
2
  Contributors: Asif2BD, priyomukul, wpdevteam, re_enter_rupok, solarissmoke, garrett-eclipse
3
  Donate link: https://wpdeveloper.net/
4
- Tags: comments, disable, global, disable comments, delete comments, stop spam, bulk comment delete, comment management
5
  Requires at least: 5.0
6
  Tested up to: 5.5
7
  Requires PHP: 5.4
8
- Stable tag: 1.10.3
9
  License: GPL-3.0-or-later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
 
12
- Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. Multisite friendly. Provides tool to delete all comments or according to post type.
13
 
14
  == Description ==
15
 
@@ -37,6 +37,7 @@ The plugin provides the option to **completely disable the commenting feature in
37
  * All comment RSS/Atom feeds are disabled (and requests for these will be redirected to the parent post);
38
  * The X-Pingback HTTP header is removed from all pages;
39
  * Outgoing pingbacks are disabled.
 
40
 
41
  **Please delete any existing comments on your site before applying this setting, otherwise (depending on your theme) those comments may still be displayed to visitors. You can use the Delete Comments tool to delete any existing comments on your site.**
42
 
@@ -51,7 +52,7 @@ Some of the plugin's behaviour can be modified by site administrators and plugin
51
  These definitions can be made either in your main `wp-config.php` or in your theme's `functions.php` file.
52
 
53
 
54
- ### This plugin is maintained by the [WPDeveloper](https://wpdeveloper.net/).
55
 
56
 
57
  ### 💙 LOVED Disable Comments?
@@ -142,6 +143,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
142
  and this project adheres to [Semantic Versioning](http://semver.org/).
143
  This will be maiintained from August 19, 2020 - @asif2bd
144
 
 
 
 
 
 
145
  = [1.10.3] - 2020-07-29 =
146
  * Minor fix - changelog backported.
147
 
@@ -279,4 +285,4 @@ This will be maiintained from August 19, 2020 - @asif2bd
279
 
280
  == Upgrade Notice ==
281
 
282
- Minor Update: Bug Fix
1
  === Disable Comments ===
2
  Contributors: Asif2BD, priyomukul, wpdevteam, re_enter_rupok, solarissmoke, garrett-eclipse
3
  Donate link: https://wpdeveloper.net/
4
+ Tags: comments, disable, disable comments, delete comments, stop spam, bulk comment delete, comment management, global, stop comment
5
  Requires at least: 5.0
6
  Tested up to: 5.5
7
  Requires PHP: 5.4
8
+ Stable tag: 1.11.0
9
  License: GPL-3.0-or-later
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
11
 
12
+ Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. Multisite friendly. Provides tool to delete comments according to post type.
13
 
14
  == Description ==
15
 
37
  * All comment RSS/Atom feeds are disabled (and requests for these will be redirected to the parent post);
38
  * The X-Pingback HTTP header is removed from all pages;
39
  * Outgoing pingbacks are disabled.
40
+ * **[New]** Delete comments by type.
41
 
42
  **Please delete any existing comments on your site before applying this setting, otherwise (depending on your theme) those comments may still be displayed to visitors. You can use the Delete Comments tool to delete any existing comments on your site.**
43
 
52
  These definitions can be made either in your main `wp-config.php` or in your theme's `functions.php` file.
53
 
54
 
55
+ ### This plugin is now maintained by the Team [WPDeveloper](https://wpdeveloper.net/).
56
 
57
 
58
  ### 💙 LOVED Disable Comments?
143
  and this project adheres to [Semantic Versioning](http://semver.org/).
144
  This will be maiintained from August 19, 2020 - @asif2bd
145
 
146
+ = [1.11.0] - 2020-08-22 =
147
+ * Introducing Delete Comment by Type - Contribution by garretthyder
148
+ * PHP 7.4 Tested
149
+ * WordPress 5.5 Compatible Tested
150
+
151
  = [1.10.3] - 2020-07-29 =
152
  * Minor fix - changelog backported.
153
 
285
 
286
  == Upgrade Notice ==
287
 
288
+ Minor Update: Tools update