Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.132.2

Version Description

December 17 2019 = * Fix: The disable comments functionality.

Download this release

Release Info

Developer shagimuratov
Plugin Icon 128x128 Spam protection, AntiSpam, FireWall by CleanTalk
Version 5.132.2
Comparing to
See all releases

Code changes from version 5.132.1 to 5.132.2

Files changed (3) hide show
  1. cleantalk.php +1 -1
  2. lib/Cleantalk/DisableComments.php +221 -0
  3. readme.txt +4 -1
cleantalk.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
- Version: 5.132.1
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
+ Version: 5.132.2
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk
lib/Cleantalk/DisableComments.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Cleantalk;
4
+
5
+ /**
6
+ * Class DisableComments
7
+ * Discribes functions needed to use disable comments functionality
8
+ *
9
+ * Only for Wodrdpress 4.7 and above
10
+ *
11
+ * Uses singleton template
12
+ *
13
+ * @contributor Cleantalk
14
+ */
15
+ class DisableComments{
16
+
17
+ use \Cleantalk\Templates\Singleton;
18
+
19
+ /**
20
+ * Determs is Wordpress Multisite is enabled
21
+ *
22
+ * @var bool
23
+ */
24
+ private $is_wpms = false;
25
+
26
+ /**
27
+ * Post types to disable comments
28
+ *
29
+ * @var array
30
+ */
31
+ private $types_to_disable;
32
+
33
+ /**
34
+ * @var /Cleantalk/ApbctState antispam instance
35
+ */
36
+ private $apbct;
37
+
38
+ /**
39
+ * Singleton constructor.
40
+ */
41
+ function init(){
42
+
43
+ global $apbct;
44
+
45
+ $this->apbct = $apbct;
46
+
47
+ $types_to_disable = array();
48
+
49
+ if( $this->apbct->settings['disable_comments__all'] ){
50
+ $types_to_disable = array( 'page', 'post', 'media' );
51
+ }else{
52
+ if( $this->apbct->settings['disable_comments__posts'] )
53
+ $types_to_disable[] = 'post';
54
+ if( $this->apbct->settings['disable_comments__pages'] )
55
+ $types_to_disable[] = 'page';
56
+ if( $this->apbct->settings['disable_comments__media'] )
57
+ $types_to_disable[] = 'media';
58
+ }
59
+
60
+ $this->is_wpms = APBCT_WPMS;
61
+ $this->types_to_disable = $types_to_disable;
62
+
63
+ add_action( 'widgets_init', array( $this, 'disable_rc_widget' ) );
64
+ add_filter( 'wp_headers', array( $this, 'filter__headers' ) );
65
+ add_action( 'template_redirect', array( $this, 'filter__query' ), 9 );
66
+ add_action( 'template_redirect', array( $this, 'filter__admin_bar' ) );
67
+ add_action( 'admin_init', array( $this, 'filter__admin_bar' ) );
68
+ add_action( 'wp_loaded', array( $this, 'disable_types' ) );
69
+ add_action( 'enqueue_block_editor_assets', array( $this, 'filter__gutenberg_blocks' ) );
70
+
71
+ }
72
+
73
+ function is_current_type_to_disable( $type = '' ){
74
+ $type = $type ? $type : get_post_type();
75
+ return in_array( $type, $this->types_to_disable );
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @return void
81
+ */
82
+ public function disable_types(){
83
+ if( ! empty( $this->types_to_disable ) ){
84
+ foreach ( $this->types_to_disable as $type ){
85
+ // we need to know what native support was for later
86
+ if( post_type_supports( $type, 'comments' ) ){
87
+ // $this->modified_types[] = $type;
88
+ remove_post_type_support( $type, 'comments' );
89
+ remove_post_type_support( $type, 'trackbacks' );
90
+ }
91
+ }
92
+
93
+ add_filter( 'comments_array', array( $this, 'filter__existing_comments' ), 20, 2 );
94
+ add_filter( 'comments_open', array( $this, 'filter__comment_status' ), 20, 2 );
95
+ add_filter( 'pings_open', array( $this, 'filter__comment_status' ), 20, 2 );
96
+ add_filter( 'get_comments_number', array( $this, 'filter__comments_number' ), 20, 2 );
97
+
98
+ if( is_admin() ){
99
+
100
+ if( $this->apbct->settings['disable_comments__all'] ){
101
+ add_action( 'admin_menu', array( $this, 'admin__filter_menu' ), 999 );
102
+ add_action( 'admin_print_styles-index.php', array( $this, 'admin__filter_css' ) );
103
+ add_action( 'admin_print_styles-profile.php', array( $this, 'admin__filter_css' ) );
104
+ add_action( 'wp_dashboard_setup', array( $this, 'admin__filter_dashboard' ) );
105
+ add_filter( 'pre_option_default_pingback_flag', '__return_zero' );
106
+ }
107
+ }else{
108
+
109
+ add_filter( 'get_comments_number', array( $this, 'template__check' ), 20, 2 );
110
+
111
+ }
112
+ }
113
+ }
114
+
115
+ function disable_rc_widget(){
116
+ unregister_widget( 'WP_Widget_Recent_Comments' );
117
+ }
118
+
119
+ function admin__filter_css(){
120
+ echo '<style>
121
+ #dashboard_right_now .comment-count,
122
+ #dashboard_right_now .comment-mod-count,
123
+ #latest-comments,
124
+ #welcome-panel .welcome-comments,
125
+ .user-comment-shortcuts-wrap {
126
+ display: none !important;
127
+ }
128
+ </style>';
129
+ }
130
+
131
+ function admin__filter_dashboard(){
132
+ remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
133
+ }
134
+
135
+ function admin__filter_menu(){
136
+ global $pagenow;
137
+
138
+ if( in_array( $pagenow, array( 'comment.php', 'edit-comments.php', 'options-discussion.php' ) ) )
139
+ wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
140
+
141
+ remove_menu_page( 'edit-comments.php' );
142
+ remove_submenu_page( 'options-general.php', 'options-discussion.php' );
143
+ }
144
+
145
+ function template__check(){
146
+ if( is_singular() && $this->is_current_type_to_disable() ){
147
+ add_filter( 'comments_template', array( $this, 'template__replace' ), 20 );
148
+ wp_deregister_script( 'comment-reply' );
149
+ remove_action( 'wp_head', 'feed_links_extra', 3 );
150
+ }
151
+ }
152
+
153
+ function template__replace(){
154
+ return APBCT_DIR_PATH . 'templates/empty_comments.php';
155
+ }
156
+
157
+ function filter__headers( $headers ){
158
+ unset( $headers['X-Pingback'] );
159
+ return $headers;
160
+ }
161
+
162
+ function filter__query( $headers ){
163
+ if( is_comment_feed() )
164
+ wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
165
+ }
166
+
167
+ function filter__admin_bar(){
168
+ if( is_admin_bar_showing() ){
169
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
170
+ if( $this->is_wpms ){
171
+ add_action( 'admin_bar_menu', array( $this, 'remove__comment_links__wpms' ), 500 );
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Determines if scripts should be enqueued
178
+ */
179
+ public function filter__gutenberg_blocks( $hook ){
180
+ if( $this->is_current_type_to_disable() ){
181
+ wp_enqueue_script(
182
+ 'cleantalk-disable-comments-gutenberg',
183
+ plugin_dir_url( __FILE__ ) . 'assets/apbct-disable-comments.js',
184
+ array(),
185
+ APBCT_VERSION,
186
+ 'in_footer'
187
+ );
188
+ wp_localize_script(
189
+ 'cleantalk-disable-comments-gutenberg',
190
+ 'apbctDisableComments',
191
+ array(
192
+ 'disabled_blocks' => array( 'core/latest-comments' ),
193
+ )
194
+ );
195
+ }
196
+ }
197
+
198
+ public function filter__existing_comments( $comments, $post_id ){
199
+ return $this->is_current_type_to_disable() ? array() : $comments;
200
+ }
201
+
202
+ public function filter__comment_status( $open, $post_id ){
203
+ return $this->is_current_type_to_disable() ? false : $open;
204
+ }
205
+
206
+ public function filter__comments_number( $count, $post_id ){
207
+ return $this->is_current_type_to_disable() ? 0 : $count;
208
+ }
209
+
210
+ function remove__comment_links__wpms( $wp_admin_bar ){
211
+ if( is_user_logged_in() ){
212
+
213
+ foreach ( (array) $wp_admin_bar->user->blogs as $blog ){
214
+ $wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
215
+ }
216
+
217
+ }else
218
+ $wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' );
219
+
220
+ }
221
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: spam, antispam, woocommerce, comments, firewall
4
  Requires at least: 3.0
5
  Tested up to: 5.3
6
  Requires PHP: 5.4
7
- Stable tag: 5.132.1
8
  License: GPLv2
9
 
10
  Spam protection, antispam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
@@ -579,6 +579,9 @@ If your website has forms that send data to external sources, you can enable opt
579
  10. Website's options.
580
 
581
  == Changelog ==
 
 
 
582
  = 5.132.1 December 17 2019 =
583
  * Fix: Fatal PHP error.
584
 
4
  Requires at least: 3.0
5
  Tested up to: 5.3
6
  Requires PHP: 5.4
7
+ Stable tag: 5.132.2
8
  License: GPLv2
9
 
10
  Spam protection, antispam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
579
  10. Website's options.
580
 
581
  == Changelog ==
582
+ = 5.132.2 December 17 2019 =
583
+ * Fix: The disable comments functionality.
584
+
585
  = 5.132.1 December 17 2019 =
586
  * Fix: Fatal PHP error.
587