Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 336 lines (282 sloc) 9.31 kb
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
1 <?php
2 /**
3 * Plugin Name: Remove Comments Absolutely
4 * Plugin URI: http://wpengineer.com/2230/removing-comments-absolutely-wordpress/
5 * Text Domain: remove_comments_absolute
6 * Domain Path: /languages
7 * Description: Deactivate comments functions and remove areas absolutely from the WordPress install
8 * Author: Frank Bültge
2b56dd7 @bueltge enhanced php doc
authored
9 * Version: 1.0.0
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
10 * Licence: GPLv3
11 * Author URI: http://bueltge.de/
12 * Upgrade Check: none
13 */
14
15 if ( ! class_exists( 'Remove_Comments_Absolute' ) ) {
16 add_action( 'plugins_loaded', array( 'Remove_Comments_Absolute', 'get_object' ) );
17
18 class Remove_Comments_Absolute {
19
20 static private $classobj = NULL;
21
22 /**
23 * Constructor, init on defined hooks of WP and include second class
24 *
25 * @access public
26 * @since 0.0.1
27 * @uses add_filter, add_action
28 * @return void
29 */
30 public function __construct() {
31
54f28df @bueltge small codex changes
authored
32 // remove update check
33 add_filter( 'site_transient_update_plugins', array( $this, 'remove_update_nag' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
34
54f28df @bueltge small codex changes
authored
35 add_filter( 'the_posts', array( $this, 'set_comment_status' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
36
54f28df @bueltge small codex changes
authored
37 add_filter( 'comments_open', array( $this, 'close_comments'), 10, 2 );
38 add_filter( 'pings_open', array( $this, 'close_comments'), 10, 2 );
39
40 add_action( 'admin_init', array( $this, 'remove_comments' ) );
41 add_action( 'admin_menu', array( $this, 'remove_menu_items' ) );
42 add_filter( 'add_menu_classes', array( $this, 'add_menu_classes' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
43
7c74b9c @bueltge Enhancement for issue #7
authored
44 // remove items in dashboard
54f28df @bueltge small codex changes
authored
45 add_action( 'admin_footer-index.php', array( $this, 'remove_comments_areas' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
46
2b56dd7 @bueltge enhanced php doc
authored
47 // chane admin bar items
54f28df @bueltge small codex changes
authored
48 add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar_render' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
49
50 // remove string on frontend in Theme
54f28df @bueltge small codex changes
authored
51 add_filter( 'gettext', array( $this, 'remove_theme_string' ), 20, 3 );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
52
53 // remove comment feed
54f28df @bueltge small codex changes
authored
54 remove_action( 'wp_head', 'feed_links', 2 );
55 add_action( 'wp_head', array( $this, 'feed_links' ), 2 );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
56
57 // remove default comment widget
54f28df @bueltge small codex changes
authored
58 add_action( 'widgets_init', array( $this, 'unregister_default_wp_widgets' ), 1 );
7c74b9c @bueltge Enhancement for issue #7
authored
59
60 // remove comment options in profile page
54f28df @bueltge small codex changes
authored
61 add_action( 'personal_options', array( $this, 'remove_profile_items' ) );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
62 }
63
64 /**
65 * Handler for the action 'init'. Instantiates this class.
66 *
67 * @access public
68 * @since 0.0.1
69 * @return object $classobj
70 */
71 public function get_object() {
72
73 if ( NULL === self :: $classobj ) {
74 self :: $classobj = new self;
75 }
76
77 return self :: $classobj;
78 }
79
80 /**
54f28df @bueltge small codex changes
authored
81 * Disable plugin update notifications
82 *
83 * @param unknown_type $value
84 * @since 1.0.0 04/02/2012
85 * @link http://dd32.id.au/2011/03/01/disable-plugin-update-notification-for-a-specific-plugin-in-wordpress-3-1/
86 * @param array string $value
87 * @return array string $value
88 */
89 public function remove_update_nag( $value ) {
90
91 if ( isset( $value ) && is_object( $value ) )
92 unset( $value->response[ plugin_basename( __FILE__ ) ] );
93
94 return $value;
95 }
96
97 /**
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
98 * Set the status on posts and pages - is_singular ()
99 *
100 * @access public
101 * @since 0.0.1
102 * @uses is_singular
103 * @param string $posts
104 * @return string $posts
105 */
106 public function set_comment_status( $posts ) {
107
108 if ( ! empty( $posts ) && is_singular() ) {
109 $posts[0]->comment_status = 'closed';
110 $posts[0]->post_status = 'closed';
111 }
112
113 return $posts;
114 }
115
116 /**
117 * Close comments, if open
118 *
119 * @access public
120 * @since 0.0.1
121 * @param string | boolean $open
122 * @param string | integer $post_id
123 * @eturn string $posts
124 */
125 public function close_comments( $open, $post_id ) {
54f28df @bueltge small codex changes
authored
126
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
127 // if not open, than back
128 if ( ! $open )
129 return $open;
130
131 $post = get_post( $post_id );
54f28df @bueltge small codex changes
authored
132 if ( $post->post_type ) // all post types
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
133 return FALSE;
134
135 return $open;
136 }
137
138 /**
139 * Change options for dont use comments
140 * Remove meta boxes on edit pages
141 * Remove support on all post types for comments
142 * Remove menu-entries
143 *
144 * @access public
145 * @since 0.0.1
146 * @uses update_option, get_post_types, remove_meta_box, remove_post_type_support
147 * @return void
148 */
149 public function remove_comments() {
54f28df @bueltge small codex changes
authored
150
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
151 // int values
152 foreach ( array( 'comments_notify', 'default_pingback_flag' ) as $option )
153 update_option( $option, 0 );
154 // string false
155 foreach ( array( 'default_comment_status', 'default_ping_status' ) as $option )
156 update_option( $option, 'false' );
157
158 // all post types
159 // alternative define an array( 'post', 'page' )
160 foreach ( get_post_types() as $post_type ) {
161 // comment status
162 remove_meta_box( 'commentstatusdiv', $post_type, 'normal' );
163 // remove trackbacks
164 remove_meta_box( 'trackbacksdiv', $post_type, 'normal' );
165 // remove all comments/trackbacks from tabels
166 remove_post_type_support( $post_type, 'comments' );
167 remove_post_type_support( $post_type, 'trackbacks' );
168 }
54f28df @bueltge small codex changes
authored
169
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
170 // remove dashboard meta box for recents comments
171 remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
172 }
173
174 /**
175 * Remove menu-entries
176 *
177 * @access public
178 * @since 0.0.3
179 * @uses remove_meta_box, remove_post_type_support
180 * @return void
181 */
182 public function remove_menu_items() {
54f28df @bueltge small codex changes
authored
183
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
184 // Remove menu entries with WP 3.1 and higher
185 if ( function_exists( 'remove_menu_page' ) ) {
186 remove_menu_page( 'edit-comments.php' );
187 remove_submenu_page( 'options-general.php', 'options-discussion.php' );
188 } else {
189 // unset comments
190 unset( $GLOBALS['menu'][25] );
191 // unset menuentry Discussion
192 unset( $GLOBALS['submenu']['options-general.php'][25] );
193 }
194 }
195
196 /**
197 * Add class for last menu entry with no 20
198 *
199 * @access public
200 * @since 0.0.1
201 * @param array string $menu
202 * @return array string $menu
203 */
204 function add_menu_classes( $menu ) {
205
206 if ( isset( $menu[20][4] ) )
207 $menu[20][4] .= ' menu-top-last';
208
209 return $menu;
210 }
211
212 /**
213 * Remove areas for comments in backend via JS
214 *
215 * @access public
216 * @since 0.0.1
217 * $return string with js
218 */
219 public function remove_comments_areas() {
220 ?>
221 <script type="text/javascript">
7c74b9c @bueltge Enhancement for issue #7
authored
222 //<![CDATA[
223 jQuery(document).ready( function($) {
224 $( 'div.table_discussion' ).remove();
225 $( 'div.musubtable' ).remove();
226 });
227 //]]>
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
228 </script>
229 <?php
230 }
231
232 /**
233 * Remove comment entry in Admin Bar
234 *
235 * @access public
236 * @since 0.0.1
237 * @uses remove_menu
238 * $return void
239 */
240 public function admin_bar_render() {
54f28df @bueltge small codex changes
authored
241
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
242 // remove comment item in blog -list for "My Sites" in Admin Bar
243 if ( isset( $GLOBALS['blog_id'] ) )
54f28df @bueltge small codex changes
authored
244 $GLOBALS['wp_admin_bar']->remove_menu( 'blog-' . $GLOBALS['blog_id'] . '-c' );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
245 // remove entry in admin bar
54f28df @bueltge small codex changes
authored
246 $GLOBALS['wp_admin_bar']->remove_menu( 'comments' );
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
247 }
248
249 /**
250 * Display the links to the general feeds, without comments
251 *
252 * @access public
253 * @since 0.0.4
254 * @uses current_theme_supports, wp_parse_args, feed_content_type, get_bloginfo, esc_attr, get_feed_link, _x, __
255 * @param array $args Optional arguments
256 * @return string
257 */
258 public function feed_links( $args = array() ) {
259
54f28df @bueltge small codex changes
authored
260 if ( ! current_theme_supports( 'automatic-feed-links' ) )
261 return NULL;
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
262
263 $defaults = array(
54f28df @bueltge small codex changes
authored
264 // translators: Separator between blog name and feed type in feed links
265 'separator' => _x( '&raquo;', 'feed link', 'remove_comments_absolute' ),
266 // translators: 1: blog title, 2: separator (raquo)
267 'feedtitle' => __( '%1$s %2$s Feed', 'remove_comments_absolute' ),
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
268 );
269
270 $args = wp_parse_args( $args, $defaults );
271
272 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' .
54f28df @bueltge small codex changes
authored
273 esc_attr(
274 sprintf(
275 $args['feedtitle'],
276 get_bloginfo('name'),
277 $args['separator']
278 )
279 ) . '" href="' . get_feed_link() . '"/>' . "\n";
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
280 }
281
282 /**
283 * Unregister default comment widget
284 *
285 * @since 07/16/2012
286 * @param void
287 * @return void
288 */
289 public function unregister_default_wp_widgets() {
290
291 unregister_widget('WP_Widget_Recent_Comments');
292 }
293
2b56dd7 @bueltge enhanced php doc
authored
294 /**
295 * Remove options for Keyboard Shortcuts on profile page
296 *
297 * @since 09/03/2012
298 * @param void
299 * @return void
300 */
7c74b9c @bueltge Enhancement for issue #7
authored
301 public function remove_profile_items() {
302 ?>
303 <script type="text/javascript">
304 //<![CDATA[
305 jQuery(document).ready( function($){
306 $('#your-profile .form-table tr:nth-child(3)').remove();
307 });
308 //]]>
309 </script>
310 <?php
311 }
312
5be3455 @bueltge Add function to remove comment widget #issue #6
authored
313 /**
314 * On posts where comments are closed, the plugin will remove the text 'Comments are closed.'
315 *
316 * @access public
317 * @since 0.0.7
318 * @uses get_translations_for_domain
319 * @return string empty
320 */
321 public function remove_theme_string( $translation, $text, $domain ) {
322
323 if ( is_admin() )
324 return $translation;
325
326 $translations = &get_translations_for_domain( $domain );
327 if ( 'Comments are closed.' === $text )
328 return '';
329
330 return $translation;
331 }
332
333 } // end class
334
335 } // end if class exists
Something went wrong with that request. Please try again.