Changeset 2042603
- Timestamp:
- 03/02/2019 04:08:56 AM (7 years ago)
- Location:
- disable-comments/trunk
- Files:
-
- 4 edited
-
disable-comments.php (modified) (5 diffs)
-
includes/settings-page.php (modified) (4 diffs)
-
includes/tools-page.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disable-comments/trunk/disable-comments.php
r1959549 r2042603 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. 8.06 Version: 1.9.0 7 7 Author: Samir Shah 8 8 Author URI: http://www.rayofsolaris.net/ … … 77 77 } 78 78 79 foreach( array( 'remove_everywhere', ' permanent', 'extra_post_types' ) as $v ) {79 foreach( array( 'remove_everywhere', 'extra_post_types' ) as $v ) { 80 80 if( !isset( $this->options[$v] ) ) { 81 81 $this->options[$v] = false; … … 182 182 add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 ); 183 183 184 // if only certain types are disabled, remember the original post status185 if( !( $this->persistent_mode_allowed() && $this->options['permanent'] ) && !$this->options['remove_everywhere'] ) {186 add_action( 'edit_form_advanced', array( $this, 'edit_form_inputs' ) );187 add_action( 'edit_page_form', array( $this, 'edit_form_inputs' ) );188 }189 190 184 if( $this->options['remove_everywhere'] ) { 191 185 add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 ); // do this as late as possible … … 271 265 // We have no way to know whether the plugin is active on other sites, so only remove this one 272 266 $wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' ); 273 }274 }275 276 public function edit_form_inputs() {277 global $post;278 // Without a dicussion meta box, comment_status will be set to closed on new/updated posts279 if( in_array( $post->post_type, $this->modified_types ) ) {280 echo '<input type="hidden" name="comment_status" value="' . $post->comment_status . '" /><input type="hidden" name="ping_status" value="' . $post->ping_status . '" />';281 267 } 282 268 } … … 417 403 } 418 404 419 private function enter_permanent_mode() {420 $types = $this->get_disabled_post_types();421 if( empty( $types ) )422 return;423 424 global $wpdb;425 426 if( $this->networkactive ) {427 // NOTE: this can be slow on large networks!428 $blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND deleted = '0'", $wpdb->siteid ) );429 430 foreach ( $blogs as $id ) {431 switch_to_blog( $id );432 $this->close_comments_in_db( $types );433 restore_current_blog();434 }435 }436 else {437 $this->close_comments_in_db( $types );438 }439 }440 441 private function close_comments_in_db( $types ){442 global $wpdb;443 $bits = implode( ', ', array_pad( array(), count( $types ), '%s' ) );444 $wpdb->query( $wpdb->prepare( "UPDATE `$wpdb->posts` SET `comment_status` = 'closed', ping_status = 'closed' WHERE `post_type` IN ( $bits )", $types ) );445 }446 447 private function persistent_mode_allowed() {448 if( defined( 'DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE' ) && DISABLE_COMMENTS_ALLOW_PERSISTENT_MODE == false ) {449 return false;450 }451 }452 453 405 private function discussion_settings_allowed() { 454 406 if( defined( 'DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS' ) && DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS == true ) { -
disable-comments/trunk/includes/settings-page.php
r1959549 r2042603 14 14 } 15 15 16 $persistent_allowed = $this->persistent_mode_allowed();17 18 16 if ( isset( $_POST['submit'] ) ) { 19 17 check_admin_referer( 'disable-comments-admin' ); … … 27 25 $disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) ); 28 26 29 // entering permanent mode, or post types have changed30 if( $persistent_allowed && !empty( $_POST['permanent'] ) && ( !$this->options['permanent'] || $disabled_post_types != $this->options['disabled_post_types'] ) )31 $this->enter_permanent_mode();32 33 27 $this->options['disabled_post_types'] = $disabled_post_types; 34 $this->options['permanent'] = $persistent_allowed && isset( $_POST['permanent'] );35 28 36 29 // Extra custom post types … … 72 65 </ul> 73 66 74 <?php if( $persistent_allowed && $this->options['permanent'] ): ?>75 <h2><?php _e( 'Other options', 'disable-comments') ?></h2>76 <ul>77 <li>78 <?php79 echo '<label for="permanent"><input type="checkbox" name="permanent" id="permanent" '. checked( $this->options['permanent'], true, false ) . '> <strong>' . __( 'Use persistent mode', 'disable-comments') . '</strong></label>';80 echo '<p class="indent">' . sprintf( __( '%s: <strong>This will make persistent changes to your database — comments will remain closed even if you later disable the plugin!</strong> You should not use it if you only want to disable comments temporarily. Please <a href="%s" target="_blank">read the FAQ</a> before selecting this option.', 'disable-comments'), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>', 'https://wordpress.org/plugins/disable-comments/faq/' ) . '</p>';81 if( $this->networkactive )82 echo '<p class="indent">' . sprintf( __( '%s: Entering persistent mode on large multi-site networks requires a large number of database queries and can take a while. Use with caution!', 'disable-comments'), '<strong style="color: #900">' . __('Warning', 'disable-comments') . '</strong>' ) . '</p>';83 ?>84 </li>85 </ul>86 <?php endif; ?>87 88 67 <?php wp_nonce_field( 'disable-comments-admin' ); ?> 89 68 <p class="submit"><input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes', 'disable-comments') ?>"></p> … … 106 85 107 86 disable_comments_uihelper(); 108 109 $("#permanent").change( function() {110 if( $(this).is(":checked") && ! confirm(<?php echo json_encode( sprintf( __( '%s: Selecting this option will make persistent changes to your database. Are you sure you want to enable it?', 'disable-comments'), __( 'Warning', 'disable-comments' ) ) );?>) )111 $(this).attr("checked", false );112 });113 87 }); 114 88 </script> -
disable-comments/trunk/includes/tools-page.php
r1546961 r2042603 60 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 61 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'" ); 62 echo "<p style='color:green'><strong>" . sprintf( __( 'All comments have been deleted for %ss.', 'disable-comments' ), $delete_post_type ) . "</strong></p>"; 62 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>"; 63 66 } 64 67 -
disable-comments/trunk/readme.txt
r1959549 r2042603 3 3 Donate link: http://www.rayofsolaris.net/donate/ 4 4 Tags: comments, disable, global 5 Requires at least: 4.76 Tested up to: 5. 05 Requires at least: 5.0 6 Tested up to: 5.1 7 7 Stable tag: trunk 8 8 … … 75 75 == Changelog == 76 76 77 = 1.9.0 = 78 * Fix compatibility with WordPress 5.0 and above. 79 * Remove deprecated "persistent mode" feature. 80 77 81 = 1.8.0 = 78 82 * Added `DISABLE_COMMENTS_ALLOW_DISCUSSION_SETTINGS` configuration.
Note: See TracChangeset
for help on using the changeset viewer.