Commit dc035e14 authored by samba's avatar samba

[auto] plugin: disable-comments 1.9.0

parent 1662cb39
......@@ -3,7 +3,7 @@
Plugin Name: Disable Comments
Plugin URI: https://wordpress.org/plugins/disable-comments/
Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type.
Version: 1.8.0
Version: 1.9.0
Author: Samir Shah
Author URI: http://www.rayofsolaris.net/
License: GPL2
......@@ -76,7 +76,7 @@ class Disable_Comments {
unset( $this->options[$v] );
}
foreach( array( 'remove_everywhere', 'permanent', 'extra_post_types' ) as $v ) {
foreach( array( 'remove_everywhere', 'extra_post_types' ) as $v ) {
if( !isset( $this->options[$v] ) ) {
$this->options[$v] = false;
}
......@@ -181,12 +181,6 @@ class Disable_Comments {
add_action( 'admin_notices', array( $this, 'discussion_notice' ) );
add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 );
// if only certain types are disabled, remember the original post status
if( !( $this->persistent_mode_allowed() && $this->options['permanent'] ) && !$this->options['remove_everywhere'] ) {
add_action( 'edit_form_advanced', array( $this, 'edit_form_inputs' ) );
add_action( 'edit_page_form', array( $this, 'edit_form_inputs' ) );
}
if( $this->options['remove_everywhere'] ) {
add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible
add_action( 'admin_print_styles-index.php', array( $this, 'admin_css' ) );
......@@ -273,14 +267,6 @@ class Disable_Comments {
}
}
public function edit_form_inputs() {
global $post;
// Without a dicussion meta box, comment_status will be set to closed on new/updated posts
if( in_array( $post->post_type, $this->modified_types ) ) {
echo '<input type="hidden" name="comment_status" value="' . $post->comment_status . '" /><input type="hidden" name="ping_status" value="' . $post->ping_status . '" />';
}
}
public function discussion_notice() {
$disabled_post_types = $this->get_disabled_post_types();
if( get_current_screen()->id == 'options-discussion' && !empty( $disabled_post_types ) ) {
......@@ -416,40 +402,6 @@ class Disable_Comments {
include dirname( __FILE__ ) . '/includes/tools-page.php';
}
private function enter_permanent_mode() {
$types = $this->get_disabled_post_types();
if( empty( $types ) )
return;
global $wpdb;
if( $this->networkactive ) {
// NOTE: this can be slow on large networks!
$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 ) );
foreach ( $blogs as $id ) {
switch_to_blog( $id );
$this->close_comments_in_db( $types );
restore_current_blog();
}
}
else {
$this->close_comments_in_db( $types );
}
}
private function close_comments_in_db( $types ){
global $wpdb;
$bits = implode( ', ', array_pad( array(), count( $types ), '%s' ) );
$wpdb->query( $wpdb->prepare( "UPDATE `$wpdb->posts` SET `comment_status` = 'closed', ping_status = 'closed' WHERE `post_type` IN ( $bits )", $types ) );
}
private function persistent_mode_allowed() {
if( defined( 'DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE' ) && DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE == false ) {
return false;
}
}
private function discussion_settings_allowed() {
if( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) {
return true;
......
......@@ -13,8 +13,6 @@ foreach( array_keys( $types ) as $type ) {
unset( $types[$type] );
}
$persistent_allowed = $this->persistent_mode_allowed();
if ( isset( $_POST['submit'] ) ) {
check_admin_referer( 'disable-comments-admin' );
$this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' );
......@@ -26,12 +24,7 @@ if ( isset( $_POST['submit'] ) ) {
$disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) );
// entering permanent mode, or post types have changed
if( $persistent_allowed && !empty( $_POST['permanent'] ) && ( !$this->options['permanent'] || $disabled_post_types != $this->options['disabled_post_types'] ) )
$this->enter_permanent_mode();
$this->options['disabled_post_types'] = $disabled_post_types;
$this->options['permanent'] = $persistent_allowed && isset( $_POST['permanent'] );
// Extra custom post types
if( $this->networkactive && !empty( $_POST['extra_post_types'] ) ) {
......@@ -71,20 +64,6 @@ if( WP_CACHE )
</li>
</ul>
<?php if( $persistent_allowed && $this->options['permanent'] ): ?>
<h2><?php _e( 'Other options', 'disable-comments') ?></h2>
<ul>
<li>
<?php
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>';
echo '<p class="indent">' . sprintf( __( '%s: <strong>This will make persistent changes to your database &mdash; 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>';
if( $this->networkactive )
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>';
?>
</li>
</ul>
<?php endif; ?>
<?php wp_nonce_field( 'disable-comments-admin' ); ?>
<p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments') ?>"></p>
</form>
......@@ -105,10 +84,5 @@ jQuery(document).ready(function($){
});
disable_comments_uihelper();
$("#permanent").change( function() {
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' ) ) );?>) )
$(this).attr("checked", false );
});
});
</script>
......@@ -59,7 +59,10 @@ if ( isset( $_POST['delete'] ) && isset( $_POST['delete_mode'] ) ) {
$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'" );
$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'" );
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" );
echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %ss.', 'disable-comments' ), $delete_post_type ) . "</strong></p>";
$post_type_object = get_post_type_object( $delete_post_type );
$post_type_label = $post_type_object ? $post_type_object->labels->name : $delete_post_type;
echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %s.', 'disable-comments' ), $post_type_label ) . "</strong></p>";
}
$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
......
......@@ -2,8 +2,8 @@
Contributors: solarissmoke
Donate link: http://www.rayofsolaris.net/donate/
Tags: comments, disable, global
Requires at least: 4.7
Tested up to: 5.0
Requires at least: 5.0
Tested up to: 5.1
Stable tag: trunk
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
== Changelog ==
= 1.9.0 =
* Fix compatibility with WordPress 5.0 and above.
* Remove deprecated "persistent mode" feature.
= 1.8.0 =
* Added `DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS` configuration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment