Conveniently close or open comments for a post or page with one click from the admin listing of posts.
From the admin listing of posts (‘Edit Posts’) and pages (‘Edit Pages’), a user can close or open comments to any posts to which they have sufficient privileges to make such changes (essentially admins and post authors for their own posts). This is done via an AJAX-powered color-coded indicator. The color-coding gives instant feedback on the current status of the post for comments: green means the post/page is open to comments, red means the post/page is closed to comments. Being AJAX-powered means that the change is submitted in the background after being clicked without requiring a page reload.
This plugin will only function for administrative users in the admin who have JavaScript enabled.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
The plugin exposes one filter for hooking. Such code should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain).
c2c_one_click_close_comments_click_char (filter)
The ‘c2c_one_click_close_comments_click_char’ hook allows you to use an alternative character, string, or markup as the plugin’s indicator in the posts listing tables. It is the character that gets color-coded to indicate if comments are open or close, and the thing to click to toggle the comment open status. You can make use of Dashicons by specifying the desired dashicon’s name (with the “dashicons-” prefix). By default this is the comments dashicon, dashicons-admin-comments
.
Arguments:
dashicons-admin-comments
).Example:
/** * Changes the character used as the one-click link to a bullet (solid circle). * * @param string $char The default character. * @return string */ function custom_one_click_char( $char ) { return '•'; } add_filter( 'c2c_one_click_close_comments_click_char', 'custom_one_click_char' );
one-click-close-comments.zip
inside the plugins directory for your site (typically wp-content/plugins/
)The commenting status link/button is only clickable is you have JavaScript enabled.
Green means the post is currently open for comments; red means the post is not currently open for comments.
You can customize the colors via CSS. .comment-state-1
indicates comments are open. .comment-state-0
indicates comments are closed.
By default, commenting status is represented using the comment bubble dashicon, dashicons-admin-comments
. You can change this by filtering c2c_one_click_close_comments_click_char
. Here’s an example — added to a theme’s functions.php file — to change it to the original bullet (solid circle) character:
add_filter( 'c2c_one_click_close_comments_click_char', function ( $a ) { return "•"; } );
WordPress already includes the interface for you to edit the comment status for a specific post. When editing a post, you’ll find the setting in the “Discussion” section; the checkbox is labeled “Allow Comments”.
The comment status indicator only reflects the value of the “Allow Comments” setting for the post. In most cases, the indicator will accurately reflect the ability for the user to see the comment form and/or submit a comment.
However, other plugins, the theme, or custom code may affect the visitor’s ability to see the comment form when viewing a post and/or may permit or disable commenting at the time the post is shown to them despite the value of the setting. For instance, you could have another plugin installed which disables comments for a post after one year. After a year, that plugin would disable comments in its own way, but the comment status indicator for the post could reflect that comments are open since technically the post’s “Allow Comments” setting would still be enabled.
Highlights:
Details:
get_click_char()
reset()
for resetting memoized variablesspan
only shown for users authorized to toggle comment status.live()
to .on()
span
$and_exit
argument to toggle_comment_status()
to prevent exiting in order to facilitate unit testingadd_post_column()
to be more conciseone-click-close-comments-click-char
Full changelog is available in CHANGELOG.md.