Skip to content

Commit ca26490

Browse files
committed
Merge branch 'alim-dev'
2 parents b71bca6 + 29d812b commit ca26490

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

disable-comments.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: Disable Comments
55
* Plugin URI: https://wordpress.org/plugins/disable-comments/
66
* 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.
7-
* Version: 2.3.4
7+
* Version: 2.3.5
88
* Author: WPDeveloper
99
* Author URI: https://wpdeveloper.com
1010
* License: GPL-3.0+
@@ -37,7 +37,7 @@ public static function get_instance()
3737

3838
function __construct()
3939
{
40-
define('DC_VERSION', '2.3.4');
40+
define('DC_VERSION', '2.3.5');
4141
define('DC_PLUGIN_SLUG', 'disable_comments_settings');
4242
define('DC_PLUGIN_ROOT_PATH', dirname(__FILE__));
4343
define('DC_PLUGIN_VIEWS_PATH', DC_PLUGIN_ROOT_PATH . '/views/');
@@ -294,7 +294,7 @@ private function is_post_type_disabled($type)
294294
private function init_filters()
295295
{
296296
// These need to happen now.
297-
if ($this->options['remove_everywhere']) {
297+
if (!empty($this->options['remove_everywhere'])) {
298298
add_action('widgets_init', array($this, 'disable_rc_widget'));
299299
add_filter('wp_headers', array($this, 'filter_wp_headers'));
300300
add_action('template_redirect', array($this, 'filter_query'), 9); // before redirect_canonical.
@@ -382,7 +382,7 @@ public function init_wploaded_filters()
382382
add_action('admin_notices', array($this, 'discussion_notice'));
383383
add_filter('plugin_row_meta', array($this, 'set_plugin_meta'), 10, 2);
384384

385-
if ($this->options['remove_everywhere']) {
385+
if (!empty($this->options['remove_everywhere'])) {
386386
add_action('admin_menu', array($this, 'filter_admin_menu'), 9999); // do this as late as possible.
387387
add_action('admin_print_styles-index.php', array($this, 'admin_css'));
388388
add_action('admin_print_styles-profile.php', array($this, 'admin_css'));
@@ -900,6 +900,9 @@ public function disable_comments_settings($_args = array())
900900
}
901901
$old_options = $this->options;
902902
$this->options = [];
903+
if($this->is_CLI){
904+
$this->options = $old_options;
905+
}
903906

904907
$this->options['is_network_admin'] = isset($formArray['is_network_admin']) && $formArray['is_network_admin'] == '1' ? true : false;
905908

@@ -985,7 +988,11 @@ public function delete_comments_settings($_args = array())
985988
global $deletedPostTypeNames;
986989
$log = '';
987990
$nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : '');
988-
$formArray = $this->form_data_modify($_POST['data']);
991+
if (!empty($_args)) {
992+
$formArray = wp_parse_args($_args);
993+
} else {
994+
$formArray = (isset($_POST['data']) ? $this->form_data_modify($_POST['data']) : []);
995+
}
989996

990997
if (($this->is_CLI && !empty($_args)) || wp_verify_nonce($nonce, 'disable_comments_save_settings')) {
991998
if ( !empty($formArray['is_network_admin']) && function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
@@ -1105,7 +1112,7 @@ private function delete_comments($_args){
11051112
$wpdb->query("OPTIMIZE TABLE $wpdb->commentmeta");
11061113
$wpdb->query("OPTIMIZE TABLE $wpdb->comments");
11071114

1108-
$log = __('All spam comments have been deleted', 'disable-comments');
1115+
$log = __('All spam comments have been deleted.', 'disable-comments');
11091116
}
11101117
}
11111118
delete_transient('wc_count_comments');

includes/cli.php

+38-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public function __construct($dc_instance)
4646
'description' => 'Uncheck specified checkbox in `On Specific Post Types.', // uncheck specified checkbox in `On Specific Post Types:`
4747
'optional' => true,
4848
),
49+
array(
50+
'type' => 'flag',
51+
'name' => 'disable-avatar',
52+
'description' => 'This will change Avatar state from your entire site.', // uncheck specified checkbox in `On Specific Post Types:`
53+
'optional' => true,
54+
),
4955
);
5056
if ($this->dc_instance->networkactive){
5157
$disable_synopsis[] = array(
@@ -81,6 +87,12 @@ public function __construct($dc_instance)
8187
'optional' => true,
8288
'options' => $comment_types,
8389
),
90+
array(
91+
'type' => 'flag',
92+
'name' => 'spam',
93+
'description' => 'Permanently delete all spam comments on your WordPress website.',
94+
'optional' => true,
95+
),
8496
);
8597
if (!$this->dc_instance->networkactive){
8698
$delete_synopsis[] = array(
@@ -116,6 +128,7 @@ function disable($args, $assoc_args)
116128
$extra_post_types = WP_CLI\Utils\get_flag_value($assoc_args, 'extra-post-types');
117129
$remove_xmlrpc_comments = WP_CLI\Utils\get_flag_value($assoc_args, 'xmlrpc');
118130
$remove_rest_API_comments = WP_CLI\Utils\get_flag_value($assoc_args, 'rest-api');
131+
$disable_avatar = WP_CLI\Utils\get_flag_value($assoc_args, 'disable-avatar');
119132

120133
if ($types === 'all') {
121134
$disable_comments_settings['mode'] = 'remove_everywhere';
@@ -150,11 +163,30 @@ function disable($args, $assoc_args)
150163

151164
if(isset($remove_xmlrpc_comments)){
152165
$disable_comments_settings['remove_xmlrpc_comments'] = $remove_xmlrpc_comments;
153-
$msg .= __( 'Disable Comments via XML-RPC. ', 'disable-comments' );
166+
if($remove_xmlrpc_comments && $remove_xmlrpc_comments !== 'false'){
167+
$msg .= __( 'Disable Comments via XML-RPC. ', 'disable-comments' );
168+
}
169+
else{
170+
$msg .= __( 'Enabled Comments via XML-RPC. ', 'disable-comments' );
171+
}
154172
}
155173
if(isset($remove_rest_API_comments)){
156174
$disable_comments_settings['remove_rest_API_comments'] = $remove_rest_API_comments;
157-
$msg .= __( 'Disable Comments via REST API. ', 'disable-comments' );
175+
if($remove_rest_API_comments && $remove_rest_API_comments !== 'false'){
176+
$msg .= __( 'Disable Comments via REST API. ', 'disable-comments' );
177+
}
178+
else{
179+
$msg .= __( 'Enabled Comments via REST API. ', 'disable-comments' );
180+
}
181+
}
182+
if($disable_avatar != null){
183+
$disable_comments_settings['disable_avatar'] = $disable_avatar;
184+
if($disable_avatar && $disable_avatar !== 'false'){
185+
$msg .= __( 'Disabled Avatar on your entire site. ', 'disable-comments' );
186+
}
187+
else{
188+
$msg .= __( 'Enabled Avatar on your entire site. ', 'disable-comments' );
189+
}
158190
}
159191

160192
$this->dc_instance->disable_comments_settings($disable_comments_settings);
@@ -174,6 +206,7 @@ function delete($args, $assoc_args)
174206
$selected_delete_types = WP_CLI\Utils\get_flag_value($assoc_args, 'types');
175207
$delete_extra_post_types = WP_CLI\Utils\get_flag_value($assoc_args, 'extra-post-types');
176208
$delete_comment_types = WP_CLI\Utils\get_flag_value($assoc_args, 'comment-types');
209+
$delete_spam_types = WP_CLI\Utils\get_flag_value($assoc_args, 'spam');
177210

178211

179212
if ( $delete_comment_types === 'all' || $selected_delete_types === 'all' ) {
@@ -184,6 +217,8 @@ function delete($args, $assoc_args)
184217
} elseif(!empty($delete_comment_types)) {
185218
$delete_comments_settings['delete_mode'] = 'selected_delete_comment_types';
186219
$delete_comments_settings['delete_comment_types'] = array_map('trim', explode(',', $delete_comment_types));
220+
} elseif(!empty($delete_spam_types)) {
221+
$delete_comments_settings['delete_mode'] = 'delete_spam';
187222
} else{
188223
WP_CLI::error("Please provide valid parameters. \nSee 'wp help dc delete' for more information.");
189224
}
@@ -194,6 +229,6 @@ function delete($args, $assoc_args)
194229
}
195230

196231
$logged_msg = $this->dc_instance->delete_comments_settings($delete_comments_settings);
197-
WP_CLI::success( implode( "\n", $logged_msg ) );
232+
WP_CLI::success( is_array($logged_msg) ? implode( "\n", $logged_msg ) : $logged_msg );
198233
}
199234
}

readme.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: comments, delete comments, disable comments, spam comment, disable, stop s
55
Requires at least: 5.0
66
Tested up to: 5.9
77
Requires PHP: 5.6
8-
Stable tag: 2.3.4
8+
Stable tag: 2.3.5
99
License: GPL-3.0-or-later
1010
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1111

@@ -192,6 +192,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
192192
and this project adheres to [Semantic Versioning](http://semver.org/).
193193
This will be maiintained from August 19, 2020 - @asif2bd
194194

195+
= [2.3.5] - 2022-04-27 =
196+
* Added: More WP-CLI commands.
197+
* Few minor bug fix and improvement.
198+
195199
= [2.3.4] - 2022-03-28 =
196200
* Fixed: PHP Warning in Multisite Network.
197201

0 commit comments

Comments
 (0)