Skip to content

Commit 5f44408

Browse files
committed
Initial commit
0 parents  commit 5f44408

File tree

11 files changed

+813
-0
lines changed

11 files changed

+813
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# OS generated files #
2+
######################
3+
.DS_Store
4+
.DS_Store?
5+
._*
6+
.Spotlight-V100
7+
.Trashes
8+
Icon?
9+
ehthumbs.db
10+
Thumbs.db

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Uncomment WordPress Plugin
2+
3+
Your one-stop shop for removing WordPress comment functionality.
4+
5+
While WordPress allows you to disable comments site-wide via the comments setting screen, the Uncomment plugin goes one step further and disables or hides all interface elements and functionality related to comments on your WordPress site.
6+
7+
## FAQ
8+
9+
### Does this plugin remove existing comments?
10+
11+
Uncomment does not remove any existing comments from the database.
12+
13+
### I'm still seeing comments on my site?
14+
15+
Uncomment uses WordPress core actions, filters and functions to hide or disable commment-related elements. It is possible that your theme or another plugin uses its own custom comment elements or functions. In that case, the Uncomment plugin is unable to remove those elements.
16+
17+
If you spot any WordPress core functionality that should have been removed by the Uncomment plugin, please let us know by opening an [issue](https://github.com/functionsfile/uncomment/issues) or [pull request](https://github.com/functionsfile/uncomment/pulls).
18+
19+
### Can I enable comments for a specific post or post type?
20+
21+
Uncomment is designed to remove all commenting functionality from your WordPress site. There are no additional settings to enable comments on specific posts or post types.

includes/admin.php

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
/**
3+
* Functionality specific to the admin
4+
*
5+
* @package Uncomment
6+
*/
7+
8+
namespace Uncomment\Admin;
9+
10+
// Do not check for plugin updates.
11+
add_filter( 'site_transient_update_plugins', __NAMESPACE__ . '\remove_update_nag' );
12+
13+
// Remove admin pages.
14+
add_action( 'admin_init', __NAMESPACE__ . '\remove_admin_pages' );
15+
16+
// Remove admin menu items.
17+
add_action( 'admin_menu', __NAMESPACE__ . '\remove_menu_items' );
18+
19+
// Remove the commentsdiv meta box.
20+
add_action( 'admin_init', __NAMESPACE__ . '\remove_commentsdiv_meta_box' );
21+
22+
// Remove "Turn comments on or off" from the Welcome Panel.
23+
add_action( 'admin_footer-index.php', __NAMESPACE__ . '\remove_welcome_panel_item' );
24+
25+
// Remove Keyboard Shortcuts options from the profile page.
26+
add_action( 'personal_options', __NAMESPACE__ . '\remove_profile_items' );
27+
28+
// Remove the 'Discussion Settings' help tab from the post edit screen.
29+
add_action( 'admin_head-post.php', __NAMESPACE__ . '\remove_help_tabs', 10, 3 );
30+
31+
// Unregister the core comment widget.
32+
add_action( 'widgets_init', __NAMESPACE__ . '\unregister_comment_widget', 1 );
33+
34+
// Unregister the core comment widget styles.
35+
add_filter( 'show_recent_comments_widget_style', '__return_false' );
36+
37+
// Enqueue editor script.
38+
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\remove_comments_block' );
39+
40+
/**
41+
* Do not check for plugin updates.
42+
*
43+
* @param array|string $value Value of site transient.
44+
* @return array|string
45+
*/
46+
function remove_update_nag( $value ) {
47+
48+
if ( isset( $value->response[ plugin_basename( __FILE__ ) ] )
49+
&& ! empty( $value->response[ plugin_basename( __FILE__ ) ] )
50+
) {
51+
unset( $value->response[ plugin_basename( __FILE__ ) ] );
52+
}
53+
54+
return $value;
55+
}
56+
57+
/**
58+
* Remove admin pages.
59+
*
60+
* @return void
61+
*/
62+
function remove_admin_pages() {
63+
64+
global $pagenow;
65+
66+
if ( in_array(
67+
$pagenow,
68+
array(
69+
'comment.php',
70+
'edit-comments.php',
71+
'moderation.php',
72+
'options-discussion.php',
73+
),
74+
true
75+
) ) {
76+
wp_die(
77+
esc_html__( 'Comments are closed.', 'default' ),
78+
'',
79+
array( 'response' => 403 )
80+
);
81+
exit();
82+
}
83+
}
84+
85+
/**
86+
* Remove admin menu items.
87+
*
88+
* @return void
89+
*/
90+
function remove_menu_items() {
91+
92+
remove_menu_page( 'edit-comments.php' );
93+
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
94+
}
95+
96+
/**
97+
* Remove the commentsdiv meta box.
98+
*
99+
* Removing post type support for comments removes the commentstatusdiv
100+
* and trackbacksdiv, but does not affect commentsdiv as it might still
101+
* be registered if $post->comment_count is bigger than 0.
102+
*
103+
* @todo Find a better place than admin_init to run this hook.
104+
*
105+
* @return void
106+
*/
107+
function remove_commentsdiv_meta_box() {
108+
109+
foreach ( get_post_types() as $post_type ) {
110+
remove_meta_box( 'commentsdiv', $post_type, 'normal' );
111+
}
112+
}
113+
114+
/**
115+
* Remove "Turn comments on or off" from the Welcome Panel.
116+
*
117+
* @return void
118+
*/
119+
function remove_welcome_panel_item() {
120+
121+
?>
122+
<script type="text/javascript">
123+
//<![CDATA[
124+
document.addEventListener( 'DOMContentLoaded', function() {
125+
var el = document.querySelector( '.welcome-comments' );
126+
if ( 'undefined' !== typeof el ) {
127+
el.parentNode.remove();
128+
}
129+
});
130+
//]]>
131+
</script>
132+
<?php
133+
}
134+
135+
/**
136+
* Remove Keyboard Shortcuts options from the profile page.
137+
*
138+
* @return void
139+
*/
140+
function remove_profile_items() {
141+
142+
echo '<style type="text/css">.user-comment-shortcuts-wrap{display:none;}</style>';
143+
}
144+
145+
/**
146+
* Remove the 'Discussion Settings' help tab from the post edit screen.
147+
*
148+
* @return void
149+
*/
150+
function remove_help_tabs() {
151+
152+
$current_screen = get_current_screen();
153+
154+
if ( $current_screen->get_help_tab( 'discussion-settings' ) ) {
155+
$current_screen->remove_help_tab( 'discussion-settings' );
156+
}
157+
}
158+
159+
/**
160+
* Unregister the core comment widget.
161+
*
162+
* @return void
163+
*/
164+
function unregister_comment_widget() {
165+
166+
unregister_widget( 'WP_Widget_Recent_Comments' );
167+
}
168+
169+
/**
170+
* Unregister the core recent comments block.
171+
*
172+
* @return void
173+
*/
174+
function remove_comments_block() {
175+
176+
$script = <<<TAG
177+
(function(){
178+
wp.hooks.addFilter('blocks.registerBlockType', 'uncomment/exclude-blocks', function(settings, name) {
179+
if ( 'core/latest-comments' === name ) {
180+
return Object.assign({}, settings, {
181+
supports: Object.assign({}, settings.supports, {inserter: false})
182+
});
183+
}
184+
return settings;
185+
});
186+
})();
187+
TAG;
188+
189+
wp_add_inline_script( 'wp-blocks', $script, 'after' );
190+
}

includes/composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"authors": [
3+
{
4+
"name": "Barry Ceelen",
5+
"email": "[email protected]",
6+
"homepage": "https://github.com/functionsfile",
7+
"role": "Developer"
8+
}
9+
],
10+
"description": "Your one-stop shop for removing WordPress comment functionality",
11+
"homepage": "https://github.com/functionsfile/uncomment",
12+
"keywords": [
13+
"comments",
14+
"plugin",
15+
"wordpress"
16+
],
17+
"license": "GPL-3.0-or-later",
18+
"name": "functionsfile/uncomment",
19+
"require": {
20+
"composer/installers":"^2.0"
21+
},
22+
"type": "wordpress-muplugin"
23+
}

0 commit comments

Comments
 (0)