Categories

One Click Close Comments

Author: Scott Reilly
Version: 3.0
First released: 2009-06-12
Last update: 2025-04-17
Compatibility: WP 4.7 – 6.8.3
Download: [ zip ]
Description:

Conveniently close or open comments for a post or page with one click from the admin listing of posts.

Extended Description

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

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the hooks provided by the plugin.

As an overview, these are the hooks provided by the plugin:

  • c2c_one_click_close_comments_click_char : Filter to customize the character, string, or markup used as the indicator used to toggle a post’s comment status.

Find out more at the plugin’s WordPress Plugin Repository page.

Screenshots

Click to see full-size image.

  1. A screenshot of the 'Posts' admin page with the plugin activated. The tooltip (from hovering over a green indicator) reads: "Comments are open. Click to close." Were the mouse to hover over a red indicator, the tooltip would read: "Comments are closed. Click to open."

    A screenshot of the ‘Posts’ admin page with the plugin activated. The tooltip (from hovering over a green indicator) reads: “Comments are open. Click to close.” Were the mouse to hover over a red indicator, the tooltip would read: “Comments are closed. Click to open.”

Installation

  1. Install via the built-in WordPress plugin installer. Or install the plugin code inside the plugins directory for your site (typically /wp-content/plugins/).
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. When on the ‘Edit Posts’ or ‘Edit Pages’ admin pages, click the indicators to toggle the comment status for a post, as necessary.

Release Log

3.0 (2025-04-17)

  • Change: Improve accessibility
    • Change: Use a semantic button instead of a span
    • New: Allow comment state buttons to be navigable by keyboard
    • New: Allow keyboard control by having the spacebar toggle comment state when toggle is focused
  • Change: Reimplement JavaScript to use vanilla JS and discontinue use of jQuery
  • Change: Prevent UI cues indicating comment status might be changeable to users who cannot change them (they never could)
    • Change: Prevent cursor from changing to pointer when comment status cannot be changed
    • Change: Prevent asynchronous JS submission of request to toggle comment status
  • Change: Prevent display and use of comment status indicator for post types that don’t support comments
  • Change: Improve nonce handling
    • Change: Generate a unique nonce per post rather than a generic nonce
    • Change: Store nonce in ‘data-nonce’ attribute rather than ‘id’
    • Change: Use unused private static class variable ‘nonce_field’ as base for nonce field key and value
  • Change: Use result of update to recognize if the comment status didn’t get changed for some reason
  • Change: Ensure AJAX response is only ever an integer
  • Change: Remove any markup potentially introduced in a string translation
  • Fix: Restore changing mouse cursor to a pointer on hover
  • Change: Assign additional generic class of ‘comment_state’ to indicator markup
  • Change: Reset field_title variable in reset() and use reset() during initialization
  • Change: Use update() rather than query() for making SQL update request
  • New: Add inline documentation to class variables
  • New: Add recommendation for Add Admin CSS plugin for adding the CSS suggested in FAQ entry related to customizing indicator
  • New: Add DEVELOPER-DOCS.md and move hooks documentation into it
  • Change: Discontinue unnecessary explicit loading of textdomain
  • Change: Prevent unwarranted PHPCS complaints
  • Change: Tweak some text in the FAQ section, including fixing a typo
  • Change: Note compatibility through WP 6.8+
  • Change: Update copyright date (2025)
  • Change: Note compatibility through PHP 8.3+
  • Change: Tweak installation instruction
  • Change: Reduce number of ‘Tags’ in readme.txt
  • Change: Remove development and testing related files from release packaging
  • Unit tests:
    • Fix: Allow tests to run against current versions of WordPress
    • Hardening: Prevent direct web access to bootstrap.php
    • Change: Restructure unit test directories
      • Change: Move bin/ into tests/
      • Change: Move tests/bootstrap.php into tests/phpunit/
      • Change: Move tests/test-one-click-close-comments.php into tests/phpunit/tests/
    • Change: Remove ‘test-‘ prefix from unit test files
    • Change: In bootstrap, store path to plugin file constant
    • Change: In bootstrap, add backcompat for PHPUnit pre-v6.0
    • Change: Rename phpunit.xml to phpunit.xml.dist per best practices
    • New: Add composer.json for PHPUnit Polyfill dependency
    • Change: Explicitly define return type for overridden methods
  • New: Add a few more possible TODO items

2.7.1 (2021-04-01)

  • New: Add a unit test
  • Change: Note compatibility through WP 5.7+
  • Change: Update copyright date (2021)

2.7 (2020-08-02)

  • This recommended release updates its JavaScript, streamlines markup output, adds unit testing, adds a TODO.md file, updates a few URLs to be HTTPS, notes compatibility through 5.4+, and other minor behind-the-scenes improvements.

Details:

  • New: Extract code for determining click character into new get_click_char()
  • New: Add unit tests
  • New: Add reset() for resetting memoized variables
  • New: Add TODO.md and move existing TODO list from top of main plugin file into it (and add items to it)
  • Change: Improve output of markup
    • Remove encompassing span only shown for users authorized to toggle comment status
    • Add ‘title’ attribute to primary span to indicate current state
    • Change text to not indicate that comment staus can be toggled when user does not have that capability
  • Change: Update JavaScript
    • Change: Migrate use of deprecated .live() to .on()
    • Change: Handle removal of a previously encapsulating span
    • Change: Remove unused code
    • Change: Update code syntax
  • Change: Allow class to be defined even when loaded outside the admin
  • Change: Return ‘-1’ to Ajax requests that don’t result in the comment status being toggled
  • Change: Add $and_exit argument to toggle_comment_status() to prevent exiting in order to facilitate unit testing
  • Change: Refactor add_post_column() to be more concise
  • Change: Add inline docs for deprecated filter one-click-close-comments-click-char
  • Change: Switch to use of strict equality operator instead of simple equality operator
  • Change: Note compatibility through WP 5.4+
  • Change: Update links to coffee2code.com to be HTTPS

Copyright & Disclaimer

Copyright © 2009-2026 by Scott Reilly (aka coffee2code)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Discussion / Support

Have any questions, comments, or suggestions? Please provide them via the plugin’s WordPress.org support forum. I’ll do my best to reply in a timely fashion and help as best I can.

Unfortunately, I cannot provide guaranteed support, nor do I provide support via any other means.

Was this plugin useful useful to you? Consider giving it a rating. If you’re inclined to give it a poor rating, please first post to the support forum to give me a chance to address or explain the situation.

4 replies on “One Click Close Comments”