diff --git a/disable-comments.php b/disable-comments.php index 234fe61..0ea4d4b 100644 --- a/disable-comments.php +++ b/disable-comments.php @@ -4,7 +4,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. You could bulk delete comments using Tools. - * Version: 2.3.4 + * Version: 2.3.5 * Author: WPDeveloper * Author URI: https://wpdeveloper.com * License: GPL-3.0+ @@ -37,7 +37,7 @@ public static function get_instance() function __construct() { - define('DC_VERSION', '2.3.4'); + define('DC_VERSION', '2.3.5'); define('DC_PLUGIN_SLUG', 'disable_comments_settings'); define('DC_PLUGIN_ROOT_PATH', dirname(__FILE__)); define('DC_PLUGIN_VIEWS_PATH', DC_PLUGIN_ROOT_PATH . '/views/'); @@ -294,7 +294,7 @@ private function is_post_type_disabled($type) private function init_filters() { // These need to happen now. - if ($this->options['remove_everywhere']) { + if (!empty($this->options['remove_everywhere'])) { add_action('widgets_init', array($this, 'disable_rc_widget')); add_filter('wp_headers', array($this, 'filter_wp_headers')); add_action('template_redirect', array($this, 'filter_query'), 9); // before redirect_canonical. @@ -382,7 +382,7 @@ public function init_wploaded_filters() add_action('admin_notices', array($this, 'discussion_notice')); add_filter('plugin_row_meta', array($this, 'set_plugin_meta'), 10, 2); - if ($this->options['remove_everywhere']) { + if (!empty($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')); add_action('admin_print_styles-profile.php', array($this, 'admin_css')); @@ -900,6 +900,9 @@ public function disable_comments_settings($_args = array()) } $old_options = $this->options; $this->options = []; + if($this->is_CLI){ + $this->options = $old_options; + } $this->options['is_network_admin'] = isset($formArray['is_network_admin']) && $formArray['is_network_admin'] == '1' ? true : false; @@ -985,7 +988,11 @@ public function delete_comments_settings($_args = array()) global $deletedPostTypeNames; $log = ''; $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : ''); - $formArray = $this->form_data_modify($_POST['data']); + if (!empty($_args)) { + $formArray = wp_parse_args($_args); + } else { + $formArray = (isset($_POST['data']) ? $this->form_data_modify($_POST['data']) : []); + } if (($this->is_CLI && !empty($_args)) || wp_verify_nonce($nonce, 'disable_comments_save_settings')) { if ( !empty($formArray['is_network_admin']) && function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) { @@ -1105,7 +1112,7 @@ private function delete_comments($_args){ $wpdb->query("OPTIMIZE TABLE $wpdb->commentmeta"); $wpdb->query("OPTIMIZE TABLE $wpdb->comments"); - $log = __('All spam comments have been deleted', 'disable-comments'); + $log = __('All spam comments have been deleted.', 'disable-comments'); } } delete_transient('wc_count_comments'); diff --git a/includes/cli.php b/includes/cli.php index 02156a3..fc93602 100644 --- a/includes/cli.php +++ b/includes/cli.php @@ -46,6 +46,12 @@ public function __construct($dc_instance) 'description' => 'Uncheck specified checkbox in `On Specific Post Types.', // uncheck specified checkbox in `On Specific Post Types:` 'optional' => true, ), + array( + 'type' => 'flag', + 'name' => 'disable-avatar', + 'description' => 'This will change Avatar state from your entire site.', // uncheck specified checkbox in `On Specific Post Types:` + 'optional' => true, + ), ); if ($this->dc_instance->networkactive){ $disable_synopsis[] = array( @@ -81,6 +87,12 @@ public function __construct($dc_instance) 'optional' => true, 'options' => $comment_types, ), + array( + 'type' => 'flag', + 'name' => 'spam', + 'description' => 'Permanently delete all spam comments on your WordPress website.', + 'optional' => true, + ), ); if (!$this->dc_instance->networkactive){ $delete_synopsis[] = array( @@ -116,6 +128,7 @@ function disable($args, $assoc_args) $extra_post_types = WP_CLI\Utils\get_flag_value($assoc_args, 'extra-post-types'); $remove_xmlrpc_comments = WP_CLI\Utils\get_flag_value($assoc_args, 'xmlrpc'); $remove_rest_API_comments = WP_CLI\Utils\get_flag_value($assoc_args, 'rest-api'); + $disable_avatar = WP_CLI\Utils\get_flag_value($assoc_args, 'disable-avatar'); if ($types === 'all') { $disable_comments_settings['mode'] = 'remove_everywhere'; @@ -150,11 +163,30 @@ function disable($args, $assoc_args) if(isset($remove_xmlrpc_comments)){ $disable_comments_settings['remove_xmlrpc_comments'] = $remove_xmlrpc_comments; - $msg .= __( 'Disable Comments via XML-RPC. ', 'disable-comments' ); + if($remove_xmlrpc_comments && $remove_xmlrpc_comments !== 'false'){ + $msg .= __( 'Disable Comments via XML-RPC. ', 'disable-comments' ); + } + else{ + $msg .= __( 'Enabled Comments via XML-RPC. ', 'disable-comments' ); + } } if(isset($remove_rest_API_comments)){ $disable_comments_settings['remove_rest_API_comments'] = $remove_rest_API_comments; - $msg .= __( 'Disable Comments via REST API. ', 'disable-comments' ); + if($remove_rest_API_comments && $remove_rest_API_comments !== 'false'){ + $msg .= __( 'Disable Comments via REST API. ', 'disable-comments' ); + } + else{ + $msg .= __( 'Enabled Comments via REST API. ', 'disable-comments' ); + } + } + if($disable_avatar != null){ + $disable_comments_settings['disable_avatar'] = $disable_avatar; + if($disable_avatar && $disable_avatar !== 'false'){ + $msg .= __( 'Disabled Avatar on your entire site. ', 'disable-comments' ); + } + else{ + $msg .= __( 'Enabled Avatar on your entire site. ', 'disable-comments' ); + } } $this->dc_instance->disable_comments_settings($disable_comments_settings); @@ -174,6 +206,7 @@ function delete($args, $assoc_args) $selected_delete_types = WP_CLI\Utils\get_flag_value($assoc_args, 'types'); $delete_extra_post_types = WP_CLI\Utils\get_flag_value($assoc_args, 'extra-post-types'); $delete_comment_types = WP_CLI\Utils\get_flag_value($assoc_args, 'comment-types'); + $delete_spam_types = WP_CLI\Utils\get_flag_value($assoc_args, 'spam'); if ( $delete_comment_types === 'all' || $selected_delete_types === 'all' ) { @@ -184,6 +217,8 @@ function delete($args, $assoc_args) } elseif(!empty($delete_comment_types)) { $delete_comments_settings['delete_mode'] = 'selected_delete_comment_types'; $delete_comments_settings['delete_comment_types'] = array_map('trim', explode(',', $delete_comment_types)); + } elseif(!empty($delete_spam_types)) { + $delete_comments_settings['delete_mode'] = 'delete_spam'; } else{ WP_CLI::error("Please provide valid parameters. \nSee 'wp help dc delete' for more information."); } @@ -194,6 +229,6 @@ function delete($args, $assoc_args) } $logged_msg = $this->dc_instance->delete_comments_settings($delete_comments_settings); - WP_CLI::success( implode( "\n", $logged_msg ) ); + WP_CLI::success( is_array($logged_msg) ? implode( "\n", $logged_msg ) : $logged_msg ); } } diff --git a/readme.txt b/readme.txt index aa3ecf0..bf54813 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: comments, delete comments, disable comments, spam comment, disable, stop s Requires at least: 5.0 Tested up to: 5.9 Requires PHP: 5.6 -Stable tag: 2.3.4 +Stable tag: 2.3.5 License: GPL-3.0-or-later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -192,6 +192,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). This will be maiintained from August 19, 2020 - @asif2bd += [2.3.5] - 2022-04-27 = +* Added: More WP-CLI commands. +* Few minor bug fix and improvement. + = [2.3.4] - 2022-03-28 = * Fixed: PHP Warning in Multisite Network.