Version Description
- Fix compatibility with WordPress 5.0 and above.
- Remove deprecated "persistent mode" feature.
Download this release
Release Info
Developer | solarissmoke |
Plugin | Disable Comments |
Version | 1.9.0 |
Comparing to | |
See all releases |
Code changes from version 1.8.0 to 1.9.0
- disable-comments.php +2 -50
- includes/settings-page.php +0 -26
- includes/tools-page.php +4 -1
- readme.txt +6 -2
disable-comments.php
CHANGED
@@ -3,7 +3,7 @@
|
|
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.
|
7 |
Author: Samir Shah
|
8 |
Author URI: http://www.rayofsolaris.net/
|
9 |
License: GPL2
|
@@ -76,7 +76,7 @@ class Disable_Comments {
|
|
76 |
unset( $this->options[$v] );
|
77 |
}
|
78 |
|
79 |
-
foreach( array( 'remove_everywhere', '
|
80 |
if( !isset( $this->options[$v] ) ) {
|
81 |
$this->options[$v] = false;
|
82 |
}
|
@@ -181,12 +181,6 @@ class Disable_Comments {
|
|
181 |
add_action( 'admin_notices', array( $this, 'discussion_notice' ) );
|
182 |
add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 );
|
183 |
|
184 |
-
// if only certain types are disabled, remember the original post status
|
185 |
-
if( !( $this->persistent_mode_allowed() && $this->options['permanent'] ) && !$this->options['remove_everywhere'] ) {
|
186 |
-
add_action( 'edit_form_advanced', array( $this, 'edit_form_inputs' ) );
|
187 |
-
add_action( 'edit_page_form', array( $this, 'edit_form_inputs' ) );
|
188 |
-
}
|
189 |
-
|
190 |
if( $this->options['remove_everywhere'] ) {
|
191 |
add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible
|
192 |
add_action( 'admin_print_styles-index.php', array( $this, 'admin_css' ) );
|
@@ -273,14 +267,6 @@ class Disable_Comments {
|
|
273 |
}
|
274 |
}
|
275 |
|
276 |
-
public function edit_form_inputs() {
|
277 |
-
global $post;
|
278 |
-
// Without a dicussion meta box, comment_status will be set to closed on new/updated posts
|
279 |
-
if( in_array( $post->post_type, $this->modified_types ) ) {
|
280 |
-
echo '<input type="hidden" name="comment_status" value="' . $post->comment_status . '" /><input type="hidden" name="ping_status" value="' . $post->ping_status . '" />';
|
281 |
-
}
|
282 |
-
}
|
283 |
-
|
284 |
public function discussion_notice() {
|
285 |
$disabled_post_types = $this->get_disabled_post_types();
|
286 |
if( get_current_screen()->id == 'options-discussion' && !empty( $disabled_post_types ) ) {
|
@@ -416,40 +402,6 @@ class Disable_Comments {
|
|
416 |
include dirname( __FILE__ ) . '/includes/tools-page.php';
|
417 |
}
|
418 |
|
419 |
-
private function enter_permanent_mode() {
|
420 |
-
$types = $this->get_disabled_post_types();
|
421 |
-
if( empty( $types ) )
|
422 |
-
return;
|
423 |
-
|
424 |
-
global $wpdb;
|
425 |
-
|
426 |
-
if( $this->networkactive ) {
|
427 |
-
// NOTE: this can be slow on large networks!
|
428 |
-
$blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND deleted = '0'", $wpdb->siteid ) );
|
429 |
-
|
430 |
-
foreach ( $blogs as $id ) {
|
431 |
-
switch_to_blog( $id );
|
432 |
-
$this->close_comments_in_db( $types );
|
433 |
-
restore_current_blog();
|
434 |
-
}
|
435 |
-
}
|
436 |
-
else {
|
437 |
-
$this->close_comments_in_db( $types );
|
438 |
-
}
|
439 |
-
}
|
440 |
-
|
441 |
-
private function close_comments_in_db( $types ){
|
442 |
-
global $wpdb;
|
443 |
-
$bits = implode( ', ', array_pad( array(), count( $types ), '%s' ) );
|
444 |
-
$wpdb->query( $wpdb->prepare( "UPDATE `$wpdb->posts` SET `comment_status` = 'closed', ping_status = 'closed' WHERE `post_type` IN ( $bits )", $types ) );
|
445 |
-
}
|
446 |
-
|
447 |
-
private function persistent_mode_allowed() {
|
448 |
-
if( defined( 'DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE' ) && DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE == false ) {
|
449 |
-
return false;
|
450 |
-
}
|
451 |
-
}
|
452 |
-
|
453 |
private function discussion_settings_allowed() {
|
454 |
if( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) {
|
455 |
return true;
|
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.9.0
|
7 |
Author: Samir Shah
|
8 |
Author URI: http://www.rayofsolaris.net/
|
9 |
License: GPL2
|
76 |
unset( $this->options[$v] );
|
77 |
}
|
78 |
|
79 |
+
foreach( array( 'remove_everywhere', 'extra_post_types' ) as $v ) {
|
80 |
if( !isset( $this->options[$v] ) ) {
|
81 |
$this->options[$v] = false;
|
82 |
}
|
181 |
add_action( 'admin_notices', array( $this, 'discussion_notice' ) );
|
182 |
add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 );
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
if( $this->options['remove_everywhere'] ) {
|
185 |
add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible
|
186 |
add_action( 'admin_print_styles-index.php', array( $this, 'admin_css' ) );
|
267 |
}
|
268 |
}
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
public function discussion_notice() {
|
271 |
$disabled_post_types = $this->get_disabled_post_types();
|
272 |
if( get_current_screen()->id == 'options-discussion' && !empty( $disabled_post_types ) ) {
|
402 |
include dirname( __FILE__ ) . '/includes/tools-page.php';
|
403 |
}
|
404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
private function discussion_settings_allowed() {
|
406 |
if( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) {
|
407 |
return true;
|
includes/settings-page.php
CHANGED
@@ -13,8 +13,6 @@ foreach( array_keys( $types ) as $type ) {
|
|
13 |
unset( $types[$type] );
|
14 |
}
|
15 |
|
16 |
-
$persistent_allowed = $this->persistent_mode_allowed();
|
17 |
-
|
18 |
if ( isset( $_POST['submit'] ) ) {
|
19 |
check_admin_referer( 'disable-comments-admin' );
|
20 |
$this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' );
|
@@ -26,12 +24,7 @@ if ( isset( $_POST['submit'] ) ) {
|
|
26 |
|
27 |
$disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) );
|
28 |
|
29 |
-
// entering permanent mode, or post types have changed
|
30 |
-
if( $persistent_allowed && !empty( $_POST['permanent'] ) && ( !$this->options['permanent'] || $disabled_post_types != $this->options['disabled_post_types'] ) )
|
31 |
-
$this->enter_permanent_mode();
|
32 |
-
|
33 |
$this->options['disabled_post_types'] = $disabled_post_types;
|
34 |
-
$this->options['permanent'] = $persistent_allowed && isset( $_POST['permanent'] );
|
35 |
|
36 |
// Extra custom post types
|
37 |
if( $this->networkactive && !empty( $_POST['extra_post_types'] ) ) {
|
@@ -71,20 +64,6 @@ if( WP_CACHE )
|
|
71 |
</li>
|
72 |
</ul>
|
73 |
|
74 |
-
<?php if( $persistent_allowed && $this->options['permanent'] ): ?>
|
75 |
-
<h2><?php _e( 'Other options', 'disable-comments') ?></h2>
|
76 |
-
<ul>
|
77 |
-
<li>
|
78 |
-
<?php
|
79 |
-
echo '<label for="permanent"><input type="checkbox" name="permanent" id="permanent" '. checked( $this->options['permanent'], true, false ) . '> <strong>' . __( 'Use persistent mode', 'disable-comments') . '</strong></label>';
|
80 |
-
echo '<p class="indent">' . sprintf( __( '%s: <strong>This will make persistent changes to your database — comments will remain closed even if you later disable the plugin!</strong> You should not use it if you only want to disable comments temporarily. Please <a href="%s" target="_blank">read the FAQ</a> before selecting this option.', 'disable-comments'), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>', 'https://wordpress.org/plugins/disable-comments/faq/' ) . '</p>';
|
81 |
-
if( $this->networkactive )
|
82 |
-
echo '<p class="indent">' . sprintf( __( '%s: Entering persistent mode on large multi-site networks requires a large number of database queries and can take a while. Use with caution!', 'disable-comments'), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>' ) . '</p>';
|
83 |
-
?>
|
84 |
-
</li>
|
85 |
-
</ul>
|
86 |
-
<?php endif; ?>
|
87 |
-
|
88 |
<?php wp_nonce_field( 'disable-comments-admin' ); ?>
|
89 |
<p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments') ?>"></p>
|
90 |
</form>
|
@@ -105,10 +84,5 @@ jQuery(document).ready(function($){
|
|
105 |
});
|
106 |
|
107 |
disable_comments_uihelper();
|
108 |
-
|
109 |
-
$("#permanent").change( function() {
|
110 |
-
if( $(this).is(":checked") && ! confirm(<?php echo json_encode( sprintf( __( '%s: Selecting this option will make persistent changes to your database. Are you sure you want to enable it?', 'disable-comments'), __( 'Warning', 'disable-comments' ) ) );?>) )
|
111 |
-
$(this).attr("checked", false );
|
112 |
-
});
|
113 |
});
|
114 |
</script>
|
13 |
unset( $types[$type] );
|
14 |
}
|
15 |
|
|
|
|
|
16 |
if ( isset( $_POST['submit'] ) ) {
|
17 |
check_admin_referer( 'disable-comments-admin' );
|
18 |
$this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' );
|
24 |
|
25 |
$disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) );
|
26 |
|
|
|
|
|
|
|
|
|
27 |
$this->options['disabled_post_types'] = $disabled_post_types;
|
|
|
28 |
|
29 |
// Extra custom post types
|
30 |
if( $this->networkactive && !empty( $_POST['extra_post_types'] ) ) {
|
64 |
</li>
|
65 |
</ul>
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
<?php wp_nonce_field( 'disable-comments-admin' ); ?>
|
68 |
<p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments') ?>"></p>
|
69 |
</form>
|
84 |
});
|
85 |
|
86 |
disable_comments_uihelper();
|
|
|
|
|
|
|
|
|
|
|
87 |
});
|
88 |
</script>
|
includes/tools-page.php
CHANGED
@@ -59,7 +59,10 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
|
|
59 |
$wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );
|
60 |
$wpdb->query( "DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );
|
61 |
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" );
|
62 |
-
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
|
59 |
$wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );
|
60 |
$wpdb->query( "DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );
|
61 |
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" );
|
62 |
+
|
63 |
+
$post_type_object = get_post_type_object( $delete_post_type );
|
64 |
+
$post_type_label = $post_type_object ? $post_type_object->labels->name : $delete_post_type;
|
65 |
+
echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %s.', 'disable-comments' ), $post_type_label ) . "</strong></p>";
|
66 |
}
|
67 |
|
68 |
$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: solarissmoke
|
3 |
Donate link: http://www.rayofsolaris.net/donate/
|
4 |
Tags: comments, disable, global
|
5 |
-
Requires at least:
|
6 |
-
Tested up to: 5.
|
7 |
Stable tag: trunk
|
8 |
|
9 |
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.
|
@@ -74,6 +74,10 @@ These definitions can be made either in your main `wp-config.php` or in your the
|
|
74 |
|
75 |
== Changelog ==
|
76 |
|
|
|
|
|
|
|
|
|
77 |
= 1.8.0 =
|
78 |
* Added `DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS` configuration.
|
79 |
|
2 |
Contributors: solarissmoke
|
3 |
Donate link: http://www.rayofsolaris.net/donate/
|
4 |
Tags: comments, disable, global
|
5 |
+
Requires at least: 5.0
|
6 |
+
Tested up to: 5.1
|
7 |
Stable tag: trunk
|
8 |
|
9 |
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.
|
74 |
|
75 |
== Changelog ==
|
76 |
|
77 |
+
= 1.9.0 =
|
78 |
+
* Fix compatibility with WordPress 5.0 and above.
|
79 |
+
* Remove deprecated "persistent mode" feature.
|
80 |
+
|
81 |
= 1.8.0 =
|
82 |
* Added `DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS` configuration.
|
83 |
|