WordPress.org

Plugin Directory

Changeset 609535


Ignore:
Timestamp:
10/08/12 11:32:17 (19 months ago)
Author:
lightningspirit
Message:

Huge update! Check changelog for further information.

Location:
hide-comments-feature/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • hide-comments-feature/trunk/hide-comments.php

    r326266 r609535  
    33/* 
    44Plugin Name: Hide Comments 
    5 Plugin URI: http://wordpress.org/extend/plugins/hide-comments 
    6 Version: 0.2 
    7 Author: Vitor Carvalho 
    8 Author URI: http://lightningspirit.net 
    9 Description: If you do not need Comments functionality in your Wordpress instance, you can "hide" it with this plugin. 
    10 Tags: plugin, hide, comments, comment, admin, feature, core 
    11 License: GPL2 
     5Plugin URI: http://wordpress.org/extend/plugins/hide-comments-feature 
     6Version: 0.3 
     7Description: Remove comments functionality and related in your Wordpress instance. 
     8Author: lightningspirit 
     9Author URI: http://profiles.wordpress.org/lightningspirit 
     10Tags: plugin, hide, remove, comments, comment, comments, dashboard, feature, core 
     11License: GPLv2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1212*/ 
    1313 
     
    2323 
    2424 
    25 /* 
    26  *      Hide Comments 
    27  *       
    28  *      Copyright 2010 Vitor Carvalho <lightningspirit@gmail.com> 
    29  *       
    30  *      This program is free software; you can redistribute it and/or modify 
    31  *      it under the terms of the GNU General Public License as published by 
    32  *      the Free Software Foundation; either version 2 of the License, or 
    33  *      (at your option) any later version. 
    34  *       
    35  *      This program is distributed in the hope that it will be useful, 
    36  *      but WITHOUT ANY WARRANTY; without even the implied warranty of 
    37  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    38  *      GNU General Public License for more details. 
    39  *       
    40  *      You should have received a copy of the GNU General Public License 
    41  *      along with this program; if not, write to the Free Software 
    42  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
    43  *      MA 02110-1301, USA. 
     25if ( ! class_exists ( 'Hide_Comments_Feature' ) ) : 
     26/** 
     27 * Hide_Comments_Feature 
     28 *  
     29 * Central class to that removes all comments features. 
     30 * All functions are aggregated to an action hook. 
     31 * Everything here is static, thus the plugin is intented to be fast. 
     32 *  
     33 * Just use the custom action hooks provided. If you need a specific hook 
     34 * not listed here, please patch the file and send to he diff to my email 
     35 * lightningspirit [at] gmail [dot] com. 
     36 * I will release it asap. 
     37 *  
     38 *  
     39 * Actions hooks: 
     40 * -------------- 
     41 *  
     42 * a) hide_comments_post_types:  
     43 *    you may filter the array of post types to be used by the plugin 
     44 *  
     45 * b) hide_comments_css:  
     46 *    for general purposes on your template, 
     47 *    you may echo any custom css to hide links and such from your theme. 
     48 *  
     49 * c) hide_comments_dashboard_right_now: 
     50 *    just boolean values. If you return true, the discussion table of dashboard right now widget 
     51 *    will be hidden. False otherwise. Defaults to true. 
     52 *  
     53 * d) hide_comments_template_comments_path: 
     54 *    the default path is the empty file template-comments.php located in the same dir of this 
     55 *    plugin. just modify the path to your own file if you want to return anything else. 
     56 *  
     57 * If you want to programmatically change any action used here, just add remove_action  
     58 * in your theme's functions.php, inside of a add_action('init') call. 
     59 *  
     60 *  
     61 * @package WordPress 
     62 * @subpackage Importer 
     63 * @since 0.3 
    4464 */ 
    45   
    46  
    47  
    48  
    49 /*  
    50  * CHANGELOG 
    51  *  
    52  * 0.1 - Initial Release 
    53  *  
     65class Hide_Comments_Feature { 
     66     
     67    public function __construct() { 
     68        Hide_Comments_Feature::init(); 
     69         
     70    } 
     71     
     72    public static function init() { 
     73        add_action( 'init', array( 'Hide_Comments_Feature', 'init_everything' ) ); 
     74        add_action( 'wp_head', array( 'Hide_Comments_Feature', 'remove_comments_css' ) ); 
     75        add_action( 'wp_meta', array( 'Hide_Comments_Feature', 'remove_comments_link_meta' ) ); 
     76        add_action( 'admin_menu', array( 'Hide_Comments_Feature', 'remove_discussion_options' ) ); 
     77        add_action( 'admin_head', array( 'Hide_Comments_Feature', 'dashboard_right_now_hide_discussion' ) ); 
     78        add_action( 'admin_bar_menu', array( 'Hide_Comments_Feature', 'remove_comments_from_admin_bar' ), 99 ); 
     79        add_action( 'get_comments_number', array( 'Hide_Comments_Feature', 'comments_number_always_zero' ) ); 
     80        add_action( 'comments_template', array( 'Hide_Comments_Feature', 'change_comments_template' ) ); 
     81        add_action( 'widgets_init', array( 'Hide_Comments_Feature', 'remove_comments_widget' ), 0 ); 
     82        add_action( 'wp_dashboard_setup', array( 'Hide_Comments_Feature', 'remove_dashboard_comments_widget' ), 0 ); 
     83         
     84    } 
     85     
     86    public static function init_everything() { 
     87        $args = array( 
     88            'public' => true, 
     89            '_builtin' => true, 
     90        ); 
     91         
     92        foreach ( apply_filters( 'hide_comments_post_types', get_post_types( $args ) ) as $post_type )  { 
     93            if ( post_type_supports( $post_type, 'comments' ) ) 
     94                remove_post_type_support( $post_type, 'comments' ); 
     95                 
     96        } 
     97         
     98    } 
     99     
     100    public static function remove_comments_css() { 
     101        ?> 
     102        <style type="text/css"> 
     103            .comments-link { 
     104                display: none; 
     105            } 
     106            <?php do_action( 'hide_comments_css' ); ?> 
     107        </style> 
     108        <!-- Hide Comments plugin --> 
     109        <?php 
     110         
     111    } 
     112     
     113    public static function remove_comments_link_meta() { 
     114        ?> 
     115        <style type="text/css"> 
     116            .widget_meta li:nth-child(4) { 
     117                display: none; 
     118            } 
     119        </style> 
     120        <!-- Hide Comments plugin --> 
     121        <?php 
     122    } 
     123     
     124    public static function remove_discussion_options() { 
     125        remove_menu_page( 'edit-comments.php' ); 
     126        remove_submenu_page( 'options-general.php', 'options-discussion.php' ); 
     127         
     128    } 
     129     
     130    public static function dashboard_right_now_hide_discussion() { 
     131        if ( ! apply_filters( 'hide_comments_dashboard_right_now', true ) ) 
     132            return; 
     133         
     134        ?> 
     135        <style type="text/css"> 
     136            #dashboard_right_now .table_discussion { 
     137                display: none; 
     138            } 
     139        </style> 
     140        <?php 
     141    } 
     142     
     143    public static function remove_comments_from_admin_bar( $admin_bar ) { 
     144        $admin_bar->remove_menu( 'comments' ); 
     145        return $admin_bar; 
     146         
     147    } 
     148     
     149    public static function comments_number_always_zero() { 
     150        return 0; 
     151         
     152    } 
     153     
     154    public static function change_comments_template() { 
     155        global $wp_query; 
     156         
     157        $wp_query->comments = array(); 
     158        $wp_query->comments_by_type = array(); 
     159        $wp_query->comment_count = '0'; 
     160        $wp_query->post->comment_count = '0'; 
     161        $wp_query->post->comment_status = 'closed'; 
     162        $wp_query->queried_object->comment_count = '0'; 
     163        $wp_query->queried_object->comment_status = 'closed'; 
     164         
     165        return apply_filters( 'hide_comments_template_comments_path', plugin_dir_path( __FILE__ ) . 'template-comments.php' ); 
     166         
     167    } 
     168     
     169    public static function remove_comments_widget() { 
     170        if ( function_exists( 'unregister_widget' ) ) { 
     171            unregister_widget( 'WP_Widget_Recent_Comments' ); 
     172     
     173        } 
     174         
     175    } 
     176     
     177    public static function remove_dashboard_comments_widget() { 
     178        remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); 
     179         
     180    } 
     181     
     182     
     183} 
     184 
     185new Hide_Comments_Feature; 
     186 
     187endif; 
     188 
     189 
     190 
     191/** 
     192 * hide_comments_activation_hook 
     193 *  
     194 * Register activation hook for plugin 
     195 *  
     196 * @since 0.3 
    54197 */ 
    55  
    56  
    57  
    58  
    59 // Checks if it is accessed from Wordpress Admin 
    60 if ( ! function_exists( 'add_action' ) ) { 
    61     header('Status: 403 Forbidden'); 
    62     header('HTTP/1.1 403 Forbidden'); 
    63     exit(); 
     198function hide_comments_activation_hook() { 
     199    // Wordpress version control. No compatibility with older versions. ( wp_die ) 
     200    if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) ) { 
     201        wp_die( 'Hide Comments is not compatible with versions prior to 3.4' ); 
     202     
     203    } 
     204     
     205    // Update to last version in 
     206    update_option( 'hide_comments_plugin_version', '0.3' );  
    64207     
    65208} 
    66  
    67  
    68 // Wordpress version control. No compatibility with older versions. ( wp_die ) 
    69 if ( version_compare( get_bloginfo( 'version' ), '2.8.0', '<' ) ) { 
    70     wp_die( 'Hide Comments is not compatible with versions prior to 2.8' ); 
    71  
    72 } 
    73  
    74  
    75 define( 'HIDE_COMMENTS_VERSION', 0.2 ); 
    76  
    77 if ( version_compare( get_option( 'hide_comments_version', 0.1 ), HIDE_COMMENTS_VERSION, '<' ) ) { 
    78     update_option( 'hide_comments_version', HIDE_COMMENTS_VERSION ); 
    79  
    80 } 
    81  
    82  
    83  
    84 /* Hide comments in Admin with jQuery */ 
    85 function hide_comments_admin_loads() { 
    86     wp_enqueue_script( 'jquery' ); 
    87     wp_enqueue_script( 'hide-comments', plugins_url( basename( dirname( __FILE__ ) ) ) . '/hide-comments.js', array( 'jquery' ), 1.0 ); 
    88  
    89 } 
    90 add_action( 'admin_init', 'hide_comments_admin_loads' ); 
    91  
    92  
    93  
    94  
    95  
    96 /* Unregister Comments Widget */ 
    97 function hide_comments_remove_widget() { 
    98     if ( function_exists( 'unregister_widget' ) ) { 
    99         unregister_widget( 'WP_Widget_Recent_Comments' ); 
    100  
    101     } 
    102      
    103 } 
    104 add_action( 'widgets_init', 'hide_comments_remove_widget', 0 ); 
    105  
    106  
    107 ?> 
     209register_activation_hook( __FILE__, 'hide_comments_activation_hook' ); 
  • hide-comments-feature/trunk/readme.txt

    r326266 r609535  
    11=== Hide Comments Feature === 
    2 Contributors: Vitor Carvalho, Lightningspirit.net 
    3 Tags: plugin, hide, comments, comment, admin, feature, core 
    4 Donate link: http://lightningspirit.net 
    5 Requires at least: 2.8 
    6 Tested up to: 3.0 
    7 Stable tag: 0.2 
    8 License: GPLv2 
     2Contributors: lightningspirit 
     3Tags: plugin, hide, remove, comments, comment, comments, dashboard, feature, core 
     4Donate link: http://vcarvalho.com/donate/ 
     5Requires at least: 3.4 
     6Tested up to: 3.5 
     7Stable tag: 0.3 
     8License: GPLv2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    99 
    10 If you do not need Comments functionality in your Wordpress instance, you can "hide" it with this plugin. 
     10Remove comments functionality and related in your Wordpress instance. 
    1111 
    1212 
     
    1414== Description == 
    1515 
    16 For those who do not need to have the Comments feature in them WordPress installation (for various reasons), this plugin completely removes any trace of the existence of this feature in the administration interface. 
    17 Completely done through techniques based on a combination of jQuery and URL. 
    18 Requires no configuration, just install and any trace of Comments disappears. 
    19 This does not modify the core, so it is an "upgrade-safe". 
     16For those who do not need to have the Comments feature in WordPress (there are a lot of reasons), this plugin removes any trace of that existence in both wp-admin and front-end. 
     17Your theme must rely properly on the WordPress API for the front-end support. The tag <?php comments_template(); ?> must be present. 
     18Completely done through techniques based on both action hooks and CSS. 
     19 
     20Doesn't requires any configuration, just install and any trace of Comments will disappear. 
     21 
     22NOTE: This does NOT play with the core, so you are able to update both plugins and WordPress without any afraid. 
     23 
     24= Provided Custom Hooks = 
     25 
     26This plugin provides 4 custom hooks you may play if you need more substance in your theme. 
     27 
     28`add_action( 'hide_comments_post_types', 'my_hide_comments_post_types' );` to change the list of post types to be processed by the plugin. Comments will be removed from all listed post types. 
     29`add_action( 'hide_comments_css', 'my_hide_comments_css' );` to add arbitrary CSS to hide comment's stuff from your theme. 
     30`add_action( 'hide_comments_template_comments_path', 'my_hide_comments_template_comments_path' );` the default path is the empty file template-comments.php located in the same dir of this plugin. Just modify the path to your own file if you want to return anything else. 
     31`add_action( 'hide_comments_dashboard_right_now', 'my_hide_comments_dashboard_right_now' );` if true is returned, the discussion table of dashboard right now widget will be hidden. False otherwise. Defaults to true. 
     32 
     33The use of these hooks are recommended, thus, if the plugin gets deactivated, those hooks will not be called anymore and then you get things consistent and clean. 
    2034 
    2135 
     
    24381. Upload `hide-comments-feature` folder to the `/wp-content/plugins/` directory 
    25392. Activate the plugin through the 'Plugins' menu in WordPress 
     403. No more configuration required. 
     41 
    2642 
    2743== Frequently Asked Questions == 
    2844 
    2945= Will this affect my Wordpress Instalation? = 
    30 No. It is an upgrade-safe plugin that does not affect the core. In other words, the feature still exists there but it is hidden. 
     46 
     47No. This won't play with the core! In other words, the feature still exists there but it is hidden by the plugin. 
    3148 
    3249= And about my theme? Comments still there... = 
    33 Off course! The purpose of this plugin is to help Web designers to create sites with Wordpress that do not need the comments functionality. 
    34 For this reason, Web designers create Themes without putting control methods for the comments on them. Thus they can ensure that their customers will no longer see mentioned the word "Comment". 
    35 If you want to remove the comments from your Theme the best you can do is to edit it and remove any methods that may exist. 
     50 
     51That's because your theme either is too old or it doesn't rely on the newest WordPress API. So you have to upgrade it, find a new one or, play with CSS to hide some HTML parts of the theme. 
     52Example of code to go into functions.php: 
     53`<?php 
     54function my_hide_comments_css() { 
     55    ?> 
     56    <style type="text/css"> 
     57    /* Your CSS here */ 
     58    </style> 
     59    <?php 
     60} 
     61add_action( 'hide_comments_css', 'my_hide_comments_css' ); 
     62?>` 
     63 
     64Though, the main purpose of this plugin is to help web designers and developers creating WordPress sites they can ensure that their users will no longer see mentioned the word "Comment". 
    3665 
    3766== Screenshots == 
    3867 
    39 1. The Comments button has gone! 
     681. There is no Comments menu link! 
     692. The comments template disappeared (magically) from the Twenty Twelve theme. 
    4070 
    4171 
    4272== Changelog == 
     73 
     74= 0.3 = 
     75* Huge update! Everything is now handled consistently. It is expected to be 3.4 and 3.5 compatible. 
     76* Optimal support for the new Twenty Twelve theme. 
     77* Added 4 custom action hooks (see )  
    4378 
    4479= 0.2 = 
     
    5085* Good support from FF3/4 and IE7 
    5186 
     87== Upgrade Notice == 
     88 
     89= 0.3 = 
     90 
     91Huge update! Completely rewritten! Everything is now handled consistently.  
     92New support for WordPress 3.4 and 3.5 using a combination of action hooks and CSS.  
     93Optimal support for the new Twenty Twelve theme.  
     94Provided 4 action hooks for developers. 
     95 
     96  
  • hide-comments-feature/trunk/uninstall.php

    r326266 r609535  
    1717if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 
    1818    exit(); 
     19     
    1920} 
    2021 
     
    2223 
    2324// Delete options from DB 
    24 delete_option( 'hide_comments_version' ); 
     25delete_option( 'hide_comments_plugin_version' ); 
    2526 
    2627 
    2728 
    2829// Bye! See you soon! 
    29  
    30 ?> 
Note: See TracChangeset for help on using the changeset viewer.