Skip to content

Commit

Permalink
Merge branch 'alim-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
priyomukul committed Apr 27, 2022
2 parents b71bca6 + 29d812b commit ca26490
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
19 changes: 13 additions & 6 deletions disable-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down Expand Up @@ -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/');
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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' ) ) {
Expand Down Expand Up @@ -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');
Expand Down
41 changes: 38 additions & 3 deletions includes/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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' ) {
Expand 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.");
}
Expand All @@ -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 );
}
}
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit ca26490

Please sign in to comment.