-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit.php
382 lines (319 loc) · 9.5 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* Plugin Name: WP Strip Naked
* Plugin URI: http://
* Description: Strips WordPress built in stuff down to it's bare essentials
* Version: 0.5
* Author: Franz Josef Kaiser
* Author URI: http://unserkaiser.com
* Text Domain: wp_strip_naked
* Domain Path: /lang
*
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
// Prevent loading this file directly - Busted!
defined( 'ABSPATH' ) OR exit;
/**
* SETUP & INIT PLUGIN
* Triggers on the "plugins_loaded" hook, as "muplugins_loaded" is too early
*/
include_once plugin_dir_path( __FILE__ ).'setup.php';
register_uninstall_hook( __FILE__, array( 'WP_Strip_Naked_Setup', 'on_uninstall' ) );
register_activation_hook( __FILE__, array( 'WP_Strip_Naked_Setup','on_activate' ) );
add_action( 'plugins_loaded', array( 'WP_Strip_Naked', 'init' ) );
/**
* Strip all of WP down to naked
*
* @author Franz Josef Kaiser
* @since 0.1
* @version 0.1
* @package WordPress Strip Naked
* @subpackage
*/
class WP_Strip_Naked
{
protected static $instance;
/**
* Container for Plugin Settings
*
* @since 0.3
* @var
*/
public $options;
/**
* Handler for the action 'init'. Instantiates this class.
* @return void
*/
public static function init()
{
is_null( self :: $instance ) AND self :: $instance = new self;
return self :: $instance;
}
public function __construct()
{
$this->setup_options();
add_action( 'init', array( $this, 'capital_p_bangit' ) );
add_action( 'init', array( $this, 'taxonomies' ) );
add_action( 'init', array( $this, 'post_types' ) );
add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar' ) );
add_filter( 'parent_file', array( $this, 'admin_menu' ) );
add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widgets' ) );
add_filter( 'admin_footer_text', '__return_false' );
add_filter( 'update_footer', '__return_false', 11 );
add_action( 'init', array( $this, 'feed' ) );
add_action( 'admin_print_styles-options.php', array( $this, 'styles' ), 20 );
add_action( 'all_admin_notices', array( $this, 'note' ), 20 );
# add_filter( 'page_template', array( $this, 'page_template' ), 10, 1 );
# add_filter( 'comments_popup_template', array( $this, 'comments_popup_template' ), 10, 1 );
}
public function setup_options()
{
$this->options['feed'] = get_option( 'strip_feed' );
$this->options['pages'] = get_option( 'strip_pages' );
}
/**
* Remove the Wordpress > WordPress filter
*
* @since 0.4
*
* @return void
*/
public function capital_p_bangit()
{
remove_filter( 'the_title', 'capital_P_dangit', 11 );
remove_filter( 'the_content', 'capital_P_dangit', 11 );
remove_filter( 'comment_text', 'capital_P_dangit', 31 );
}
/**
* Adds a new "WP Strip Naked" Settings Section above the all settings page
*
* @since 0.3
*
* @return string $html;
*/
public function note()
{
global $pagenow;
if ( 'options.php' !== $pagenow )
return;
// Add new separate Strip Settings section
screen_icon();
$html = '<div class="wrap"><h2>';
$html .= __( 'WP Strip Naked Settings', '' );
$html .= '</h2>';
$html .= "<p>";
$html .= sprintf( __( 'Plugin settings are highlighted in %sblue', '' ), '<span id="strip_note">' );
$html .= "</span>.</p>";
print $html;
}
/**
* Adds a Note to the strip settings section
*
* @since 0.3
*
* @return void
*/
public function styles()
{
echo <<<EOF
<style type="text/css">#strip_note,#strip_feed,#strip_pages {color:#fff;background:#009ee0;}</style>
EOF;
}
public function page_template( $templates )
{
$templates = array();
return $templates;
}
public function comments_popup_template( $templates )
{
$templates = array();
return $templates;
}
/**
* Removes all built in taxonomies
* Leaves only the "nav-menu" taxonomy
*
* @since 0.1
*
* @return void
*/
public function taxonomies()
{
global $wp_taxonomies;
unset( $wp_taxonomies['category'] );
unset( $wp_taxonomies['post_tag'] );
unset( $wp_taxonomies['link_category'] );
unset( $wp_taxonomies['post_format'] );
}
/**
* Removes the by default built in post types of "Post" & "Page"
*
* @since 0.1
*
* @return void
*/
public function post_types()
{
global $wp_post_types;
unset( $wp_post_types['post'] );
if ( 1 != $this->options['pages'] )
unset( $wp_post_types['page'] );
}
/**
* Removes all admin bar items
* Leaves only the site name that can be used to access the public view
*
* @since 0.1
*
* @return void
*/
public function admin_bar()
{
global $wp_admin_bar;
if ( ! is_admin_bar_showing() )
return;
$wp_admin_bar->remove_menu( 'wp-logo' );
$wp_admin_bar->remove_menu( 'comments' );
$wp_admin_bar->remove_menu( 'my-account' );
$wp_admin_bar->remove_menu( 'appearance' );
$wp_admin_bar->remove_menu( 'new-content' );
$wp_admin_bar->remove_menu( 'my-account-with-avatar' );
}
/**
* Removes all menu & submenu items for the admin menu
* for stuff that's built in
* Also removes all settings pages and replaces them
* with an "All Settings" page
*
* @since 0.1
*
* @param string $parent_file
* @return string $parent_file
*/
public function admin_menu( $parent_file )
{
global $menu, $submenu;
# >>>> Sub menu items
// Add New Post
remove_submenu_page( 'edit.php', 'post-new.php' );
// Add New Link
remove_submenu_page( 'link-manager.php', 'link-add.php' );
// Link Taxonomy
remove_submenu_page( 'link-manager.php', 'edit-tags.php?taxonomy=link_category' );
// Add New Page
if ( 1 != $this->options['pages'] )
remove_submenu_page( 'edit.php?post_type=page', 'post-new.php?post_type=page' );
// Theme Editor
remove_submenu_page( 'themes.php', 'theme-editor.php' );
// Plugins Editor
remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
// Settings General
remove_submenu_page( 'options-general.php', 'options-general.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-writing.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-reading.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-media.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-privacy.php' );
// Settings
remove_submenu_page( 'options-general.php', 'options-permalink.php' );
# <<<< Sub menu items
# >>>> Main menu items
// Posts
remove_menu_page( 'edit.php' );
// Links
remove_menu_page( 'link-manager.php' );
// Pages
if ( 1 != $this->options['pages'] )
remove_menu_page( 'edit.php?post_type=page' );
// Comments
remove_menu_page( 'edit-comments.php' );
# <<<< Main menu items
// Add all options page instead
add_submenu_page(
'options-general.php'
,__( 'All Options' )
,__( 'All Settings' )
,'manage_options'
,'options.php'
);
$opt_first = reset( array_keys( $submenu[ 'options-general.php' ] ) );
// (Re)move
foreach ( $submenu[ 'options-general.php' ] as $i => $item )
{
if ( 'options.php' == $item[2] )
{
unset( $submenu[ 'options-general.php' ][ $i ] );
$submenu[ 'options-general.php' ][ $opt_first - 1 ] = $item;
}
}
// Sort
sort( $submenu[ 'options-general.php' ] );
return $parent_file;
}
/**
* Removes all default meta boxes from the dashboard
* Leaves only "Incoming Links"
*
* @since 0.1
*
* @return void
*/
public function dashboard_widgets()
{
remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' );
}
/**
* Disables the feed on demand
*
* @since 0.3
*
* @return void
*/
public function feed()
{
if ( 1 != $this->options['feed'] )
return;
add_action( 'do_feed', 'disable_feed_cb', 1 );
add_action( 'do_feed_rdf', 'disable_feed_cb', 1 );
add_action( 'do_feed_rss', 'disable_feed_cb', 1 );
add_action( 'do_feed_rss2', 'disable_feed_cb', 1 );
add_action( 'do_feed_atom', 'disable_feed_cb', 1 );
}
/**
* Callback fn to disable the feed
* Replaces it with a notice to visit the site
*
* @since 0.2
*
* @return void
*/
function disable_feed_cb()
{
$url = get_bloginfo( 'url' );
wp_die(
sprintf(
__( 'Please visit our %s.' )
,"<a href='{$url}'>site</a>"
)
,__( 'No Feed available' )
);
}
}