-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathselfish-fresh-start.php
296 lines (236 loc) · 8.92 KB
/
selfish-fresh-start.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
<?php
/**
* @link https://chuckreynolds.us
* @since 1.1.0
* @package Selfish_Fresh_Start
*
* Plugin Name: Selfish Fresh Start
* Plugin URI: https://wordpress.org/plugins/selfish-fresh-start/
* Description: Removes clutter and commonly unneeded things in WordPress. Full details in the plugin description.
* Version: 1.2.0
* Author: Chuck Reynolds
* Author URI: https://chuckreynolds.us
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: selfish-fresh-start
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* The core plugin class. Does all the things.
*
* @since 1.0.0
* @package Selfish_Fresh_Start
* @author Chuck Reynolds <chuck@rynoweb.com>
*/
class Selfish_Fresh_Start {
/**
* Construct for Selfish_Fresh_Start class
*
* @return void
*/
public function __construct() {
add_action( 'init', array( $this, 'nuke_init' ) );
add_action( 'after_setup_theme', array( $this, 'nuke_after_theme_setup' ) );
}
/**
* Functions called at the init action
*
* @return void
*/
public function nuke_init() {
$this->nuke_file_edit();
$this->nuke_trackbacks_smilies();
}
/**
* Removes theme and plugin editor links if not defined already
*
* @return void
*/
public function nuke_file_edit() {
if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {
define( 'DISALLOW_FILE_EDIT', 'true' );
}
}
/**
* Sets db options table flags
*
* @return string Closed: Disallow pingbacks and trackbacks from other blogs
* @return int No: Attempt to notify any blogs linked to from the article
* @return int No: Convert emoticons like :-) and :P to graphics when displayed
*/
public function nuke_trackbacks_smilies() {
$options = array(
'default_ping_status' => 'closed',
'default_pingback_flag' => 0,
'use_smilies' => 0
);
foreach( $options as $key => $value ) {
$current = get_option( $key );
if ( $current != $value ) {
update_option( $key, $value );
}
}
}
/**
* Functions called after the after_setup_theme action
*
* @return void
*/
public function nuke_after_theme_setup() {
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'welcome_panel', 'wp_welcome_panel' );
add_action( 'wp_dashboard_setup', array( $this, 'nuke_dashboard_metaboxes' ) );
add_action( 'do_meta_boxes', array( $this, 'nuke_plugin_metaboxes') );
add_action( 'admin_menu', array( $this, 'nuke_post_metaboxes' ) );
add_action( 'admin_menu', array( $this, 'nuke_page_metaboxes' ) );
add_action( 'admin_head', array( $this, 'nuke_update_notification_non_admins' ), 1 );
add_action( 'pre_ping', array( $this, 'nuke_self_pings' ) );
add_action( 'admin_init', array( $this, 'nuke_hello_dolly' ) );
add_filter( 'the_content_more_link', array( $this, 'nuke_more_jump_link_anchor' ) );
add_filter( 'content_save_pre', array( $this, 'nuke_curly_other_chars' ) );
add_filter( 'title_save_pre', array( $this, 'nuke_curly_other_chars' ) );
}
/**
* Removes some dashboard widgets
*
* @return void
*/
public function nuke_dashboard_metaboxes() {
#remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); // At a Glance
#remove_meta_box( 'network_dashboard_right_now', 'dashboard', 'normal' ); // Network Right Now
#remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); // Activity
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); // Quick Draft / Your Recent Drafts
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); // WordPress Events and News
// from older than WP ~4.0 versions
#remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); // incoming links box (deprecated in 3.8)
#remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); // new plugins box (deprecated in 3.8)
#remove_meta_box( 'dashboard_recent_comments','dashboard', 'normal' ); // recent comments sub (now part of activity)
#remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); // recent drafts (now part of quick_press)
#remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' ); // other wordpress news (deprecated in 3.8)
}
/**
* Removes some plugin dashboard widgets.
* Yup I'm goin there. Sorry not sorry.
*
* @return void
*/
public function nuke_plugin_metaboxes() {
remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'normal' ); // yoast seo overview
remove_meta_box( 'aw_dashboard', 'dashboard', 'normal' ); // wp socializer box
remove_meta_box( 'w3tc_latest', 'dashboard', 'normal' ); // w3 total cache news box
remove_meta_box( 'rg_forms_dashboard', 'dashboard', 'normal' ); // gravity forms
remove_meta_box( 'bbp-dashboard-right-now', 'dashboard', 'normal' ); // bbpress right now in forums
remove_meta_box( 'jetpack_summary_widget', 'dashboard', 'normal' ); // jetpack
remove_meta_box( 'tribe_dashboard_widget', 'dashboard', 'normal' ); // modern tribe rss widget
}
/**
* Removes some meta boxes from default posts screen
*
* @return void
*/
public function nuke_post_metaboxes() {
remove_meta_box( 'trackbacksdiv', 'post', 'normal' ); // trackbacks metabox
#remove_meta_box( 'postcustom', 'post', 'normal' ); // custom fields metabox
#remove_meta_box( 'postexcerpt', 'post', 'normal' ); // excerpt metabox
#remove_meta_box( 'commentstatusdiv', 'post', 'normal' ); // comments metabox
#remove_meta_box( 'slugdiv', 'post', 'normal' ); // slug metabox (breaks edit permalink update)
#remove_meta_box( 'authordiv', 'post', 'normal' ); // author metabox
#remove_meta_box( 'revisionsdiv', 'post', 'normal' ); // revisions metabox
#remove_meta_box( 'tagsdiv-post_tag', 'post', 'normal' ); // tags metabox
#remove_meta_box( 'categorydiv', 'post', 'normal' ); // comments metabox
}
/**
* Removes some meta boxes from default pages screen
*
* @return void
*/
public function nuke_page_metaboxes() {
remove_meta_box( 'commentstatusdiv', 'page', 'normal' ); // discussion metabox
remove_meta_box( 'commentsdiv', 'page', 'normal' ); // comments metabox
#remove_meta_box( 'postcustom', 'page', 'normal' ); // custom fields metabox
#remove_meta_box( 'slugdiv', 'page', 'normal' ); // slug metabox (breaks edit permalink update)
#remove_meta_box( 'authordiv', 'page', 'normal' ); // author metabox
#remove_meta_box( 'revisionsdiv', 'page', 'normal' ); // revisions metabox
#remove_meta_box( 'postimagediv', 'page', 'side' ); // featured image metabox
}
/**
* Removes update notifications for everybody except admin users
*
* @return void
*/
public function nuke_update_notification_non_admins() {
if ( ! current_user_can( 'update_core' ) ) {
remove_action( 'admin_notices', 'update_nag', 3 );
}
}
/**
* Disables potential to self-trackback
*
* @return void
*/
public function nuke_self_pings(&$links) {
foreach ( $links as $l => $link ) {
if ( 0 === strpos( $link, get_option( 'home' ) ) ) {
unset( $links[$l] );
}
}
}
/**
* Removes hellodolly plugin if it exists. sorry @photomatt
*
* @return void
*/
public function nuke_hello_dolly() {
if ( file_exists( WP_PLUGIN_DIR . '/hello.php' ) ) {
delete_plugins( array( 'hello.php' ) );
}
}
/**
* Modifies #more link to not use hashtag anchor
*
* @return void
*/
public function nuke_more_jump_link_anchor( $link ) {
$offset = strpos( $link, '#more-' );
if ( $offset ) {
$end = strpos( $link, '"', $offset );
}
if ( $end ) {
$link = substr_replace( $link, '', $offset, $end-$offset );
}
return $link;
}
/**
* Fixes curly quotes and badly formatted characters. One of my bigger pet peeves is curly quotes from word pastes
*
* @return string clean formated characters
*/
public function nuke_curly_other_chars( $fixChars ) {
$fixChars = str_replace(
array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
array("'", "'", '"', '"', '-', '—', '…'), $fixChars);
$fixChars = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
array("'", "'", '"', '"', '-', '—', '…'), $fixChars);
$fixChars = str_replace(
array('™', '©', '®'),
array('™', '©', '®'), $fixChars);
return $fixChars;
}
}
/**
* Begins execution of the plugin
*
* @since 1.1.0
*/
function run_selfish_fresh_start() {
$plugin = new Selfish_Fresh_Start();
}
run_selfish_fresh_start();