-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefitune.php
More file actions
408 lines (347 loc) · 13.9 KB
/
Copy pathrefitune.php
File metadata and controls
408 lines (347 loc) · 13.9 KB
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<?php
/**
* Plugin Name: RefiTune - Site refiner toolkit
* Plugin URI: https://rotistudio.com/plugins/refitune-site-refiner-toolkit-for-wordpress
* Description: Take control of WordPress with smart performance tweaks, security enhancements, and usability improvements. RefiTune is an all-in-one toolkit.
* Version: 1.3.1
* Requires at least: 6.2
* Requires PHP: 7.4
* Author: RotiStudio - Tamas Rottenbacher
* Author URI: https://rotistudio.com
* License: GPLv2 or later
* Text Domain: refitune
* Domain Path: /languages
*
* @package RefiTune
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'REFITUNE_VERSION', '1.3.1' );
define( 'REFITUNE_PATH', plugin_dir_path( __FILE__ ) );
define( 'REFITUNE_URL', plugin_dir_url( __FILE__ ) );
// Register and load translation files.
add_action( 'init', 'refitune_register_textdomain', 1 );
add_action( 'init', 'refitune_load_bundled_textdomain', 20 );
/**
* Register the plugin text domain path.
*
* @return void
*/
function refitune_register_textdomain(): void {
// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Bundled MO must register before override load on init:20.
load_plugin_textdomain( 'refitune', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Load bundled translations, overriding copies in wp-content/languages/plugins/.
*
* WordPress prefers language files installed under wp-content/languages/plugins/,
* which may be older than the plugin-shipped .mo during development.
*
* @return void
*/
function refitune_load_bundled_textdomain(): void {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core locale filter for textdomain loading.
$refitune_locale = apply_filters( 'plugin_locale', determine_locale(), 'refitune' );
$refitune_mofile = REFITUNE_PATH . 'languages/refitune-' . $refitune_locale . '.mo';
if ( ! is_readable( $refitune_mofile ) ) {
return;
}
unload_textdomain( 'refitune' );
load_textdomain( 'refitune', $refitune_mofile );
}
// Load encryption helpers.
require_once REFITUNE_PATH . 'includes/encryption.php';
/**
* Whether a RefiTune feature is available on the current WordPress version.
*
* @param array $refitune_feature Feature definition from refitune_get_features().
* @return bool
*/
function refitune_is_feature_available( array $refitune_feature ): bool {
if ( ! empty( $refitune_feature['max_wp_version'] ) ) {
if ( version_compare( get_bloginfo( 'version' ), (string) $refitune_feature['max_wp_version'], '>=' ) ) {
return false;
}
}
if ( ! empty( $refitune_feature['requires_webp_support'] ) ) {
require_once REFITUNE_PATH . 'includes/webp-converter.php';
if ( ! refitune_webp_server_supports() ) {
return false;
}
}
return true;
}
/**
* Return the plugin settings array.
*
* Thin wrapper around get_option() so every module reads settings the same
* way. WordPress caches autoloaded options in memory, so repeated calls are
* cheap and always reflect mid-request updates.
*
* @return array
*/
function refitune_get_settings(): array {
return (array) get_option( 'refitune_settings', array() );
}
/**
* Whether a file extension is allowed by the multisite network upload policy.
*
* On single-site installs this always returns true. On multisite it respects
* the network `upload_filetypes` setting.
*
* @param string $refitune_ext File extension without a leading dot.
* @return bool
*/
function refitune_network_allows_upload_extension( string $refitune_ext ): bool {
if ( ! is_multisite() ) {
return true;
}
$refitune_ext = strtolower( ltrim( $refitune_ext, '.' ) );
$refitune_allowed = explode( ' ', strtolower( (string) get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ) );
$refitune_allowed = array_filter( array_map( 'trim', $refitune_allowed ) );
return in_array( $refitune_ext, $refitune_allowed, true );
}
/**
* Restore default cron schedules on plugin deactivation.
*
* When Automatic Updates Control changed the update check interval, the
* custom cron recurrences disappear with the plugin, so the update check
* events must be restored to the WordPress default schedule.
*
* @return void
*/
function refitune_deactivate(): void {
$refitune_settings = refitune_get_settings();
if ( ! empty( $refitune_settings['auto_updates_control'] ) ) {
require_once REFITUNE_PATH . 'modules/auto-updates.php';
refitune_restore_default_update_check_schedules();
}
wp_clear_scheduled_hook( 'refitune_trash_delete_continue' );
}
register_deactivation_hook( __FILE__, 'refitune_deactivate' );
$refitune_settings = refitune_get_settings();
// --- Header cleanup ---
$refitune_cleanup_head_keys = array(
'cleanup_head_generator',
'cleanup_head_wc_generator',
'cleanup_head_rsd',
'cleanup_head_wlwmanifest',
'cleanup_head_shortlink',
'cleanup_head_adjacent_posts',
);
foreach ( $refitune_cleanup_head_keys as $refitune_ck ) {
if ( ! empty( $refitune_settings[ $refitune_ck ] ) ) {
require_once REFITUNE_PATH . 'modules/cleanup-head.php';
break;
}
}
// --- Feed link removal ---
$refitune_disable_feeds_keys = array( 'disable_feeds_posts', 'disable_feeds_comments', 'disable_feeds_extra' );
foreach ( $refitune_disable_feeds_keys as $refitune_dk ) {
if ( ! empty( $refitune_settings[ $refitune_dk ] ) ) {
require_once REFITUNE_PATH . 'modules/disable-feeds.php';
break;
}
}
// --- Disable emoji ---
if ( ! empty( $refitune_settings['disable_emoji'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-emoji.php';
}
// --- Disable jQuery Migrate ---
if ( ! empty( $refitune_settings['disable_jquery_migrate'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-jquery-migrate.php';
}
// --- Disable oEmbed ---
if ( ! empty( $refitune_settings['disable_oembed'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-oembed.php';
}
// --- Remove CSS/JS ver query strings ---
if ( ! empty( $refitune_settings['remove_asset_versions'] ) ) {
require_once REFITUNE_PATH . 'modules/remove-asset-versions.php';
}
// --- Disable XML-RPC ---
if ( ! empty( $refitune_settings['disable_xmlrpc'] ) ) {
// Block direct access to xmlrpc.php with a 404 response so the file
// appears not to exist to attackers.
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
http_response_code( 404 );
header( 'Content-Type: text/html; charset=utf-8' );
exit( '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1><p>The requested URL was not found on this server.</p></body></html>' );
}
require_once REFITUNE_PATH . 'modules/disable-xmlrpc.php';
}
// --- Disable comments ---
if ( ! empty( $refitune_settings['disable_comments'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-comments.php';
}
// --- Disable trackbacks ---
if ( ! empty( $refitune_settings['disable_trackbacks'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-trackbacks.php';
}
// --- Disable file editor ---
if ( ! empty( $refitune_settings['disable_file_edit'] ) ) {
require_once REFITUNE_PATH . 'modules/disable-file-edit.php';
}
// --- Login tweaks ---
if ( ! empty( $refitune_settings['login_tweaks'] ) ) {
require_once REFITUNE_PATH . 'modules/login-tweaks.php';
}
// --- Hide admin bar ---
if ( ! empty( $refitune_settings['hide_admin_bar_enabled'] ) ) {
require_once REFITUNE_PATH . 'modules/hide-admin-bar.php';
}
// --- SVG and AVIF upload ---
$refitune_svg_enabled = ! empty( $refitune_settings['svg_upload_enabled'] );
$refitune_avif_enabled = ! empty( $refitune_settings['avif_upload_enabled'] );
$refitune_svg_roles = isset( $refitune_settings['svg_upload_roles'] ) ? (array) $refitune_settings['svg_upload_roles'] : array();
$refitune_avif_roles = isset( $refitune_settings['avif_upload_roles'] ) ? (array) $refitune_settings['avif_upload_roles'] : array();
if ( ( $refitune_svg_enabled && ! empty( $refitune_svg_roles ) ) || ( $refitune_avif_enabled && ! empty( $refitune_avif_roles ) ) ) {
require_once REFITUNE_PATH . 'modules/svg-avif-upload.php';
}
// --- Block visibility ---
if ( ! empty( $refitune_settings['block_visibility'] ) && version_compare( get_bloginfo( 'version' ), '7.0', '<' ) ) {
require_once REFITUNE_PATH . 'modules/block-visibility.php';
}
// --- External links in new window ---
if ( ! empty( $refitune_settings['external_links'] ) ) {
require_once REFITUNE_PATH . 'modules/external-links.php';
}
// --- Enable page excerpt ---
if ( ! empty( $refitune_settings['page_excerpt'] ) ) {
require_once REFITUNE_PATH . 'modules/page-excerpt.php';
}
// --- Post revisions limit ---
if ( isset( $refitune_settings['post_revisions_limit'] ) && '' !== $refitune_settings['post_revisions_limit'] ) {
require_once REFITUNE_PATH . 'modules/post-revisions.php';
}
// --- Auto-save interval ---
if ( isset( $refitune_settings['autosave_interval'] ) && '' !== $refitune_settings['autosave_interval'] ) {
require_once REFITUNE_PATH . 'modules/autosave-interval.php';
}
// --- Trash Auto-Delete ---
if ( isset( $refitune_settings['trash_auto_delete_days'] ) && '' !== $refitune_settings['trash_auto_delete_days'] ) {
require_once REFITUNE_PATH . 'modules/trash-auto-delete.php';
}
// --- Heartbeat Control ---
if ( ! empty( $refitune_settings['heartbeat_control'] ) ) {
require_once REFITUNE_PATH . 'modules/heartbeat-control.php';
}
// --- Email SMTP / disable all ---
$refitune_email_mode = isset( $refitune_settings['email_mode'] ) ? $refitune_settings['email_mode'] : 'default';
if ( 'disable_all' === $refitune_email_mode || 'smtp' === $refitune_email_mode ) {
require_once REFITUNE_PATH . 'modules/email-smtp.php';
}
// --- Email notifications ---
$refitune_email_control_keys = array(
'email_disable_update',
'email_disable_new_user',
'email_disable_password_reset',
'email_disable_comments',
'email_disable_privacy',
'email_disable_critical',
);
foreach ( $refitune_email_control_keys as $refitune_eck ) {
if ( ! empty( $refitune_settings[ $refitune_eck ] ) ) {
require_once REFITUNE_PATH . 'modules/email-controls.php';
break;
}
}
// --- Login page customization ---
if ( ! empty( $refitune_settings['login_customizer_enabled'] ) ) {
require_once REFITUNE_PATH . 'modules/login-customizer.php';
}
// --- Role redirects ---
if ( ! empty( $refitune_settings['role_redirects_enabled'] ) ) {
$refitune_login_redirects = isset( $refitune_settings['role_redirects_login'] ) && is_array( $refitune_settings['role_redirects_login'] ) ? $refitune_settings['role_redirects_login'] : array();
$refitune_logout_redirects = isset( $refitune_settings['role_redirects_logout'] ) && is_array( $refitune_settings['role_redirects_logout'] ) ? $refitune_settings['role_redirects_logout'] : array();
if ( ! empty( $refitune_login_redirects ) || ! empty( $refitune_logout_redirects ) ) {
require_once REFITUNE_PATH . 'modules/role-redirects.php';
}
}
// --- Maintenance Mode ---
if ( ! empty( $refitune_settings['maintenance_mode_enabled'] ) ) {
$refitune_maintenance_roles = isset( $refitune_settings['maintenance_mode_roles'] )
? (array) $refitune_settings['maintenance_mode_roles']
: array();
if ( ! empty( $refitune_maintenance_roles ) ) {
require_once REFITUNE_PATH . 'modules/maintenance-mode.php';
}
}
// --- Dynamic Year Shortcodes ---
if ( ! empty( $refitune_settings['dynamic_year'] ) ) {
require_once REFITUNE_PATH . 'modules/dynamic-year.php';
}
// --- Restrict admin access ---
if ( ! empty( $refitune_settings['admin_access_enabled'] ) ) {
require_once REFITUNE_PATH . 'modules/admin-access.php';
}
// --- REST API restrictions ---
$refitune_rest_api_keys = array( 'rest_disable_users', 'rest_restrict_index', 'rest_disable_media', 'rest_disable_comments', 'rest_disable_search' );
$refitune_rest_api_active = false;
foreach ( $refitune_rest_api_keys as $refitune_rest_key ) {
if ( ! empty( $refitune_settings[ $refitune_rest_key ] ) ) {
$refitune_rest_api_active = true;
break;
}
}
if ( $refitune_rest_api_active ) {
require_once REFITUNE_PATH . 'modules/rest-api-restrictions.php';
}
// --- Login limit ---
if ( ! empty( $refitune_settings['login_limit_enabled'] ) ) {
require_once REFITUNE_PATH . 'modules/login-limit.php';
}
// --- Verified upload ---
if ( ! empty( $refitune_settings['upload_security'] ) ) {
require_once REFITUNE_PATH . 'modules/upload-security.php';
}
// --- Clean upload filenames ---
if ( ! empty( $refitune_settings['upload_filename_sanitize'] ) ) {
require_once REFITUNE_PATH . 'modules/upload-filename-sanitize.php';
}
// --- WebP upload conversion ---
if ( ! empty( $refitune_settings['upload_webp_convert'] ) ) {
require_once REFITUNE_PATH . 'includes/webp-converter.php';
if ( refitune_webp_server_supports() ) {
require_once REFITUNE_PATH . 'modules/upload-webp-convert.php';
}
}
// --- Automatic updates control ---
if ( ! empty( $refitune_settings['auto_updates_control'] ) ) {
require_once REFITUNE_PATH . 'modules/auto-updates.php';
refitune_auto_updates_module_init();
}
// Translatable plugin description on the plugins list screen.
add_filter(
'all_plugins',
function ( $plugins ) {
$refitune_plugin_file = plugin_basename( __FILE__ );
if ( isset( $plugins[ $refitune_plugin_file ] ) ) {
$plugins[ $refitune_plugin_file ]['Description'] = __( 'Collects useful refinements and fine-tuning options (performance, security, usability).', 'refitune' );
}
return $plugins;
}
);
if ( is_admin() ) {
require_once REFITUNE_PATH . 'admin/admin-core.php';
}
/**
* Show an admin warning when encryption is unavailable but SMTP needs it.
*
* @return void
*/
function refitune_encryption_admin_notice() {
if ( ! current_user_can( 'manage_options' ) || refitune_encryption_available() ) {
return;
}
$refitune_settings = refitune_get_settings();
if ( 'smtp' !== ( $refitune_settings['email_mode'] ?? 'default' ) ) {
return;
}
printf(
'<div class="notice notice-error"><p><strong>RefiTune:</strong> %s</p></div>',
esc_html__( 'The PHP Sodium extension is not available, so SMTP credentials cannot be decrypted securely. SMTP email sending is disabled until Sodium is enabled on the server.', 'refitune' )
);
}
add_action( 'admin_notices', 'refitune_encryption_admin_notice', 10 );