WordPress.org

Plugin Directory

Changeset 614399


Ignore:
Timestamp:
10/19/12 06:27:24 (18 months ago)
Author:
solarissmoke
Message:

Releasing version 0.7

Location:
disable-comments/trunk
Files:
3 edited

Legend:

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

    r597840 r614399  
    44Plugin URI: http://wordpress.org/extend/plugins/disable-comments/ 
    55Description: Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. 
    6 Version: 0.6 
     6Version: 0.7 
    77Author: Samir Shah 
    88Author URI: http://rayofsolaris.net/ 
     
    1414 
    1515class Disable_Comments { 
    16     const db_version = 4; 
     16    const db_version = 5; 
    1717    private $options; 
     18    private $networkactive; 
    1819    private $modified_types = array(); 
    1920     
    2021    function __construct() { 
     22        // are we network activated? 
     23        $this->networkactive = ( is_multisite() && array_key_exists( plugin_basename( __FILE__ ), get_site_option( 'active_sitewide_plugins' ) ) ); 
     24         
    2125        // load options 
    22         $this->options = get_option( 'disable_comments_options', array() ); 
     26        $this->options = $this->networkactive ? get_site_option( 'disable_comments_options', array() ) : get_option( 'disable_comments_options', array() ); 
    2327         
    2428        // If it looks like first run, check compat 
     
    3741                delete_option( 'disable_comments_post_types' ); 
    3842            } 
    39  
    40             foreach( array( 'remove_admin_menu_comments', 'remove_admin_bar_comments', 'remove_recent_comments', 'remove_discussion', 'remove_rc_widget', 'permanent' ) as $v ) 
     43            if( $old_ver < 5 ) { 
     44                // simple is beautiful - remove multiple settings in favour of one 
     45                $this->options['remove_everywhere'] = isset( $this->options['remove_admin_menu_comments'] ) ? $this->options['remove_admin_menu_comments'] : false; 
     46                foreach( array( 'remove_admin_menu_comments', 'remove_admin_bar_comments', 'remove_recent_comments', 'remove_discussion', 'remove_rc_widget' ) as $v ) 
     47                    unset( $this->options[$v] ); 
     48            } 
     49 
     50            foreach( array( 'remove_everywhere', 'permanent' ) as $v ) 
    4151                if( !isset( $this->options[$v] ) ) 
    4252                    $this->options[$v] = false; 
    4353 
    4454            $this->options['db_version'] = self::db_version; 
    45             update_option( 'disable_comments_options', $this->options ); 
     55            $this->update_options(); 
    4656        } 
    4757         
    4858        // these need to happen now 
    49         if( $this->options['remove_rc_widget'] ) 
     59        if( $this->options['remove_everywhere'] ) 
    5060            add_action( 'widgets_init', array( $this, 'disable_rc_widget' ) ); 
    5161         
    5262        // these can happen later 
    5363        add_action( 'wp_loaded', array( $this, 'setup_filters' ) );  
     64    } 
     65     
     66    private function update_options() { 
     67        if( $this->networkactive ) 
     68            update_site_option( 'disable_comments_options', $this->options ); 
     69        else 
     70            update_option( 'disable_comments_options', $this->options ); 
    5471    } 
    5572     
     
    6885        } 
    6986        elseif( is_admin() ) { 
    70             add_action( 'admin_notices', array( $this, 'setup_notice' ) ); 
    71         } 
    72          
    73         if( $this->options['remove_admin_bar_comments'] && is_admin_bar_showing() ) { 
     87            add_action( 'all_admin_notices', array( $this, 'setup_notice' ) ); 
     88        } 
     89         
     90        if( $this->options['remove_everywhere'] && is_admin_bar_showing() ) { 
    7491            remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 );    // WP<3.3 
    7592            remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );    // WP 3.3 
     93            if( $this->networkactive ) 
     94                add_action( 'admin_bar_menu', array( $this, 'remove_network_comment_links' ), 500 ); 
    7695        } 
    7796         
    7897        if( is_admin() ) { 
    79             add_action( 'admin_menu', array( $this, 'settings_menu' ) ); 
     98            if( $this->networkactive ) { 
     99                add_action( 'network_admin_menu', array( $this, 'settings_menu' ) ); 
     100            } 
     101            else { 
     102                add_action( 'admin_menu', array( $this, 'settings_menu' ) ); 
     103                register_deactivation_hook( __FILE__, array( $this, 'single_site_deactivate' ) ); 
     104            } 
     105 
    80106            add_action( 'admin_print_footer_scripts', array( $this, 'discussion_notice' ) ); 
    81107             
     
    85111            } 
    86112             
    87             if( $this->options['remove_admin_menu_comments'] ) 
     113            if( $this->options['remove_everywhere'] ) { 
    88114                add_action( 'admin_menu', array( $this, 'filter_admin_menu' ), 9999 );  // do this as late as possible 
    89                  
    90             if( $this->options['remove_discussion'] ) 
    91115                add_action( 'admin_head', array( $this, 'hide_discussion_rightnow' ) ); 
    92                  
    93             if( $this->options['remove_recent_comments'] ) 
    94116                add_action( 'wp_dashboard_setup', array( $this, 'filter_dashboard' ) ); 
    95         } 
     117            } 
     118        } 
     119    } 
     120     
     121    function remove_network_comment_links( $wp_admin_bar ) { 
     122        foreach( (array) $wp_admin_bar->user->blogs as $blog ) 
     123            $wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' ); 
    96124    } 
    97125     
     
    120148     
    121149    function setup_notice(){ 
    122         if( current_user_can( 'manage_options' ) && get_current_screen()->id != 'settings_page_disable_comments_settings' ) 
    123             echo '<div class="updated fade"><p>The <em>Disable Comments</em> plugin is active, but isn\'t configured to do anything yet. Visit the <a href="options-general.php?page=disable_comments_settings">configuration page</a> to choose which post types to disable comments on.</p></div>'; 
     150        if( strpos( get_current_screen()->id, 'settings_page_disable_comments_settings' ) === 0 ) 
     151            return; 
     152        $hascaps = $this->networkactive ? is_network_admin() && current_user_can( 'manage_network_plugins' ) : current_user_can( 'manage_options' ); 
     153        $url = $this->networkactive ? network_admin_url( 'settings.php?page=disable_comments_settings' ) : admin_url( 'options-general.php?page=disable_comments_settings' ); 
     154        $url = esc_url( $url ); 
     155        if( $hascaps ) 
     156            echo '<div class="updated fade"><p>The <em>Disable Comments</em> plugin is active, but isn\'t configured to do anything yet. Visit the <a href="' . $url . '">configuration page</a> to choose which post types to disable comments on.</p></div>'; 
    124157    } 
    125158     
    126159    function filter_admin_menu(){ 
    127         global $menu; 
    128         if( isset( $menu[25] ) && $menu[25][2] == 'edit-comments.php' ) 
    129             unset( $menu[25] ); 
     160        remove_menu_page( 'edit-comments.php' ); 
     161        remove_submenu_page( 'options-general.php', 'options-discussion.php' ); 
    130162    } 
    131163     
     
    154186     
    155187    function settings_menu() { 
    156         add_submenu_page('options-general.php', 'Disable Comments', 'Disable Comments', 'manage_options', 'disable_comments_settings', array( $this, 'settings_page' ) ); 
     188        if( $this->networkactive ) 
     189            add_submenu_page( 'settings.php', 'Disable Comments', 'Disable Comments', 'manage_network_plugins', 'disable_comments_settings', array( $this, 'settings_page' ) ); 
     190        else 
     191            add_submenu_page( 'options-general.php', 'Disable Comments', 'Disable Comments', 'manage_options', 'disable_comments_settings', array( $this, 'settings_page' ) ); 
    157192    } 
    158193     
    159194    function settings_page() { 
    160         $types = get_post_types( array( 'public' => true ), 'objects' ); 
     195        $typeargs = array( 'public' => true ); 
     196        if( $this->networkactive ) 
     197            $typeargs['_builtin'] = true;   // stick to known types for network 
     198        $types = get_post_types( $typeargs, 'objects' ); 
    161199        foreach( array_keys( $types ) as $type ) { 
    162200            if( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) )   // the type doesn't support comments anyway 
     
    172210             
    173211            $this->options['disabled_post_types'] = $disabled_post_types; 
    174             foreach( array( 'remove_admin_menu_comments', 'remove_admin_bar_comments', 'remove_recent_comments', 'remove_discussion', 'remove_rc_widget', 'permanent' ) as $v ) 
     212            foreach( array( 'remove_everywhere', 'permanent' ) as $v ) 
    175213                $this->options[$v] = !empty( $_POST[$v] );   
    176214             
    177             update_option( 'disable_comments_options', $this->options ); 
     215            $this->update_options(); 
    178216            echo '<div id="message" class="updated fade"><p>Options updated. Changes to the Admin Menu and Admin Bar will not appear until you leave or reload this page.</p></div>'; 
    179217        }    
     
    181219    <style> .indent {padding-left: 2em} </style> 
    182220    <div class="wrap"> 
    183     <?php screen_icon(); ?> 
     221    <?php screen_icon( 'plugins' ); ?> 
    184222    <h2>Disable Comments</h2> 
     223    <?php if( $this->networkactive ) echo '<div class="updated fade"><p><em>Disable Comments</em> is Network Activated. The settings below will affect <strong>all sites</strong> in this network.</p></div>';?> 
    185224    <form action="" method="post" id="disable-comments"> 
    186225    <p>Globally disable comments on:</p> 
     
    191230    <h3>Other options</h3> 
    192231    <ul class="indent"> 
    193         <li><label for="remove_admin_menu_comments"><input type="checkbox" name="remove_admin_menu_comments" id="remove_admin_menu_comments" <?php checked( $this->options['remove_admin_menu_comments'] );?>> Remove the "Comments" link from the Admin Menu</label></li> 
    194         <li><label for="remove_admin_bar_comments"><input type="checkbox" name="remove_admin_bar_comments" id="remove_admin_bar_comments" <?php checked( $this->options['remove_admin_bar_comments'] );?>> Remove the "Comments" icon from the Admin Bar</label></li> 
    195         <li><label for="remove_recent_comments"><input type="checkbox" name="remove_recent_comments" id="remove_recent_comments" <?php checked( $this->options['remove_recent_comments'] );?>> Disable the "Recent Comments" Dashboard widget</label></li> 
    196         <li><label for="remove_rc_widget"><input type="checkbox" name="remove_rc_widget" id="remove_rc_widget" <?php checked( $this->options['remove_rc_widget'] );?>> Disable the "Recent Comments" template widget (this prevents the widget from being available in <code>Appearance -> Widgets</code> and from being used by your theme)</label></li> 
    197         <li><label for="remove_discussion"><input type="checkbox" name="remove_discussion" id="remove_discussion" <?php checked( $this->options['remove_discussion'] );?>> Remove the "Discussion" section from the "Right Now" Dashboard widget <span class="hide-if-js"><strong>(Note: this option will only work if you have Javascript enabled in your browser)</strong></span></label></li> 
     232        <li><label for="remove_everywhere"><input type="checkbox" name="remove_everywhere" id="remove_everywhere" <?php checked( $this->options['remove_everywhere'] );?>> Remove all comment-related controls from WordPress</label></li> 
     233            <p>Selecting this option will remove the following:</p> 
     234            <ul class="indent" style="list-style: disc"> 
     235            <li>The "Comments" link from the Admin Menu</li> 
     236            <li>The "Comments" icon from the Admin Bar</li> 
     237            <li>The "Recent Comments" Dashboard widget</li> 
     238            <li>The "Recent Comments" template widget (this prevents the widget from being available in <code>Appearance -> Widgets</code> and from being used by themes)</li> 
     239            <li>The "Discussion" section from the WordPress Dashboard <span class="hide-if-js"><strong>(Note: this requires Javascript to be enabled in the browser)</strong></span></li> 
     240            <li>The "Discussion Settings" page</strong></span></li> 
     241            </ul> 
     242            <p><strong>Note:</strong> this option is global. They will affect all users, everywhere, regardless of whether comments are enabled on portions of your site. Use it only if you want to remove all references to comments <em>everywhere</em>.</p> 
     243        </li> 
     244        <li><label for="permanent"><input type="checkbox" name="permanent" id="permanent" <?php checked( $this->options['permanent'] );?>> Use permanent mode (use only if normal mode doesn't work - see the <a href="http://wordpress.org/extend/plugins/disable-comments/faq/" target="_blank">FAQ</a> for what this means)</a></label> 
     245        <?php if( $this->networkactive ) echo '<p><strong>Warning:</strong> entering permanent mode on large multi-site networks requires a large number of database queries and can take a while. Use with caution!</p>';?> 
     246        </li> 
    198247    </ul> 
    199     <p><strong>Note:</strong> these options are global. They will affect all users, everywhere, regardless of whether comments are enabled on portions of your site. Use them only if you want to remove all references to comments <em>everywhere</em>. 
    200     <ul class="indent"><li><label for="permanent"><input type="checkbox" name="permanent" id="permanent" <?php checked( $this->options['permanent'] );?>> Use permanent mode (see the <a href="http://wordpress.org/extend/plugins/disable-comments/faq/" target="_blank">FAQ</a> for what this means)</a></label></li></ul> 
    201248    <p class="submit"><input class="button-primary" type="submit" name="submit" value="Update settings"></p> 
    202249    </form> 
     
    218265             
    219266        global $wpdb; 
     267 
     268        if( $this->networkactive ) { 
     269            // NOTE: this can be slow on large networks! 
     270            $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 ) ); 
     271     
     272            foreach ( $blogs as $id ) { 
     273                switch_to_blog( $id ); 
     274                $this->close_comments_in_db( $types ); 
     275                restore_current_blog(); 
     276            } 
     277        } 
     278        else { 
     279            $this->close_comments_in_db( $types ); 
     280        } 
     281    } 
     282     
     283    private function close_comments_in_db( $types ){ 
     284        global $wpdb; 
    220285        $bits = implode( ', ', array_pad( array(), count( $types ), '%s' ) ); 
    221286        $wpdb->query( $wpdb->prepare( "UPDATE `$wpdb->posts` SET `comment_status` = 'closed', ping_status = 'closed' WHERE `post_type` IN ( $bits )", $types ) ); 
    222287    } 
     288     
     289    function single_site_deactivate() { 
     290        // for single sites, delete the options upon deactivation, not uninstall 
     291        delete_option( 'disable_comments_options' ); 
     292    } 
    223293} 
    224294 
  • disable-comments/trunk/readme.txt

    r611782 r614399  
    66Stable tag: trunk 
    77 
    8 Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. 
     8Allows administrators to globally disable comments on their site. Comments can be disabled according to post type. Multisite friendly. 
    99 
    1010== Description == 
    1111 
    12 This plugin allows administrators to globally disable comments on any post type (posts, pages, attachments, etc.) so that these settings cannot be overridden for individual posts. It also removes all comment-related fields from edit and quick-edit screens. 
     12This plugin allows administrators to globally disable comments on any post type (posts, pages, attachments, etc.) so that these settings cannot be overridden for individual posts. It also removes all comment-related fields from edit and quick-edit screens. On multisite installations, it can be used to disable comments on the entire network. 
    1313 
    1414Additionally, comment-related items can be removed from the Dashboard, Widgets, the Admin Menu and the Admin Bar. 
     
    4747 
    4848== Changelog == 
     49 
     50= 0.7 = 
     51* Now supports Network Activation - disable comments on your entire multi-site network. 
     52* Simplified settings page. 
    4953 
    5054= 0.6 =  
     
    87911. Upload the plugin folder to the `/wp-content/plugins/` directory 
    88922. Activate the plugin through the 'Plugins' menu in WordPress 
    89 3. The plugin settings can be accessed via the 'Settings' menu in the administration area 
     933. The plugin settings can be accessed via the 'Settings' menu in the administration area (either your site administration for single-site installs, or your network administration for network installs). 
  • disable-comments/trunk/uninstall.php

    r444122 r614399  
    33    exit; 
    44 
    5 delete_option( 'disable_comments_options' ); 
    6 ?> 
     5delete_site_option( 'disable_comments_options' ); 
Note: See TracChangeset for help on using the changeset viewer.