Disable Comments - Version 1.0.0

Version Description

Download this release

Release Info

Developer rbplugins
Plugin Icon 128x128 Disable Comments
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

class_rb_disable-comments.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * RB Disable Comments
4
+ * Version: 1.0.0 - 88347
5
+ * Author: RBS
6
+ * Date: Thu, 01 Jun 2017 11:42:22 GMT
7
+ */
8
+
9
+ if( !defined('WPINC') || !defined("ABSPATH") ){
10
+ die();
11
+ }
12
+
13
+
14
+ class Robo_Disable_Comments {
15
+
16
+ private $options;
17
+ private $options_name = 'rb_disable_comments';
18
+ private $modified_types = array();
19
+
20
+
21
+ public function __construct() {
22
+ $this->options = get_option( $this->options_name , array() );
23
+ $this->hooks();
24
+ }
25
+
26
+
27
+ private function save_options() {
28
+ update_option( $this->options_name, $this->options );
29
+ }
30
+
31
+
32
+ private function get_disabled_post_types() {
33
+ $types = $this->options['disabled_post_types'];
34
+ return $types;
35
+ }
36
+
37
+
38
+ private function hooks() {
39
+ if( $this->options['remove_everywhere'] ) {
40
+ add_action( 'widgets_init', array( $this, 'disable_rc_widget' ) );
41
+ add_filter( 'wp_headers', array( $this, 'filter_wp_headers' ) );
42
+ add_action( 'template_redirect', array( $this, 'filter_query' ), 9 );
43
+
44
+ add_action( 'template_redirect', array( $this, 'filter_admin_bar' ) );
45
+ add_action( 'admin_init', array( $this, 'filter_admin_bar' ) );
46
+ }
47
+ add_action( 'plugins_loaded', array( $this, 'register_text_domain' ) );
48
+ add_action( 'wp_loaded', array( $this, 'wp_load_hooks' ) );
49
+ }
50
+
51
+
52
+ public function register_text_domain() {
53
+ load_plugin_textdomain( 'disable-comments-rb', false, RB_DISABLE_COMMENTS_PATH . 'languages' );
54
+ }
55
+
56
+ public function wp_load_hooks(){
57
+ $disabled_post_types = $this->get_disabled_post_types();
58
+
59
+ if( !empty( $disabled_post_types ) ) {
60
+ foreach( $disabled_post_types as $type ) {
61
+ if( post_type_supports( $type, 'comments' ) ) {
62
+ $this->modified_types[] = $type;
63
+ remove_post_type_support( $type, 'comments' );
64
+ remove_post_type_support( $type, 'trackbacks' );
65
+ }
66
+ }
67
+ add_filter( 'comments_array', array( $this, 'filter_existing_comments' ), 20, 2 );
68
+ add_filter( 'comments_open', array( $this, 'filter_comment_status' ), 20, 2 );
69
+ add_filter( 'pings_open', array( $this, 'filter_comment_status' ), 20, 2 );
70
+ }
71
+ elseif( is_admin() ) {
72
+ add_action( 'all_admin_notices', array( $this, 'setup_notice' ) );
73
+ }
74
+
75
+ if( is_admin() ) {
76
+
77
+ add_action( 'admin_menu', array( $this, 'settings_menu' ) );
78
+ add_filter( 'plugin_action_links', array( $this, 'plugin_actions_links'), 10, 2 );
79
+
80
+ if( $this->options['remove_everywhere'] ) {
81
+ add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 );
82
+ add_action( 'admin_print_footer_scripts-index.php', array( $this, 'dashboard_js' ) );
83
+ add_action( 'wp_dashboard_setup', array( $this, 'filter_dashboard' ) );
84
+ add_filter( 'pre_option_default_pingback_flag', '__return_zero' );
85
+ }
86
+ } else {
87
+ add_action( 'template_redirect', array( $this, 'check_comment_template' ) );
88
+
89
+ if( $this->options['remove_everywhere'] ) {
90
+ add_filter( 'feed_links_show_comments_feed', '__return_false' );
91
+ add_action( 'wp_footer', array( $this, 'hide_meta_widget_link' ), 100 );
92
+ }
93
+ }
94
+ }
95
+
96
+ public function check_comment_template() {
97
+ if( is_singular() && ( $this->options['remove_everywhere'] ) ) {
98
+ wp_deregister_script( 'comment-reply' );
99
+ remove_action( 'wp_head', 'feed_links_extra', 3 );
100
+ }
101
+ }
102
+
103
+ public function empty_template_for_comments() { return ''; }
104
+
105
+
106
+ public function filter_wp_headers( $headers ) {
107
+ unset( $headers['X-Pingback'] );
108
+ return $headers;
109
+ }
110
+
111
+
112
+ public function filter_query() {
113
+ if( is_comment_feed() ) {
114
+ wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
115
+ }
116
+ }
117
+
118
+ public function filter_admin_bar() {
119
+ if( is_admin_bar_showing() ) {
120
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
121
+ }
122
+ }
123
+
124
+
125
+ private function settings_page_url() {
126
+ return add_query_arg( 'page', 'rb_disable_comments_settings', admin_url( 'options-general.php' ) );
127
+ }
128
+
129
+
130
+ public function setup_notice(){
131
+ if( strpos( get_current_screen()->id, 'settings_page_rb_disable_comments_settings' ) === 0 )
132
+ return;
133
+ $hascaps = current_user_can( 'manage_options' );
134
+ if( $hascaps ) {
135
+ echo '<div class="updated fade"><p>' . sprintf( __( 'The <em>Disable Comments</em> plugin is active, but isn\'t configured to do anything yet. Visit the <a href="%s">configuration page</a> to choose which post types to disable comments on.', 'disable-comments'), esc_attr( $this->settings_page_url() ) ) . '</p></div>';
136
+ }
137
+ }
138
+
139
+
140
+ public function filter_admin_menu(){
141
+ global $pagenow;
142
+
143
+ if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' || $pagenow == 'options-discussion.php' )
144
+ wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
145
+
146
+ remove_menu_page( 'edit-comments.php' );
147
+ remove_submenu_page( 'options-general.php', 'options-discussion.php' );
148
+ }
149
+
150
+
151
+ public function filter_dashboard(){
152
+ remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
153
+ }
154
+
155
+
156
+ public function dashboard_js(){
157
+ echo '<script>
158
+ jQuery(function($){
159
+ $("#dashboard_right_now .comment-count, #latest-comments").hide();
160
+ $("#welcome-panel .welcome-comments").parent().hide();
161
+ });
162
+ </script>';
163
+ }
164
+
165
+
166
+ public function hide_meta_widget_link(){
167
+ if ( is_active_widget( false, false, 'meta', true ) && wp_script_is( 'jquery', 'enqueued' ) ) {
168
+ echo '<script> jQuery(function($){ $(".widget_meta a[href=\'' . esc_url( get_bloginfo( 'comments_rss2_url' ) ) . '\']").parent().remove(); }); </script>';
169
+ }
170
+ }
171
+
172
+
173
+ public function filter_existing_comments($comments, $post_id) {
174
+ $post = get_post( $post_id );
175
+ return ( $this->options['remove_everywhere'] ) ? array() : $comments;
176
+ }
177
+
178
+
179
+ public function filter_comment_status( $open, $post_id ) {
180
+ $post = get_post( $post_id );
181
+ return ( $this->options['remove_everywhere'] ) ? false : $open;
182
+ }
183
+
184
+
185
+ public function disable_rc_widget() {
186
+ unregister_widget( 'WP_Widget_Recent_Comments' );
187
+ }
188
+
189
+
190
+ public function plugin_actions_links( $links, $file ) {
191
+ static $plugin;
192
+
193
+ if( $file == 'disable-comments-rb/disable-comments-rb.php' && current_user_can('manage_options') ) {
194
+ array_unshift(
195
+ $links,
196
+ sprintf( '<a href="%s">%s</a>', esc_attr( $this->settings_page_url() ), __( 'Settings' ) )
197
+ );
198
+ }
199
+
200
+ return $links;
201
+ }
202
+
203
+
204
+ public function settings_menu() {
205
+ $title = __( 'Rb Disable Comments', 'disable-comments-rb' );
206
+ add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'rb_disable_comments_settings', array( $this, 'options' ) );
207
+ }
208
+
209
+
210
+ public function options() {
211
+ include( RB_DISABLE_COMMENTS_PATH .'options.php');
212
+ }
213
+
214
+ }
disable-comments-rb.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Disable Comments RB
4
+ Plugin URI: https://robosoft.co/wordpress-plugins/disable-comments
5
+ Description: Easy tool to disable comments for your blog posts, pages. Admin can disable comments in just few clicks. Delete comments from blog post.
6
+ Version: 1.0.0
7
+ Author: Robosoft Team
8
+ Author URI: https://robosoft.co/wordpress-plugins/disable-comments
9
+ License: GPL2
10
+ Text Domain: disable-comments-rb
11
+ Domain Path: /languages/
12
+ */
13
+
14
+ if( !defined('WPINC') || !defined("ABSPATH") ) die();
15
+
16
+ define("RB_DISABLE_COMMENTS_PATH", plugin_dir_path( __FILE__ ) );
17
+ define("RB_DISABLE_COMMENTS_VERSION", '1.0.0' );
18
+
19
+ include_once( RB_DISABLE_COMMENTS_PATH .'class_rb_disable-comments.php');
20
+
21
+ $rb_DisableComments = new Robo_Disable_Comments();
languages/disable-comments-rb.pot ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #, fuzzy
2
+ msgid ""
3
+ msgstr ""
4
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
5
+ "Project-Id-Version: Disable Comments Rb\n"
6
+ "POT-Creation-Date: 2017-06-01 13:41+0200\n"
7
+ "PO-Revision-Date: 2017-05-25 19:02+0200\n"
8
+ "Last-Translator: \n"
9
+ "Language-Team: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Generator: Poedit 2.0\n"
14
+ "X-Poedit-Basepath: ..\n"
15
+ "X-Poedit-Flags-xgettext: --add-comments=translators:\n"
16
+ "X-Poedit-WPHeader: disable-comments-rb.php\n"
17
+ "X-Poedit-SourceCharset: UTF-8\n"
18
+ "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
19
+ "esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
20
+ "_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
21
+ "X-Poedit-SearchPath-0: .\n"
22
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
23
+ "X-Poedit-SearchPathExcluded-1: .hg\n"
24
+ "X-Poedit-SearchPathExcluded-2: .hgignore\n"
25
+
26
+ #: class_rb_disable-comments.php:109 class_rb_disable-comments.php:139
27
+ #: dist/disable-comments-rb/class_rb_disable-comments.php:114
28
+ #: dist/disable-comments-rb/class_rb_disable-comments.php:144
29
+ msgid "Comments are closed."
30
+ msgstr ""
31
+
32
+ #: class_rb_disable-comments.php:130
33
+ #: dist/disable-comments-rb/class_rb_disable-comments.php:135
34
+ #, php-format
35
+ msgid ""
36
+ "The <em>Disable Comments</em> plugin is active, but isn't configured to do "
37
+ "anything yet. Visit the <a href=\"%s\">configuration page</a> to choose "
38
+ "which post types to disable comments on."
39
+ msgstr ""
40
+
41
+ #: class_rb_disable-comments.php:191
42
+ #: dist/disable-comments-rb/class_rb_disable-comments.php:196
43
+ msgid "Settings"
44
+ msgstr ""
45
+
46
+ #: class_rb_disable-comments.php:200
47
+ #: dist/disable-comments-rb/class_rb_disable-comments.php:205
48
+ msgid "Rb Disable Comments"
49
+ msgstr ""
50
+
51
+ #. Plugin Name of the plugin/theme
52
+ #: dist/disable-comments-rb/options.php:39 options.php:34
53
+ msgid "Robo Disable Comments"
54
+ msgstr ""
55
+
56
+ #: dist/disable-comments-rb/options.php:46 options.php:41
57
+ msgid "Disable all comments"
58
+ msgstr ""
59
+
60
+ #: dist/disable-comments-rb/options.php:54 options.php:49
61
+ msgid "Enable"
62
+ msgstr ""
63
+
64
+ #: dist/disable-comments-rb/options.php:61 options.php:56
65
+ msgid "Save Changes"
66
+ msgstr ""
67
+
68
+ #. Plugin URI of the plugin/theme
69
+ #. Author URI of the plugin/theme
70
+ msgid "https://robosoft.co/wordpress-plugins/disable-comments"
71
+ msgstr ""
72
+
73
+ #. Description of the plugin/theme
74
+ msgid ""
75
+ "Allows administrators to globally disable comments on their site. Comments "
76
+ "can be disabled according to post type."
77
+ msgstr ""
78
+
79
+ #. Author of the plugin/theme
80
+ msgid "Robosoft Team"
81
+ msgstr ""
options.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * RB Disable Comments
4
+ * Version: 1.0.0 - 88347
5
+ * Author: RBS
6
+ * Date: Thu, 01 Jun 2017 11:42:22 GMT
7
+ */
8
+
9
+ if( !defined('WPINC') || !defined("ABSPATH") ){
10
+ die();
11
+ }
12
+
13
+ $types = get_post_types( array( 'public' => true ), 'objects' );
14
+ foreach( array_keys( $types ) as $type ) {
15
+ if( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) )
16
+ unset( $types[$type] );
17
+ }
18
+
19
+ if ( isset( $_POST['submit'] ) ) {
20
+ check_admin_referer( 'disable-comments-admin' );
21
+ $this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' );
22
+
23
+ if( $this->options['remove_everywhere'] )
24
+ $disabled_post_types = array_keys( $types );
25
+ else
26
+ $disabled_post_types = array() ;
27
+
28
+
29
+ $disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) );
30
+
31
+
32
+ $this->options['disabled_post_types'] = $disabled_post_types;
33
+
34
+ $this->save_options();
35
+ }
36
+ ?>
37
+ <style> .indent {padding-left: 2em} </style>
38
+ <div class="wrap">
39
+ <h1><?php _e( 'Robo Disable Comments') ?></h1>
40
+ <form action="" method="post" id="disable-comments">
41
+ <ul>
42
+ <li>
43
+ <label for="remove_everywhere">
44
+ <input type="radio" id="remove_everywhere" name="mode" value="remove_everywhere" <?php checked( $this->options['remove_everywhere'] );?> />
45
+ <strong>
46
+ <?php _e( 'Disable all comments'); ?>
47
+ </strong>
48
+ </label>
49
+ </li>
50
+ <li>
51
+ <label for="rb_disable_comments_off">
52
+ <input type="radio" id="rb_disable_comments_off" name="mode" value="rb_disable_comments_off" <?php checked( !$this->options['remove_everywhere'] );?> />
53
+ <strong>
54
+ <?php _e( 'Enable'); ?>
55
+ </strong>
56
+ </label>
57
+ </li>
58
+ </ul>
59
+ <?php wp_nonce_field( 'disable-comments-admin' ); ?>
60
+ <p class="submit">
61
+ <input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes') ?>">
62
+ </p>
63
+ </form>
64
+ </div>
readme.txt ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Disable Comments RB ===
2
+ Contributors: rbplugins
3
+ Tags: disable comments, comments, disable
4
+ Requires at least: 4.1
5
+ Tested up to: 4.8
6
+ Stable tag: 1.0.0
7
+ License: GPLv2 or later
8
+
9
+ Easy tool to disable comments for your blog posts, pages. Admin can disable comments in just few clicks. Delete comments from blog post.
10
+
11
+ == Description ==
12
+
13
+ Our plugin it's a tool for admin to fully disable comments on your website. It's not require any special skills or code modifications to disable comments on your website.
14
+
15
+ Just install plugin from the directory and enable disable comments function in plugin settings.
16
+
17
+ == Frequently Asked Questions ==
18
+
19
+ = How to install disable comments plugin ? =
20
+
21
+ There is few ways to install plugin on your wordpress blog. First of all you can donwload plugin installer from the plugin directory and install it in plugins section of the Wordpress backend. Another way open plugins section and click Add button. Then you can try to search disable comments plugin in directory online. When you find required item just click on install button and activate it after that.
22
+
23
+ = How to turn on disable comments functionality on your website ? =
24
+
25
+ After installation of the disable comments plugin ou need to open plugin settings and enable main function to disable comments for your blog.
26
+
27
+ = If I wish to disable comments for some particular post ? =
28
+
29
+ You don't need this plugin.
30
+
31
+ Go to the edit page for the post you want to disable comments on. Scroll down to the "Discussion" box, where you will find the comment options for that post. If you don't see a "Discussion" box, then click on "Screen Options" at the top of your screen, and make sure the "Discussion" checkbox is checked.
32
+
33
+ == Changelog ==
34
+
35
+ = 1.0 =
36
+ * First release of the plugin.