Plugin Directory

Changeset 2125992


Ignore:
Timestamp:
07/20/2019 03:16:53 AM (6 years ago)
Author:
solarissmoke
Message:

Version 1.10.0

Location:
disable-comments/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • disable-comments/trunk/disable-comments.php

    r2042603 r2125992  
    44Plugin URI: https://wordpress.org/plugins/disable-comments/
    55Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type.
    6 Version: 1.9.0
     6Version: 1.10.0
    77Author: Samir Shah
    88Author URI: http://www.rayofsolaris.net/
     
    1212*/
    1313
    14 if( !defined( 'ABSPATH' ) )
     14if ( ! defined( 'ABSPATH' ) ) {
    1515    exit;
     16}
    1617
    1718class Disable_Comments {
    18     const DB_VERSION = 6;
     19    const DB_VERSION         = 6;
    1920    private static $instance = null;
    2021    private $options;
     
    3435
    3536        // Load options
    36         if( $this->networkactive ) {
     37        if ( $this->networkactive ) {
    3738            $this->options = get_site_option( 'disable_comments_options', array() );
    38         }
    39         else {
     39        } else {
    4040            $this->options = get_option( 'disable_comments_options', array() );
    4141        }
    4242
    4343        // If it looks like first run, check compat
    44         if( empty( $this->options ) ) {
     44        if ( empty( $this->options ) ) {
    4545            $this->check_compatibility();
    4646        }
     
    6464    private function check_db_upgrades() {
    6565        $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 ) {
    6868                // upgrade options from version 0.2.1 or earlier to 0.3
    6969                $this->options['disabled_post_types'] = get_option( 'disable_comments_post_types', array() );
    7070                delete_option( 'disable_comments_post_types' );
    7171            }
    72             if( $old_ver < 5 ) {
     72            if ( $old_ver < 5 ) {
    7373                // simple is beautiful - remove multiple settings in favour of one
    7474                $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;
    8283                }
    8384            }
     
    8990
    9091    private function update_options() {
    91         if( $this->networkactive ) {
     92        if ( $this->networkactive ) {
    9293            update_site_option( 'disable_comments_options', $this->options );
    93         }
    94         else {
     94        } else {
    9595            update_option( 'disable_comments_options', $this->options );
    9696        }
     
    103103        $types = $this->options['disabled_post_types'];
    104104        // 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 ) ) {
    108108                    $types[] = $extra;
    109109                }
     
    122122    private function init_filters() {
    123123        // These need to happen now
    124         if( $this->options['remove_everywhere'] ) {
     124        if ( $this->options['remove_everywhere'] ) {
    125125            add_action( 'widgets_init', array( $this, 'disable_rc_widget' ) );
    126126            add_filter( 'wp_headers', array( $this, 'filter_wp_headers' ) );
    127             add_action( 'template_redirect', array( $this, 'filter_query' ), 9 );   // before redirect_canonical
     127            add_action( 'template_redirect', array( $this, 'filter_query' ), 9 );   // before redirect_canonical
    128128
    129129            // Admin bar filtering has to happen here since WP 3.6
     
    135135        add_action( 'plugins_loaded', array( $this, 'register_text_domain' ) );
    136136        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') );
    137140    }
    138141
    139142    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() {
    144147        $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 ) {
    147150                // we need to know what native support was for later
    148                 if( post_type_supports( $type, 'comments' ) ) {
     151                if ( post_type_supports( $type, 'comments' ) ) {
    149152                    $this->modified_types[] = $type;
    150153                    remove_post_type_support( $type, 'comments' );
     
    155158            add_filter( 'comments_open', array( $this, 'filter_comment_status' ), 20, 2 );
    156159            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'] ) {
    159162            // It is possible that $disabled_post_types is empty if other
    160163            // plugins have disabled comments. Hence we also check for
     
    165168
    166169        // Filters for the admin only
    167         if( is_admin() ) {
    168             if( $this->networkactive ) {
     170        if ( is_admin() ) {
     171            if ( $this->networkactive ) {
    169172                add_action( 'network_admin_menu', array( $this, 'settings_menu' ) );
    170173                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 {
    174176                add_action( 'admin_menu', array( $this, 'settings_menu' ) );
    175177                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.
    178180                    register_deactivation_hook( __FILE__, array( $this, 'single_site_deactivate' ) );
     181                }
    179182            }
    180183
     
    182185            add_filter( 'plugin_row_meta', array( $this, 'set_plugin_meta' ), 10, 2 );
    183186
    184             if( $this->options['remove_everywhere'] ) {
    185                 add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 );  // do this as late as possible
     187            if ( $this->options['remove_everywhere'] ) {
     188                add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 );  // do this as late as possible
    186189                add_action( 'admin_print_styles-index.php', array( $this, 'admin_css' ) );
    187190                add_action( 'admin_print_styles-profile.php', array( $this, 'admin_css' ) );
     
    194197            add_action( 'template_redirect', array( $this, 'check_comment_template' ) );
    195198
    196             if( $this->options['remove_everywhere'] ) {
     199            if ( $this->options['remove_everywhere'] ) {
    197200                add_filter( 'feed_links_show_comments_feed', '__return_false' );
    198201            }
     
    206209     */
    207210    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 ) {
    210213                // Kill the comments template.
    211214                add_filter( 'comments_template', array( $this, 'dummy_comments_template' ), 20 );
     
    235238     */
    236239    public function filter_query() {
    237         if( is_comment_feed() ) {
     240        if ( is_comment_feed() ) {
    238241            wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
    239242        }
     
    244247     */
    245248    public function filter_admin_bar() {
    246         if( is_admin_bar_showing() ) {
     249        if ( is_admin_bar_showing() ) {
    247250            // Remove comments links from admin bar
    248251            remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
    249             if( is_multisite() ) {
     252            if ( is_multisite() ) {
    250253                add_action( 'admin_bar_menu', array( $this, 'remove_network_comment_links' ), 500 );
    251254            }
     
    253256    }
    254257
     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
    255287    /*
    256288     * Remove comment links from the admin bar in a multisite network.
    257289     */
    258290    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 ) {
    261293                $wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
    262294            }
    263         }
    264         else {
     295        } else {
    265296            // We have no way to know whether the plugin is active on other sites, so only remove this one
    266297            $wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' );
     
    270301    public function discussion_notice() {
    271302        $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 ) ) {
    273304            $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            }
    276308
    277309            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>';
     
    283315     */
    284316    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' );
    286318        return add_query_arg( 'page', 'disable_comments_settings', $base );
    287319    }
     
    291323     */
    292324    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' );
    294326        return add_query_arg( 'page', 'disable_comments_tools', $base );
    295327    }
    296328
    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 ) {
    299331            return;
     332        }
    300333        $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() {
    307340        global $pagenow;
    308341
    309         if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' )
     342        if ( $pagenow == 'comment.php' || $pagenow == 'edit-comments.php' ) {
    310343            wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
     344        }
    311345
    312346        remove_menu_page( 'edit-comments.php' );
    313347
    314348        if ( ! $this->discussion_settings_allowed() ) {
    315             if ( $pagenow == 'options-discussion.php' )
     349            if ( $pagenow == 'options-discussion.php' ) {
    316350                wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
     351            }
    317352
    318353            remove_submenu_page( 'options-general.php', 'options-discussion.php' );
     
    320355    }
    321356
    322     public function filter_dashboard(){
     357    public function filter_dashboard() {
    323358        remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
    324359    }
    325360
    326     public function admin_css(){
     361    public function admin_css() {
    327362        echo '<style>
    328363            #dashboard_right_now .comment-count,
     
    336371    }
    337372
    338     public function filter_existing_comments($comments, $post_id) {
     373    public function filter_existing_comments( $comments, $post_id ) {
    339374        $post = get_post( $post_id );
    340375        return ( $this->options['remove_everywhere'] || $this->is_post_type_disabled( $post->post_type ) ) ? array() : $comments;
     
    344379        $post = get_post( $post_id );
    345380        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;
    346386    }
    347387
     
    350390        // The widget has added a style action when it was constructed - which will
    351391        // 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' );
    353393    }
    354394
     
    364404    /**
    365405     * Add links to Settings page
    366     */
     406     */
    367407    public function plugin_actions_links( $links, $file ) {
    368408        static $plugin;
    369409        $plugin = plugin_basename( __FILE__ );
    370         if( $file == $plugin && current_user_can('manage_options') ) {
     410        if ( $file == $plugin && current_user_can( 'manage_options' ) ) {
    371411            array_unshift(
    372412                $links,
     
    381421    public function settings_menu() {
    382422        $title = _x( 'Disable Comments', 'settings menu title', 'disable-comments' );
    383         if( $this->networkactive )
     423        if ( $this->networkactive ) {
    384424            add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'disable_comments_settings', array( $this, 'settings_page' ) );
    385         else
     425        } else {
    386426            add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'disable_comments_settings', array( $this, 'settings_page' ) );
     427        }
    387428    }
    388429
     
    393434    public function tools_menu() {
    394435        $title = __( 'Delete Comments', 'disable-comments' );
    395         if( $this->networkactive )
     436        if ( $this->networkactive ) {
    396437            add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'disable_comments_tools', array( $this, 'tools_page' ) );
    397         else
     438        } else {
    398439            add_submenu_page( 'tools.php', $title, $title, 'manage_options', 'disable_comments_tools', array( $this, 'tools_page' ) );
     440        }
    399441    }
    400442
     
    404446
    405447    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 ) {
    407449            return true;
    408450        }
  • disable-comments/trunk/includes/comments-template.php

    r1211200 r2125992  
    11<?php
    2 /* Dummy comments template file.
     2/*
     3 Dummy comments template file.
    34 * This replaces the theme's comment template when comments are disabled everywhere
    45 */
  • disable-comments/trunk/includes/settings-page.php

    r2042603 r2125992  
    11<?php
    2 if( !defined( 'ABSPATH' ) ) {
     2if ( ! defined( 'ABSPATH' ) ) {
    33    exit;
    44}
    55
    66$typeargs = array( 'public' => true );
    7 if( $this->networkactive ) {
    8     $typeargs['_builtin'] = true;   // stick to known types for network
     7if ( $this->networkactive ) {
     8    $typeargs['_builtin'] = true;   // stick to known types for network
    99}
    1010$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] );
     11foreach ( 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    }
    1415}
    1516
     
    1819    $this->options['remove_everywhere'] = ( $_POST['mode'] == 'remove_everywhere' );
    1920
    20     if( $this->options['remove_everywhere'] )
     21    if ( $this->options['remove_everywhere'] ) {
    2122        $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    }
    2426
    2527    $disabled_post_types = array_intersect( $disabled_post_types, array_keys( $types ) );
     
    2830
    2931    // 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 builtins
     32    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
    3335    }
    3436
     
    4042<style> .indent {padding-left: 2em} </style>
    4143<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>
    4345<?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>';
     46if ( $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}
     49if ( 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}
    4852?>
    4953<form action="" method="post" id="disable-comments">
    5054<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>
    5357</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>
    5559    <p></p>
    5660    <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        ?>
    5865    </ul>
    59     <?php if( $this->networkactive ) :?>
     66    <?php if ( $this->networkactive ) : ?>
    6067    <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' ); ?>
    6168    <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>
    6269    <?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>
    6471</li>
    6572</ul>
    6673
    6774<?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>
    6976</form>
    7077</div>
  • disable-comments/trunk/includes/tools-page.php

    r2042603 r2125992  
    11<?php
    2 if( !defined( 'ABSPATH' ) ) {
     2if ( ! defined( 'ABSPATH' ) ) {
    33    exit;
    44}
    55?>
    66<div class="wrap">
    7 <h1><?php _e( 'Delete Comments', 'disable-comments') ?></h1>
     7<h1><?php _e( 'Delete Comments', 'disable-comments' ); ?></h1>
    88<?php
    99
    1010global $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" );
     12if ( $comments_count <= 0 ) {
     13    ?>
     14<p><strong><?php _e( 'No comments available for deletion.', 'disable-comments' ); ?></strong></p>
    1415</div>
    15 <?php
     16    <?php
    1617    return;
    1718}
    1819
    1920$typeargs = array( 'public' => true );
    20 if( $this->networkactive ) {
    21     $typeargs['_builtin'] = true;   // stick to known types for network
     21if ( $this->networkactive ) {
     22    $typeargs['_builtin'] = true;   // stick to known types for network
    2223}
    2324$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] );
     25foreach ( 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    }
    2729}
    2830
     
    3032    check_admin_referer( 'delete-comments-admin' );
    3133
    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        }
    4547    } 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'];
    4749        $delete_post_types = array_intersect( $delete_post_types, array_keys( $types ) );
    4850
    4951        // Extra custom post types
    50         if( $this->networkactive && !empty( $_POST['delete_extra_post_types'] ) ) {
     52        if ( $this->networkactive && ! empty( $_POST['delete_extra_post_types'] ) ) {
    5153            $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 builtins
    53             $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 );
    5456        }
    5557
     
    5759            // Loop through post_types and remove comments/meta and set posts comment_count to 0
    5860            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'" );
    6264
    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>';
    6668            }
    6769
    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" );
    7072
    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>';
    7274        }
    73 
    7475    }
    7576
    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>
    7981        </div>
    80     <?php
     82        <?php
    8183        return;
    8284    }
    83 
    8485}
    8586?>
    8687<form action="" method="post" id="delete-comments">
    8788<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>
    9091</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>
    9293    <p></p>
    9394    <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        ?>
    9599    </ul>
    96     <?php if( $this->networkactive ) :?>
     100    <?php if ( $this->networkactive ) : ?>
    97101    <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' ); ?>
    98102    <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>
    99103    <?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>
    101105</li>
    102106</ul>
     
    104108<?php wp_nonce_field( 'delete-comments-admin' ); ?>
    105109<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>
    107111</form>
    108112</div>
  • disable-comments/trunk/readme.txt

    r2042603 r2125992  
    11=== Disable Comments ===
    2 Contributors: solarissmoke
     2Contributors: solarissmoke, garrett-eclipse
    33Donate link: http://www.rayofsolaris.net/donate/
    44Tags: comments, disable, global
    55Requires at least: 5.0
    6 Tested up to: 5.1
     6Tested up to: 5.3
    77Stable tag: trunk
    88
     
    4747= I want to delete comments from my database. What do I do? =
    4848
    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.
     49Go 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.
    5050
    5151== Details ==
     
    7575== Changelog ==
    7676
     77= 1.10.0 =
     78* Disable "recent comments" Gutenberg block.
     79
    7780= 1.9.0 =
    7881* 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
     2if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    33    exit;
     4}
    45
    56delete_site_option( 'disable_comments_options' );
Note: See TracChangeset for help on using the changeset viewer.