Changeset 2125992
- Timestamp:
- 07/20/2019 03:16:53 AM (6 years ago)
- Location:
- disable-comments/trunk
- Files:
-
- 6 edited
-
disable-comments.php (modified) (27 diffs)
-
includes/comments-template.php (modified) (1 diff)
-
includes/settings-page.php (modified) (4 diffs)
-
includes/tools-page.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
disable-comments/trunk/disable-comments.php
r2042603 r2125992 4 4 Plugin URI: https://wordpress.org/plugins/disable-comments/ 5 5 Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. 6 Version: 1. 9.06 Version: 1.10.0 7 7 Author: Samir Shah 8 8 Author URI: http://www.rayofsolaris.net/ … … 12 12 */ 13 13 14 if ( !defined( 'ABSPATH' ) )14 if ( ! defined( 'ABSPATH' ) ) { 15 15 exit; 16 } 16 17 17 18 class Disable_Comments { 18 const DB_VERSION = 6;19 const DB_VERSION = 6; 19 20 private static $instance = null; 20 21 private $options; … … 34 35 35 36 // Load options 36 if ( $this->networkactive ) {37 if ( $this->networkactive ) { 37 38 $this->options = get_site_option( 'disable_comments_options', array() ); 38 } 39 else { 39 } else { 40 40 $this->options = get_option( 'disable_comments_options', array() ); 41 41 } 42 42 43 43 // If it looks like first run, check compat 44 if ( empty( $this->options ) ) {44 if ( empty( $this->options ) ) { 45 45 $this->check_compatibility(); 46 46 } … … 64 64 private function check_db_upgrades() { 65 65 $old_ver = isset( $this->options['db_version'] ) ? $this->options['db_version'] : 0; 66 if ( $old_ver < self::DB_VERSION ) {67 if ( $old_ver < 2 ) {66 if ( $old_ver < self::DB_VERSION ) { 67 if ( $old_ver < 2 ) { 68 68 // upgrade options from version 0.2.1 or earlier to 0.3 69 69 $this->options['disabled_post_types'] = get_option( 'disable_comments_post_types', array() ); 70 70 delete_option( 'disable_comments_post_types' ); 71 71 } 72 if ( $old_ver < 5 ) {72 if ( $old_ver < 5 ) { 73 73 // simple is beautiful - remove multiple settings in favour of one 74 74 $this->options['remove_everywhere'] = isset( $this->options['remove_admin_menu_comments'] ) ? $this->options['remove_admin_menu_comments'] : false; 75 foreach( array( 'remove_admin_menu_comments', 'remove_admin_bar_comments', 'remove_recent_comments', 'remove_discussion', 'remove_rc_widget' ) as $v ) 76 unset( $this->options[$v] ); 77 } 78 79 foreach( array( 'remove_everywhere', 'extra_post_types' ) as $v ) { 80 if( !isset( $this->options[$v] ) ) { 81 $this->options[$v] = false; 75 foreach ( array( 'remove_admin_menu_comments', 'remove_admin_bar_comments', 'remove_recent_comments', 'remove_discussion', 'remove_rc_widget' ) as $v ) { 76 unset( $this->options[ $v ] ); 77 } 78 } 79 80 foreach ( array( 'remove_everywhere', 'extra_post_types' ) as $v ) { 81 if ( ! isset( $this->options[ $v ] ) ) { 82 $this->options[ $v ] = false; 82 83 } 83 84 } … … 89 90 90 91 private function update_options() { 91 if ( $this->networkactive ) {92 if ( $this->networkactive ) { 92 93 update_site_option( 'disable_comments_options', $this->options ); 93 } 94 else { 94 } else { 95 95 update_option( 'disable_comments_options', $this->options ); 96 96 } … … 103 103 $types = $this->options['disabled_post_types']; 104 104 // Not all extra_post_types might be registered on this particular site 105 if ( $this->networkactive ) {106 foreach ( (array) $this->options['extra_post_types'] as $extra ) {107 if ( post_type_exists( $extra ) ) {105 if ( $this->networkactive ) { 106 foreach ( (array) $this->options['extra_post_types'] as $extra ) { 107 if ( post_type_exists( $extra ) ) { 108 108 $types[] = $extra; 109 109 } … … 122 122 private function init_filters() { 123 123 // These need to happen now 124 if ( $this->options['remove_everywhere'] ) {124 if ( $this->options['remove_everywhere'] ) { 125 125 add_action( 'widgets_init', array( $this, 'disable_rc_widget' ) ); 126 126 add_filter( 'wp_headers', array( $this, 'filter_wp_headers' ) ); 127 add_action( 'template_redirect', array( $this, 'filter_query' ), 9 ); // before redirect_canonical127 add_action( 'template_redirect', array( $this, 'filter_query' ), 9 ); // before redirect_canonical 128 128 129 129 // Admin bar filtering has to happen here since WP 3.6 … … 135 135 add_action( 'plugins_loaded', array( $this, 'register_text_domain' ) ); 136 136 add_action( 'wp_loaded', array( $this, 'init_wploaded_filters' ) ); 137 138 // Disable "Latest comments" block in Gutenberg 139 add_action( 'admin_enqueue_scripts', array( $this, 'filter_gutenberg_blocks') ); 137 140 } 138 141 139 142 public function register_text_domain() { 140 load_plugin_textdomain( 'disable-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );141 } 142 143 public function init_wploaded_filters() {143 load_plugin_textdomain( 'disable-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 144 } 145 146 public function init_wploaded_filters() { 144 147 $disabled_post_types = $this->get_disabled_post_types(); 145 if ( !empty( $disabled_post_types ) ) {146 foreach ( $disabled_post_types as $type ) {148 if ( ! empty( $disabled_post_types ) ) { 149 foreach ( $disabled_post_types as $type ) { 147 150 // we need to know what native support was for later 148 if ( post_type_supports( $type, 'comments' ) ) {151 if ( post_type_supports( $type, 'comments' ) ) { 149 152 $this->modified_types[] = $type; 150 153 remove_post_type_support( $type, 'comments' ); … … 155 158 add_filter( 'comments_open', array( $this, 'filter_comment_status' ), 20, 2 ); 156 159 add_filter( 'pings_open', array( $this, 'filter_comment_status' ), 20, 2 ); 157 }158 elseif( is_admin() && !$this->options['remove_everywhere'] ) {160 add_filter( 'get_comments_number', array( $this, 'filter_comments_number' ), 20, 2 ); 161 } elseif ( is_admin() && ! $this->options['remove_everywhere'] ) { 159 162 // It is possible that $disabled_post_types is empty if other 160 163 // plugins have disabled comments. Hence we also check for … … 165 168 166 169 // Filters for the admin only 167 if ( is_admin() ) {168 if ( $this->networkactive ) {170 if ( is_admin() ) { 171 if ( $this->networkactive ) { 169 172 add_action( 'network_admin_menu', array( $this, 'settings_menu' ) ); 170 173 add_action( 'network_admin_menu', array( $this, 'tools_menu' ) ); 171 add_filter( 'network_admin_plugin_action_links', array( $this, 'plugin_actions_links'), 10, 2 ); 172 } 173 else { 174 add_filter( 'network_admin_plugin_action_links', array( $this, 'plugin_actions_links' ), 10, 2 ); 175 } else { 174 176 add_action( 'admin_menu', array( $this, 'settings_menu' ) ); 175 177 add_action( 'admin_menu', array( $this, 'tools_menu' ) ); 176 add_filter( 'plugin_action_links', array( $this, 'plugin_actions_links' ), 10, 2 );177 if ( is_multisite() )// We're on a multisite setup, but the plugin isn't network activated.178 add_filter( 'plugin_action_links', array( $this, 'plugin_actions_links' ), 10, 2 ); 179 if ( is_multisite() ) { // We're on a multisite setup, but the plugin isn't network activated. 178 180 register_deactivation_hook( __FILE__, array( $this, 'single_site_deactivate' ) ); 181 } 179 182 } 180 183 … … 182 185 add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 ); 183 186 184 if ( $this->options['remove_everywhere'] ) {185 add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible187 if ( $this->options['remove_everywhere'] ) { 188 add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible 186 189 add_action( 'admin_print_styles-index.php', array( $this, 'admin_css' ) ); 187 190 add_action( 'admin_print_styles-profile.php', array( $this, 'admin_css' ) ); … … 194 197 add_action( 'template_redirect', array( $this, 'check_comment_template' ) ); 195 198 196 if ( $this->options['remove_everywhere'] ) {199 if ( $this->options['remove_everywhere'] ) { 197 200 add_filter( 'feed_links_show_comments_feed', '__return_false' ); 198 201 } … … 206 209 */ 207 210 public function check_comment_template() { 208 if ( is_singular() && ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( get_post_type() ) ) ) {209 if ( !defined( 'DISABLE_COMMENTS_REMOVE_COMMENTS_TEMPLATE' ) || DISABLE_COMMENTS_REMOVE_COMMENTS_TEMPLATE == true ) {211 if ( is_singular() && ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( get_post_type() ) ) ) { 212 if ( ! defined( 'DISABLE_COMMENTS_REMOVE_COMMENTS_TEMPLATE' ) || DISABLE_COMMENTS_REMOVE_COMMENTS_TEMPLATE == true ) { 210 213 // Kill the comments template. 211 214 add_filter( 'comments_template', array( $this, 'dummy_comments_template' ), 20 ); … … 235 238 */ 236 239 public function filter_query() { 237 if ( is_comment_feed() ) {240 if ( is_comment_feed() ) { 238 241 wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) ); 239 242 } … … 244 247 */ 245 248 public function filter_admin_bar() { 246 if ( is_admin_bar_showing() ) {249 if ( is_admin_bar_showing() ) { 247 250 // Remove comments links from admin bar 248 251 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); 249 if ( is_multisite() ) {252 if ( is_multisite() ) { 250 253 add_action( 'admin_bar_menu', array( $this, 'remove_network_comment_links' ), 500 ); 251 254 } … … 253 256 } 254 257 258 /** 259 * Determines if scripts should be enqueued 260 */ 261 public function filter_gutenberg_blocks($hook) { 262 if (!in_array($hook, array('post-new.php', 'post.php'), true)) { 263 return; 264 } 265 266 if ($this->options['remove_everywhere']) { 267 return $this->disable_comments_script(); 268 } 269 270 global $post; 271 272 if (isset($post->post_type) && in_array($post->post_type, $this->get_disabled_post_types(), true)) { 273 return $this->disable_comments_script(); 274 } 275 } 276 277 /** 278 * Enqueues scripts 279 */ 280 public function disable_comments_script() { 281 wp_enqueue_script('disable-comments-gutenberg', plugin_dir_url(__FILE__) . 'assets/disable-comments.js', array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' )); 282 wp_localize_script('disable-comments-gutenberg', 'disable_comments', array( 283 'disabled_blocks' => array('core/latest-comments'), 284 )); 285 } 286 255 287 /* 256 288 * Remove comment links from the admin bar in a multisite network. 257 289 */ 258 290 public function remove_network_comment_links( $wp_admin_bar ) { 259 if ( $this->networkactive && is_user_logged_in() ) {260 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {291 if ( $this->networkactive && is_user_logged_in() ) { 292 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { 261 293 $wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' ); 262 294 } 263 } 264 else { 295 } else { 265 296 // We have no way to know whether the plugin is active on other sites, so only remove this one 266 297 $wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' ); … … 270 301 public function discussion_notice() { 271 302 $disabled_post_types = $this->get_disabled_post_types(); 272 if ( get_current_screen()->id == 'options-discussion' && !empty( $disabled_post_types ) ) {303 if ( get_current_screen()->id == 'options-discussion' && ! empty( $disabled_post_types ) ) { 273 304 $names = array(); 274 foreach( $disabled_post_types as $type ) 275 $names[$type] = get_post_type_object( $type )->labels->name; 305 foreach ( $disabled_post_types as $type ) { 306 $names[ $type ] = get_post_type_object( $type )->labels->name; 307 } 276 308 277 309 echo '<div class="notice notice-warning"><p>' . sprintf( __( 'Note: The <em>Disable Comments</em> plugin is currently active, and comments are completely disabled on: %s. Many of the settings below will not be applicable for those post types.', 'disable-comments' ), implode( __( ', ' ), $names ) ) . '</p></div>'; … … 283 315 */ 284 316 private function settings_page_url() { 285 $base = $this->networkactive ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );317 $base = $this->networkactive ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' ); 286 318 return add_query_arg( 'page', 'disable_comments_settings', $base ); 287 319 } … … 291 323 */ 292 324 private function tools_page_url() { 293 $base = $this->networkactive ? network_admin_url( 'settings.php' ) : admin_url( 'tools.php' );325 $base = $this->networkactive ? network_admin_url( 'settings.php' ) : admin_url( 'tools.php' ); 294 326 return add_query_arg( 'page', 'disable_comments_tools', $base ); 295 327 } 296 328 297 public function setup_notice() {298 if ( strpos( get_current_screen()->id, 'settings_page_disable_comments_settings' ) === 0 )329 public function setup_notice() { 330 if ( strpos( get_current_screen()->id, 'settings_page_disable_comments_settings' ) === 0 ) { 299 331 return; 332 } 300 333 $hascaps = $this->networkactive ? is_network_admin() && current_user_can( 'manage_network_plugins' ) : current_user_can( 'manage_options' ); 301 if ( $hascaps ) {302 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>';303 } 304 } 305 306 public function filter_admin_menu() {334 if ( $hascaps ) { 335 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>'; 336 } 337 } 338 339 public function filter_admin_menu() { 307 340 global $pagenow; 308 341 309 if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' ) 342 if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' ) { 310 343 wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) ); 344 } 311 345 312 346 remove_menu_page( 'edit-comments.php' ); 313 347 314 348 if ( ! $this->discussion_settings_allowed() ) { 315 if ( $pagenow == 'options-discussion.php' ) 349 if ( $pagenow == 'options-discussion.php' ) { 316 350 wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) ); 351 } 317 352 318 353 remove_submenu_page( 'options-general.php', 'options-discussion.php' ); … … 320 355 } 321 356 322 public function filter_dashboard() {357 public function filter_dashboard() { 323 358 remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); 324 359 } 325 360 326 public function admin_css() {361 public function admin_css() { 327 362 echo '<style> 328 363 #dashboard_right_now .comment-count, … … 336 371 } 337 372 338 public function filter_existing_comments( $comments, $post_id) {373 public function filter_existing_comments( $comments, $post_id ) { 339 374 $post = get_post( $post_id ); 340 375 return ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( $post->post_type ) ) ? array() : $comments; … … 344 379 $post = get_post( $post_id ); 345 380 return ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( $post->post_type ) ) ? false : $open; 381 } 382 383 public function filter_comments_number( $count, $post_id ) { 384 $post = get_post( $post_id ); 385 return ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( $post->post_type ) ) ? 0 : $count; 346 386 } 347 387 … … 350 390 // The widget has added a style action when it was constructed - which will 351 391 // still fire even if we now unregister the widget... so filter that out 352 add_filter( 'show_recent_comments_widget_style', '__return_false' );392 add_filter( 'show_recent_comments_widget_style', '__return_false' ); 353 393 } 354 394 … … 364 404 /** 365 405 * Add links to Settings page 366 */406 */ 367 407 public function plugin_actions_links( $links, $file ) { 368 408 static $plugin; 369 409 $plugin = plugin_basename( __FILE__ ); 370 if ( $file == $plugin && current_user_can('manage_options') ) {410 if ( $file == $plugin && current_user_can( 'manage_options' ) ) { 371 411 array_unshift( 372 412 $links, … … 381 421 public function settings_menu() { 382 422 $title = _x( 'Disable Comments', 'settings menu title', 'disable-comments' ); 383 if ( $this->networkactive )423 if ( $this->networkactive ) { 384 424 add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'disable_comments_settings', array( $this, 'settings_page' ) ); 385 else425 } else { 386 426 add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'disable_comments_settings', array( $this, 'settings_page' ) ); 427 } 387 428 } 388 429 … … 393 434 public function tools_menu() { 394 435 $title = __( 'Delete Comments', 'disable-comments' ); 395 if ( $this->networkactive )436 if ( $this->networkactive ) { 396 437 add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'disable_comments_tools', array( $this, 'tools_page' ) ); 397 else438 } else { 398 439 add_submenu_page( 'tools.php', $title, $title, 'manage_options', 'disable_comments_tools', array( $this, 'tools_page' ) ); 440 } 399 441 } 400 442 … … 404 446 405 447 private function discussion_settings_allowed() { 406 if ( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) {448 if ( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) { 407 449 return true; 408 450 } -
disable-comments/trunk/includes/comments-template.php
r1211200 r2125992 1 1 <?php 2 /* Dummy comments template file. 2 /* 3 Dummy comments template file. 3 4 * This replaces the theme's comment template when comments are disabled everywhere 4 5 */ -
disable-comments/trunk/includes/settings-page.php
r2042603 r2125992 1 1 <?php 2 if ( !defined( 'ABSPATH' ) ) {2 if ( ! defined( 'ABSPATH' ) ) { 3 3 exit; 4 4 } 5 5 6 6 $typeargs = array( 'public' => true ); 7 if ( $this->networkactive ) {8 $typeargs['_builtin'] = true; // stick to known types for network7 if ( $this->networkactive ) { 8 $typeargs['_builtin'] = true; // stick to known types for network 9 9 } 10 10 $types = get_post_types( $typeargs, 'objects' ); 11 foreach( array_keys( $types ) as $type ) { 12 if( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) // the type doesn't support comments anyway 13 unset( $types[$type] ); 11 foreach ( array_keys( $types ) as $type ) { 12 if ( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) { // the type doesn't support comments anyway 13 unset( $types[ $type ] ); 14 } 14 15 } 15 16 … … 18 19 $this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' ); 19 20 20 if ( $this->options['remove_everywhere'] )21 if ( $this->options['remove_everywhere'] ) { 21 22 $disabled_post_types = array_keys( $types ); 22 else 23 $disabled_post_types = empty( $_POST['disabled_types'] ) ? array() : (array) $_POST['disabled_types']; 23 } else { 24 $disabled_post_types = empty( $_POST['disabled_types'] ) ? array() : (array) $_POST['disabled_types']; 25 } 24 26 25 27 $disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) ); … … 28 30 29 31 // Extra custom post types 30 if ( $this->networkactive && !empty( $_POST['extra_post_types'] ) ) {31 $extra_post_types = array_filter( array_map( 'sanitize_key', explode( ',', $_POST['extra_post_types'] ) ) );32 $this->options['extra_post_types'] = array_diff( $extra_post_types, array_keys( $types ) ); // Make sure we don't double up builtins32 if ( $this->networkactive && ! empty( $_POST['extra_post_types'] ) ) { 33 $extra_post_types = array_filter( array_map( 'sanitize_key', explode( ',', $_POST['extra_post_types'] ) ) ); 34 $this->options['extra_post_types'] = array_diff( $extra_post_types, array_keys( $types ) ); // Make sure we don't double up builtins 33 35 } 34 36 … … 40 42 <style> .indent {padding-left: 2em} </style> 41 43 <div class="wrap"> 42 <h1><?php _ex( 'Disable Comments', 'settings page title', 'disable-comments' )?></h1>44 <h1><?php _ex( 'Disable Comments', 'settings page title', 'disable-comments' ); ?></h1> 43 45 <?php 44 if( $this->networkactive ) 45 echo '<div class="updated"><p>' . __( '<em>Disable Comments</em> is Network Activated. The settings below will affect <strong>all sites</strong> in this network.', 'disable-comments') . '</p></div>'; 46 if( WP_CACHE ) 47 echo '<div class="updated"><p>' . __( "It seems that a caching/performance plugin is active on this site. Please manually invalidate that plugin's cache after making any changes to the settings below.", 'disable-comments') . '</p></div>'; 46 if ( $this->networkactive ) { 47 echo '<div class="updated"><p>' . __( '<em>Disable Comments</em> is Network Activated. The settings below will affect <strong>all sites</strong> in this network.', 'disable-comments' ) . '</p></div>'; 48 } 49 if ( WP_CACHE ) { 50 echo '<div class="updated"><p>' . __( "It seems that a caching/performance plugin is active on this site. Please manually invalidate that plugin's cache after making any changes to the settings below.", 'disable-comments' ) . '</p></div>'; 51 } 48 52 ?> 49 53 <form action="" method="post" id="disable-comments"> 50 54 <ul> 51 <li><label for="remove_everywhere"><input type="radio" id="remove_everywhere" name="mode" value="remove_everywhere" <?php checked( $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'Everywhere', 'disable-comments') ?></strong>: <?php _e( 'Disable all comment-related controls and settings in WordPress.', 'disable-comments')?></label>52 <p class="indent"><?php printf( __( '% s: This option is global and will affect your entire site. Use it only if you want to disable comments <em>everywhere</em>. A complete description of what this option does is <a href="%s" target="_blank">available here</a>.', 'disable-comments' ), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>', 'https://wordpress.org/plugins/disable-comments/other_notes/' ); ?></p>55 <li><label for="remove_everywhere"><input type="radio" id="remove_everywhere" name="mode" value="remove_everywhere" <?php checked( $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'Everywhere', 'disable-comments' ); ?></strong>: <?php _e( 'Disable all comment-related controls and settings in WordPress.', 'disable-comments' ); ?></label> 56 <p class="indent"><?php printf( __( '%1$s: This option is global and will affect your entire site. Use it only if you want to disable comments <em>everywhere</em>. A complete description of what this option does is <a href="%2$s" target="_blank">available here</a>.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>', 'https://wordpress.org/plugins/disable-comments/other_notes/' ); ?></p> 53 57 </li> 54 <li><label for="selected_types"><input type="radio" id="selected_types" name="mode" value="selected_types" <?php checked( ! $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'On certain post types', 'disable-comments')?></strong>:</label>58 <li><label for="selected_types"><input type="radio" id="selected_types" name="mode" value="selected_types" <?php checked( ! $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'On certain post types', 'disable-comments' ); ?></strong>:</label> 55 59 <p></p> 56 60 <ul class="indent" id="listoftypes"> 57 <?php foreach( $types as $k => $v ) echo "<li><label for='post-type-$k'><input type='checkbox' name='disabled_types[]' value='$k' ". checked( in_array( $k, $this->options['disabled_post_types'] ), true, false ) ." id='post-type-$k'> {$v->labels->name}</label></li>";?> 61 <?php 62 foreach ( $types as $k => $v ) { 63 echo "<li><label for='post-type-$k'><input type='checkbox' name='disabled_types[]' value='$k' " . checked( in_array( $k, $this->options['disabled_post_types'] ), true, false ) . " id='post-type-$k'> {$v->labels->name}</label></li>";} 64 ?> 58 65 </ul> 59 <?php if ( $this->networkactive ) :?>66 <?php if ( $this->networkactive ) : ?> 60 67 <p class="indent" id="extratypes"><?php _e( 'Only the built-in post types appear above. If you want to disable comments on other custom post types on the entire network, you can supply a comma-separated list of post types below (use the slug that identifies the post type).', 'disable-comments' ); ?> 61 68 <br /><label><?php _e( 'Custom post types:', 'disable-comments' ); ?> <input type="text" name="extra_post_types" size="30" value="<?php echo implode( ', ', (array) $this->options['extra_post_types'] ); ?>" /></label></p> 62 69 <?php endif; ?> 63 <p class="indent"><?php _e( 'Disabling comments will also disable trackbacks and pingbacks. All comment-related fields will also be hidden from the edit/quick-edit screens of the affected posts. These settings cannot be overridden for individual posts.', 'disable-comments' )?></p>70 <p class="indent"><?php _e( 'Disabling comments will also disable trackbacks and pingbacks. All comment-related fields will also be hidden from the edit/quick-edit screens of the affected posts. These settings cannot be overridden for individual posts.', 'disable-comments' ); ?></p> 64 71 </li> 65 72 </ul> 66 73 67 74 <?php wp_nonce_field( 'disable-comments-admin' ); ?> 68 <p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments' )?>"></p>75 <p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments' ); ?>"></p> 69 76 </form> 70 77 </div> -
disable-comments/trunk/includes/tools-page.php
r2042603 r2125992 1 1 <?php 2 if ( !defined( 'ABSPATH' ) ) {2 if ( ! defined( 'ABSPATH' ) ) { 3 3 exit; 4 4 } 5 5 ?> 6 6 <div class="wrap"> 7 <h1><?php _e( 'Delete Comments', 'disable-comments' )?></h1>7 <h1><?php _e( 'Delete Comments', 'disable-comments' ); ?></h1> 8 8 <?php 9 9 10 10 global $wpdb; 11 $comments_count = $wpdb->get_var("SELECT count(comment_id) from $wpdb->comments"); 12 if ( $comments_count <= 0 ) { ?> 13 <p><strong><?php _e( 'No comments available for deletion.', 'disable-comments') ?></strong></p> 11 $comments_count = $wpdb->get_var( "SELECT count(comment_id) from $wpdb->comments" ); 12 if ( $comments_count <= 0 ) { 13 ?> 14 <p><strong><?php _e( 'No comments available for deletion.', 'disable-comments' ); ?></strong></p> 14 15 </div> 15 <?php16 <?php 16 17 return; 17 18 } 18 19 19 20 $typeargs = array( 'public' => true ); 20 if ( $this->networkactive ) {21 $typeargs['_builtin'] = true; // stick to known types for network21 if ( $this->networkactive ) { 22 $typeargs['_builtin'] = true; // stick to known types for network 22 23 } 23 24 $types = get_post_types( $typeargs, 'objects' ); 24 foreach( array_keys( $types ) as $type ) { 25 if( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) // the type doesn't support comments anyway 26 unset( $types[$type] ); 25 foreach ( array_keys( $types ) as $type ) { 26 if ( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) { // the type doesn't support comments anyway 27 unset( $types[ $type ] ); 28 } 27 29 } 28 30 … … 30 32 check_admin_referer( 'delete-comments-admin' ); 31 33 32 if ( $_POST['delete_mode'] == 'delete_everywhere' ) {33 if ( $wpdb->query( "TRUNCATE $wpdb->commentmeta" ) != FALSE ){34 if ( $wpdb->query( "TRUNCATE $wpdb->comments" ) != FALSE ){35 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0" );36 $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );37 $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );38 echo "<p style='color:green'><strong>" . __( 'All comments have been deleted.', 'disable-comments' ) . "</strong></p>";39 } else {40 echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . "</strong></p>";41 }42 } else {43 echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . "</strong></p>";44 }34 if ( $_POST['delete_mode'] == 'delete_everywhere' ) { 35 if ( $wpdb->query( "TRUNCATE $wpdb->commentmeta" ) != false ) { 36 if ( $wpdb->query( "TRUNCATE $wpdb->comments" ) != false ) { 37 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0" ); 38 $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" ); 39 $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" ); 40 echo "<p style='color:green'><strong>" . __( 'All comments have been deleted.', 'disable-comments' ) . '</strong></p>'; 41 } else { 42 echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . '</strong></p>'; 43 } 44 } else { 45 echo "<p style='color:red'><strong>" . __( 'Internal error occured. Please try again later.', 'disable-comments' ) . '</strong></p>'; 46 } 45 47 } else { 46 $delete_post_types = empty( $_POST['delete_types'] ) ? array() : (array) $_POST['delete_types'];48 $delete_post_types = empty( $_POST['delete_types'] ) ? array() : (array) $_POST['delete_types']; 47 49 $delete_post_types = array_intersect( $delete_post_types, array_keys( $types ) ); 48 50 49 51 // Extra custom post types 50 if ( $this->networkactive && !empty( $_POST['delete_extra_post_types'] ) ) {52 if ( $this->networkactive && ! empty( $_POST['delete_extra_post_types'] ) ) { 51 53 $delete_extra_post_types = array_filter( array_map( 'sanitize_key', explode( ',', $_POST['delete_extra_post_types'] ) ) ); 52 $delete_extra_post_types = array_diff( $delete_extra_post_types, array_keys( $types ) ); // Make sure we don't double up builtins53 $delete_post_types = array_merge($delete_post_types, $delete_extra_post_types);54 $delete_extra_post_types = array_diff( $delete_extra_post_types, array_keys( $types ) ); // Make sure we don't double up builtins 55 $delete_post_types = array_merge( $delete_post_types, $delete_extra_post_types ); 54 56 } 55 57 … … 57 59 // Loop through post_types and remove comments/meta and set posts comment_count to 0 58 60 foreach ( $delete_post_types as $delete_post_type ) { 59 $wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );60 $wpdb->query( "DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" );61 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" );61 $wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" ); 62 $wpdb->query( "DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'" ); 63 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" ); 62 64 63 $post_type_object = get_post_type_object( $delete_post_type );64 $post_type_label= $post_type_object ? $post_type_object->labels->name : $delete_post_type;65 echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %s.', 'disable-comments' ), $post_type_label ) . "</strong></p>";65 $post_type_object = get_post_type_object( $delete_post_type ); 66 $post_type_label = $post_type_object ? $post_type_object->labels->name : $delete_post_type; 67 echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %s.', 'disable-comments' ), $post_type_label ) . '</strong></p>'; 66 68 } 67 69 68 $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );69 $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );70 $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" ); 71 $wpdb->query( "OPTIMIZE TABLE $wpdb->comments" ); 70 72 71 echo "<h4 style='color:green'><strong>" . __( 'Comment Deletion Complete', 'disable-comments') . "</strong></h4>";73 echo "<h4 style='color:green'><strong>" . __( 'Comment Deletion Complete', 'disable-comments' ) . '</strong></h4>'; 72 74 } 73 74 75 } 75 76 76 $comments_count = $wpdb->get_var("SELECT count(comment_id) from $wpdb->comments"); 77 if ( $comments_count <= 0 ) { ?> 78 <p><strong><?php _e( 'No comments available for deletion.', 'disable-comments') ?></strong></p> 77 $comments_count = $wpdb->get_var( "SELECT count(comment_id) from $wpdb->comments" ); 78 if ( $comments_count <= 0 ) { 79 ?> 80 <p><strong><?php _e( 'No comments available for deletion.', 'disable-comments' ); ?></strong></p> 79 81 </div> 80 <?php82 <?php 81 83 return; 82 84 } 83 84 85 } 85 86 ?> 86 87 <form action="" method="post" id="delete-comments"> 87 88 <ul> 88 <li><label for="delete_everywhere"><input type="radio" id="delete_everywhere" name="delete_mode" value="delete_everywhere" <?php checked( $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'Everywhere', 'disable-comments') ?></strong>: <?php _e( 'Delete all comments in WordPress.', 'disable-comments')?></label>89 <p class="indent"><?php printf( __( '%s: This function and will affect your entire site. Use it only if you want to delete comments <em>everywhere</em>.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments') . '</strong>' ); ?></p>89 <li><label for="delete_everywhere"><input type="radio" id="delete_everywhere" name="delete_mode" value="delete_everywhere" <?php checked( $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'Everywhere', 'disable-comments' ); ?></strong>: <?php _e( 'Delete all comments in WordPress.', 'disable-comments' ); ?></label> 90 <p class="indent"><?php printf( __( '%s: This function and will affect your entire site. Use it only if you want to delete comments <em>everywhere</em>.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>' ); ?></p> 90 91 </li> 91 <li><label for="selected_delete_types"><input type="radio" id="selected_delete_types" name="delete_mode" value="selected_delete_types" <?php checked( ! $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'For certain post types', 'disable-comments')?></strong>:</label>92 <li><label for="selected_delete_types"><input type="radio" id="selected_delete_types" name="delete_mode" value="selected_delete_types" <?php checked( ! $this->options['remove_everywhere'] ); ?> /> <strong><?php _e( 'For certain post types', 'disable-comments' ); ?></strong>:</label> 92 93 <p></p> 93 94 <ul class="indent" id="listofdeletetypes"> 94 <?php foreach( $types as $k => $v ) echo "<li><label for='post-type-$k'><input type='checkbox' name='delete_types[]' value='$k' ". checked( in_array( $k, $this->options['disabled_post_types'] ), true, false ) ." id='post-type-$k'> {$v->labels->name}</label></li>";?> 95 <?php 96 foreach ( $types as $k => $v ) { 97 echo "<li><label for='post-type-$k'><input type='checkbox' name='delete_types[]' value='$k' " . checked( in_array( $k, $this->options['disabled_post_types'] ), true, false ) . " id='post-type-$k'> {$v->labels->name}</label></li>";} 98 ?> 95 99 </ul> 96 <?php if ( $this->networkactive ) :?>100 <?php if ( $this->networkactive ) : ?> 97 101 <p class="indent" id="extradeletetypes"><?php _e( 'Only the built-in post types appear above. If you want to disable comments on other custom post types on the entire network, you can supply a comma-separated list of post types below (use the slug that identifies the post type).', 'disable-comments' ); ?> 98 102 <br /><label><?php _e( 'Custom post types:', 'disable-comments' ); ?> <input type="text" name="delete_extra_post_types" size="30" value="<?php echo implode( ', ', (array) $this->options['extra_post_types'] ); ?>" /></label></p> 99 103 <?php endif; ?> 100 <p class="indent"><?php printf( __( '%s: Deleting comments will remove existing comment entries in the database and cannot be reverted without a database backup.', 'disable-comments' ), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>' ); ?></p>104 <p class="indent"><?php printf( __( '%s: Deleting comments will remove existing comment entries in the database and cannot be reverted without a database backup.', 'disable-comments' ), '<strong style="color: #900">' . __( 'Warning', 'disable-comments' ) . '</strong>' ); ?></p> 101 105 </li> 102 106 </ul> … … 104 108 <?php wp_nonce_field( 'delete-comments-admin' ); ?> 105 109 <h4><?php _e( 'Total Comments:', 'disable-comments' ); ?> <?php echo $comments_count; ?></h4> 106 <p class="submit"><input class="button-primary" type="submit" name="delete" value="<?php _e( 'Delete Comments', 'disable-comments' )?>"></p>110 <p class="submit"><input class="button-primary" type="submit" name="delete" value="<?php _e( 'Delete Comments', 'disable-comments' ); ?>"></p> 107 111 </form> 108 112 </div> -
disable-comments/trunk/readme.txt
r2042603 r2125992 1 1 === Disable Comments === 2 Contributors: solarissmoke 2 Contributors: solarissmoke, garrett-eclipse 3 3 Donate link: http://www.rayofsolaris.net/donate/ 4 4 Tags: comments, disable, global 5 5 Requires at least: 5.0 6 Tested up to: 5. 16 Tested up to: 5.3 7 7 Stable tag: trunk 8 8 … … 47 47 = I want to delete comments from my database. What do I do? = 48 48 49 Go to the settings page for the disable comments plugin and utlize the Delete Comments tool to delete all comments or according to the specified post types from your database.49 Go to the tools page for the Disable Comments plugin and utlize the Delete Comments tool to delete all comments or according to the specified post types from your database. 50 50 51 51 == Details == … … 75 75 == Changelog == 76 76 77 = 1.10.0 = 78 * Disable "recent comments" Gutenberg block. 79 77 80 = 1.9.0 = 78 81 * Fix compatibility with WordPress 5.0 and above. -
disable-comments/trunk/uninstall.php
r732081 r2125992 1 <?php 2 if ( !defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )1 <?php 2 if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 3 3 exit; 4 } 4 5 5 6 delete_site_option( 'disable_comments_options' );
Note: See TracChangeset
for help on using the changeset viewer.