PluginProbe
Admin and Site Enhancements (ASE) / 5.0.2
Admin and Site Enhancements (ASE) v5.0.2
9.1.1 9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 All 273 releases
admin-site-enhancements / bootstrap.php
bootstrap.php
737 lines 35.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // We're using the singleton design pattern
4 // https://code.tutsplus.com/articles/design-patterns-in-wordpress-the-singleton-pattern--wp-31621
5 // https://carlalexander.ca/singletons-in-wordpress/
6 // https://torquemag.io/2016/11/singletons-wordpress-good-evil/
7 /**
8 * Main class of the plugin used to add functionalities
9 *
10 * @since 1.0.0
11 */
12 class Admin_Site_Enhancements
13 {
14 // Refers to a single instance of this class
15 private static $instance = null ;
16 /**
17 * Creates or returns a single instance of this class
18 *
19 * @return Admin_Site_Enhancements a single instance of this class
20 * @since 1.0.0
21 */
22 public static function get_instance()
23 {
24 if ( null == self::$instance ) {
25 self::$instance = new self();
26 }
27 return self::$instance;
28 }
29
30 /**
31 * Initialize plugin functionalities
32 */
33 private function __construct()
34 {
35 // Setup admin menu, admin page, settings, settings sections, sections fields, admin scripts, plugin action links, etc.
36 // Register admin menu and add the settings page.
37 add_action( 'admin_menu', 'asenha_register_admin_menu' );
38 // Register plugin settings
39 // Instantiate object for registration of settings section and fields
40 $settings = new ASENHA\Classes\Settings_Sections_Fields();
41 add_action( 'admin_init', [ $settings, 'register_sections_fields' ] );
42 // Suppress all notices on the plugin's main page. Then add notification for successful settings update.
43 add_action( 'admin_notices', 'asenha_suppress_notices', 5 );
44 add_action( 'all_admin_notices', 'asenha_suppress_generic_notices', 5 );
45 // Enqueue admin scripts and styles
46 add_action( 'admin_enqueue_scripts', 'asenha_admin_scripts' );
47 // Enqueue public scripts and styles
48 add_action( 'wp_enqueue_scripts', 'asenha_public_scripts' );
49 // Add action links in plugins page
50 add_filter( 'plugin_action_links_' . ASENHA_SLUG . '/' . ASENHA_SLUG . '.php', 'asenha_plugin_action_links' );
51 // Update footer text
52 add_filter( 'admin_footer_text', 'asenha_footer_text', 20 );
53 // Update footer version text
54 add_filter( 'update_footer', 'asenha_footer_version_text', 20 );
55 // ===== Activate features based on settings =====
56 // Get all WP Enhancements options, default to empty array in case it's not been created yet
57 $options = get_option( ASENHA_SLUG_U, array() );
58 // =================================================================
59 // CONTENT MANAGEMENT
60 // =================================================================
61 // Instantiate object for Content Management features
62 $content_management = new ASENHA\Classes\Content_Management();
63 // Content Duplication
64
65 if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) {
66 add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] );
67 add_filter(
68 'page_row_actions',
69 [ $content_management, 'add_duplication_action_link' ],
70 10,
71 2
72 );
73 add_filter(
74 'post_row_actions',
75 [ $content_management, 'add_duplication_action_link' ],
76 10,
77 2
78 );
79 }
80
81 // Content Order
82 if ( array_key_exists( 'content_order', $options ) && $options['content_order'] ) {
83
84 if ( array_key_exists( 'content_order_for', $options ) && !empty($options['content_order_for']) ) {
85 add_action( 'admin_menu', [ $content_management, 'add_content_order_submenu' ] );
86 add_action( 'wp_ajax_save_custom_order', [ $content_management, 'save_custom_content_order' ] );
87 add_filter( 'pre_get_posts', [ $content_management, 'orderby_menu_order_in_admin_lists' ] );
88 }
89
90 }
91 // Enable Media Replacement
92
93 if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) {
94 add_filter(
95 'media_row_actions',
96 [ $content_management, 'modify_media_list_table_edit_link' ],
97 10,
98 2
99 );
100 add_filter(
101 'attachment_fields_to_edit',
102 [ $content_management, 'add_media_replacement_button' ],
103 10,
104 2
105 );
106 add_action( 'edit_attachment', [ $content_management, 'replace_media' ] );
107 add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] );
108 }
109
110 // Enable SVG Upload
111
112 if ( array_key_exists( 'enable_svg_upload', $options ) && $options['enable_svg_upload'] && array_key_exists( 'enable_svg_upload_for', $options ) && isset( $options['enable_svg_upload_for'] ) ) {
113 global $roles_svg_upload_enabled ;
114 $enable_svg_upload = $options['enable_svg_upload'];
115 $for_roles = $options['enable_svg_upload_for'];
116 // User has role(s). Do further checks.
117
118 if ( isset( $for_roles ) && count( $for_roles ) > 0 ) {
119 // Assemble single-dimensional array of roles for which SVG upload would be enabled
120 $roles_svg_upload_enabled = array();
121 foreach ( $for_roles as $role_slug => $svg_upload_enabled ) {
122 if ( $svg_upload_enabled ) {
123 $roles_svg_upload_enabled[] = $role_slug;
124 }
125 }
126 }
127
128 add_filter( 'upload_mimes', [ $content_management, 'add_svg_mime' ] );
129 add_filter(
130 'wp_check_filetype_and_ext',
131 [ $content_management, 'confirm_file_type_is_svg' ],
132 10,
133 4
134 );
135 add_filter( 'wp_handle_upload_prefilter', [ $content_management, 'sanitize_and_maybe_allow_svg_upload' ] );
136 add_filter(
137 'wp_generate_attachment_metadata',
138 [ $content_management, 'generate_svg_metadata' ],
139 10,
140 3
141 );
142 add_action( 'wp_ajax_svg_get_attachment_url', [ $content_management, 'get_svg_attachment_url' ] );
143 add_filter( 'wp_prepare_attachment_for_js', [ $content_management, 'get_svg_url_in_media_library' ] );
144 }
145
146 // Enable External Permalinks
147 if ( array_key_exists( 'enable_external_permalinks', $options ) && $options['enable_external_permalinks'] ) {
148
149 if ( array_key_exists( 'enable_external_permalinks_for', $options ) && !empty($options['enable_external_permalinks_for']) ) {
150 add_action(
151 'add_meta_boxes',
152 [ $content_management, 'add_external_permalink_meta_box' ],
153 10,
154 2
155 );
156 add_action( 'save_post', [ $content_management, 'save_external_permalink' ] );
157 // Filter the permalink for use by get_permalink()
158 add_filter(
159 'page_link',
160 [ $content_management, 'use_external_permalink_for_pages' ],
161 20,
162 2
163 );
164 add_filter(
165 'post_link',
166 [ $content_management, 'use_external_permalink_for_posts' ],
167 20,
168 2
169 );
170 add_filter(
171 'post_type_link',
172 [ $content_management, 'use_external_permalink_for_posts' ],
173 20,
174 2
175 );
176 // Enable redirection to external permalink when page/post is opened directly via it's WP permalink
177 add_action( 'wp', [ $content_management, 'redirect_to_external_permalink' ] );
178 }
179
180 }
181 // Open All External Links in New Tab
182 if ( array_key_exists( 'external_links_new_tab', $options ) && $options['external_links_new_tab'] ) {
183 add_filter( 'the_content', [ $content_management, 'add_target_and_rel_atts_to_content_links' ] );
184 }
185 // Enable Auto-Publishing of Posts with Missed Schedules
186
187 if ( array_key_exists( 'enable_missed_schedule_posts_auto_publish', $options ) && $options['enable_missed_schedule_posts_auto_publish'] ) {
188 add_action( 'wp_head', [ $content_management, 'publish_missed_schedule_posts' ] );
189 add_action( 'admin_head', [ $content_management, 'publish_missed_schedule_posts' ] );
190 }
191
192 // Enhance List Tables
193
194 if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) {
195 // Show Featured Image Column
196 if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) {
197 add_action( 'admin_init', [ $content_management, 'show_featured_image_column' ] );
198 }
199 // Show Excerpt Column
200 if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) {
201 add_action( 'admin_init', [ $content_management, 'show_excerpt_column' ] );
202 }
203 // Show ID Column
204 if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) {
205 add_action( 'admin_init', [ $content_management, 'show_id_column' ] );
206 }
207 // Show ID in Action Row
208 if ( array_key_exists( 'show_id_in_action_row', $options ) && $options['show_id_in_action_row'] ) {
209 add_action( 'admin_init', [ $content_management, 'show_id_in_action_row' ] );
210 }
211 // Show Custom Taxonomy Filters
212 if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) {
213 add_action( 'restrict_manage_posts', [ $content_management, 'show_custom_taxonomy_filters' ] );
214 }
215 // Hide Comments Column
216 if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) {
217 add_action( 'admin_init', [ $content_management, 'hide_comments_column' ] );
218 }
219 // Hide Post Tags Column
220 if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) {
221 add_action( 'admin_init', [ $content_management, 'hide_post_tags_column' ] );
222 }
223 }
224
225 // =================================================================
226 // ADMIN INTERFACE
227 // =================================================================
228 // Instantiate object for Admin Interface features
229 $admin_interface = new ASENHA\Classes\Admin_Interface();
230 // Hide Admin Notices
231
232 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
233 add_action( 'admin_notices', [ $admin_interface, 'admin_notices_wrapper' ], 9 );
234 // add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] );
235 add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] );
236 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] );
237 // wp-admin
238 }
239
240 // Hide Admin Bar
241 if ( array_key_exists( 'hide_admin_bar', $options ) && $options['hide_admin_bar'] && array_key_exists( 'hide_admin_bar_for', $options ) && isset( $options['hide_admin_bar_for'] ) ) {
242 add_filter( 'show_admin_bar', [ $admin_interface, 'hide_admin_bar_for_roles' ] );
243 }
244 // Disable Dashboard Widgets
245 if ( array_key_exists( 'disable_dashboard_widgets', $options ) && $options['disable_dashboard_widgets'] ) {
246 add_action( 'wp_dashboard_setup', [ $admin_interface, 'disable_dashboard_widgets' ], 99 );
247 }
248 // Hide or Modify Elements
249
250 if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) {
251 add_filter( 'admin_bar_menu', [ $admin_interface, 'modify_admin_bar_menu' ], 5 );
252 // priority 5 to execute earlier than the normal 10
253 if ( array_key_exists( 'hide_help_drawer', $options ) && $options['hide_help_drawer'] ) {
254 add_action( 'admin_head', [ $admin_interface, 'hide_help_drawer' ] );
255 }
256 }
257
258 // Admin Menu Organizer
259
260 if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) {
261 // add_action( 'wp_ajax_save_custom_menu_order', [ $admin_interface, 'save_custom_menu_order' ] );
262 // add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_interface, 'save_hidden_menu_items' ] );
263
264 if ( array_key_exists( 'custom_menu_order', $options ) ) {
265 add_filter( 'custom_menu_order', '__return_true' );
266 add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ] );
267 }
268
269 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
270 add_action( 'admin_menu', [ $admin_interface, 'apply_custom_menu_item_titles' ], 1000 );
271 }
272
273 if ( array_key_exists( 'custom_menu_hidden', $options ) || array_key_exists( 'custom_menu_always_hidden', $options ) ) {
274 add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 1001 );
275 add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ], 1002 );
276 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] );
277 }
278
279 }
280
281 // =================================================================
282 // LOG IN | LOG OUT
283 // =================================================================
284 // Instantiate object for Log In Log Out features
285 $login_logout = new ASENHA\Classes\Login_Logout();
286 // Change Login URL
287 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
288
289 if ( array_key_exists( 'custom_login_slug', $options ) && !empty($options['custom_login_slug']) ) {
290 add_action( 'init', [ $login_logout, 'redirect_on_custom_login_url' ] );
291 add_action( 'login_head', [ $login_logout, 'redirect_on_default_login_urls' ] );
292 add_action( 'wp_login_failed', [ $login_logout, 'redirect_to_custom_login_url_on_login_fail' ] );
293 add_action( 'wp_logout', [ $login_logout, 'redirect_to_custom_login_url_on_logout_success' ] );
294 }
295
296 }
297 // Enable Login Logout Menu
298
299 if ( array_key_exists( 'enable_login_logout_menu', $options ) && $options['enable_login_logout_menu'] ) {
300 add_action( 'admin_head-nav-menus.php', [ $login_logout, 'add_login_logout_metabox' ] );
301 add_filter( 'wp_setup_nav_menu_item', [ $login_logout, 'set_login_logout_menu_item_dynamic_url' ] );
302 add_filter( 'wp_nav_menu_objects', [ $login_logout, 'maybe_remove_login_or_logout_menu_item' ] );
303 }
304
305 // Enable Last Login Column
306
307 if ( array_key_exists( 'enable_last_login_column', $options ) && $options['enable_last_login_column'] ) {
308 add_action( 'wp_login', [ $login_logout, 'log_login_datetime' ] );
309 add_filter( 'manage_users_columns', [ $login_logout, 'add_last_login_column' ] );
310 add_filter(
311 'manage_users_custom_column',
312 [ $login_logout, 'show_last_login_info' ],
313 10,
314 3
315 );
316 add_action( 'admin_print_styles-users.php', [ $login_logout, 'add_column_style' ] );
317 }
318
319 // Redirect After Login
320 if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) {
321 if ( array_key_exists( 'redirect_after_login_to_slug', $options ) && !empty($options['redirect_after_login_to_slug']) ) {
322 if ( array_key_exists( 'redirect_after_login_for', $options ) && !empty($options['redirect_after_login_for']) ) {
323 add_filter(
324 'wp_login',
325 [ $login_logout, 'redirect_for_roles_after_login' ],
326 5,
327 2
328 );
329 }
330 }
331 }
332 // Redirect After Logout
333 if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) {
334 if ( array_key_exists( 'redirect_after_logout_to_slug', $options ) && !empty($options['redirect_after_logout_to_slug']) ) {
335
336 if ( array_key_exists( 'redirect_after_logout_for', $options ) && !empty($options['redirect_after_logout_for']) ) {
337 add_action(
338 'wp_logout',
339 [ $login_logout, 'redirect_after_logout' ],
340 5,
341 1
342 );
343 // load earlier than Change Login URL add_action
344 }
345
346 }
347 }
348 // =================================================================
349 // CUSTOM CODE
350 // =================================================================
351 // Instantiate object for Custom Code features
352 $custom_code = new ASENHA\Classes\Custom_Code();
353 // Enable Custom Admin / Frontend CSS
354 if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) {
355 add_filter( 'admin_enqueue_scripts', [ $custom_code, 'custom_admin_css' ] );
356 }
357 if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
358 add_filter( 'wp_enqueue_scripts', [ $custom_code, 'custom_frontend_css' ] );
359 }
360 // Custom Body Class
361 if ( array_key_exists( 'enable_custom_body_class', $options ) && $options['enable_custom_body_class'] ) {
362
363 if ( array_key_exists( 'enable_custom_body_class_for', $options ) && !empty($options['enable_custom_body_class_for']) ) {
364 add_action(
365 'add_meta_boxes',
366 [ $custom_code, 'add_custom_body_class_meta_box' ],
367 10,
368 2
369 );
370 add_action( 'save_post', [ $custom_code, 'save_custom_body_class' ], 99 );
371 add_filter( 'body_class', [ $custom_code, 'append_custom_body_class' ], 99 );
372 }
373
374 }
375 // Manage ads.txt and app-ads.txt
376 if ( array_key_exists( 'manage_ads_appads_txt', $options ) && $options['manage_ads_appads_txt'] ) {
377 add_action( 'init', [ $custom_code, 'show_ads_appads_txt_content' ] );
378 }
379 // Manage robots.txt
380 if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) {
381 add_filter(
382 'robots_txt',
383 [ $custom_code, 'maybe_show_custom_robots_txt_content' ],
384 10,
385 2
386 );
387 }
388 // Insert <head>, <body> and <footer> code
389
390 if ( array_key_exists( 'insert_head_body_footer_code', $options ) && $options['insert_head_body_footer_code'] ) {
391
392 if ( isset( $options['head_code_priority'] ) ) {
393 add_action( 'wp_head', [ $custom_code, 'insert_head_code' ], $options['head_code_priority'] );
394 } else {
395 add_action( 'wp_head', [ $custom_code, 'insert_head_code' ], 10 );
396 }
397
398 if ( function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ) {
399
400 if ( isset( $options['body_code_priority'] ) ) {
401 add_action( 'wp_body_open', [ $custom_code, 'insert_body_code' ], $options['body_code_priority'] );
402 } else {
403 add_action( 'wp_body_open', [ $custom_code, 'insert_body_code' ], 10 );
404 }
405
406 }
407
408 if ( isset( $options['footer_code_priority'] ) ) {
409 add_action( 'wp_footer', [ $custom_code, 'insert_footer_code' ], $options['footer_code_priority'] );
410 } else {
411 add_action( 'wp_footer', [ $custom_code, 'insert_footer_code' ], 10 );
412 }
413
414 }
415
416 // =================================================================
417 // DISABLE COMPONENTS
418 // =================================================================
419 // Instantiate object for Disable Components features
420 $disable_components = new ASENHA\Classes\Disable_Components();
421 // Disable Gutenberg
422 if ( array_key_exists( 'disable_gutenberg', $options ) && $options['disable_gutenberg'] ) {
423
424 if ( array_key_exists( 'disable_gutenberg_for', $options ) && !empty($options['disable_gutenberg_for']) ) {
425 add_action( 'admin_init', [ $disable_components, 'disable_gutenberg_for_post_types_admin' ] );
426 if ( array_key_exists( 'disable_gutenberg_frontend_styles', $options ) && $options['disable_gutenberg_frontend_styles'] ) {
427 add_action( 'wp_enqueue_scripts', [ $disable_components, 'disable_gutenberg_for_post_types_frontend' ], 100 );
428 }
429 }
430
431 }
432 // Disable Comments
433 if ( array_key_exists( 'disable_comments', $options ) && $options['disable_comments'] ) {
434
435 if ( array_key_exists( 'disable_comments_for', $options ) && !empty($options['disable_comments_for']) ) {
436 add_action( 'do_meta_boxes', [ $disable_components, 'disable_comments_for_post_types_edit' ] );
437 // also work with 'init', 'admin_init', 'wp_loaded' hooks
438 add_action( 'template_redirect', [ $disable_components, 'show_blank_comment_template' ] );
439 add_filter(
440 'comments_array',
441 [ $disable_components, 'hide_existing_comments_on_frontend' ],
442 10,
443 2
444 );
445 // hide comments
446 add_filter( 'comments_open', [ $disable_components, 'close_commenting_on_frontend' ] );
447 // close commenting
448 }
449
450 }
451 // Disable REST API
452
453 if ( array_key_exists( 'disable_rest_api', $options ) && $options['disable_rest_api'] ) {
454
455 if ( version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
456 add_filter( 'rest_authentication_errors', [ $disable_components, 'disable_rest_api' ] );
457 } else {
458 // REST API 1.x
459 add_filter( 'json_enabled', '__return_false' );
460 add_filter( 'json_jsonp_enabled', '__return_false' );
461 // REST API 2.x
462 add_filter( 'rest_enabled', '__return_false' );
463 add_filter( 'rest_jsonp_enabled', '__return_false' );
464 }
465
466 remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
467 // Disable REST API links in HTML <head>
468 remove_action(
469 'template_redirect',
470 'rest_output_link_header',
471 11,
472 0
473 );
474 // Disable REST API link in HTTP headers
475 remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
476 // Remove REST API URL from the WP RSD endpoint.
477 }
478
479 // Disable Feeds
480
481 if ( array_key_exists( 'disable_feeds', $options ) && $options['disable_feeds'] ) {
482 remove_action( 'wp_head', 'feed_links', 2 );
483 // Remove feed links in <head>
484 remove_action( 'wp_head', 'feed_links_extra', 3 );
485 // Remove feed links in <head>
486 remove_action(
487 'do_feed_rdf',
488 'do_feed_rdf',
489 10,
490 0
491 );
492 remove_action(
493 'do_feed_rss',
494 'do_feed_rss',
495 10,
496 0
497 );
498 remove_action(
499 'do_feed_rss2',
500 'do_feed_rss2',
501 10,
502 1
503 );
504 remove_action(
505 'do_feed_atom',
506 'do_feed_atom',
507 10,
508 1
509 );
510 }
511
512 // Disable All Updates
513
514 if ( array_key_exists( 'disable_all_updates', $options ) && $options['disable_all_updates'] ) {
515 add_action( 'admin_init', [ $disable_components, 'disable_update_notices_version_checks' ] );
516 // Disable core update
517 add_filter( 'pre_transient_update_core', [ $disable_components, 'override_version_check_info' ] );
518 add_filter( 'pre_site_transient_update_core', [ $disable_components, 'override_version_check_info' ] );
519 // Disable theme updates
520 add_filter( 'pre_transient_update_themes', [ $disable_components, 'override_version_check_info' ] );
521 add_filter( 'pre_site_transient_update_themes', [ $disable_components, 'override_version_check_info' ] );
522 add_action( 'pre_set_site_transient_update_themes', [ $disable_components, 'override_version_check_info' ], 20 );
523 // Disable plugin updates
524 add_filter( 'pre_transient_update_plugins', [ $disable_components, 'override_version_check_info' ] );
525 add_filter( 'pre_site_transient_update_plugins', [ $disable_components, 'override_version_check_info' ] );
526 add_action( 'pre_set_site_transient_update_plugins', [ $disable_components, 'override_version_check_info' ], 20 );
527 // Disable auto updates
528 add_filter( 'automatic_updater_disabled', '__return_true' );
529 if ( !defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) {
530 define( 'AUTOMATIC_UPDATER_DISABLED', true );
531 }
532 if ( !defined( 'WP_AUTO_UPDATE_CORE' ) ) {
533 define( 'WP_AUTO_UPDATE_CORE', false );
534 }
535 add_filter( 'auto_update_core', '__return_false' );
536 add_filter( 'wp_auto_update_core', '__return_false' );
537 add_filter( 'allow_minor_auto_core_updates', '__return_false' );
538 add_filter( 'allow_major_auto_core_updates', '__return_false' );
539 add_filter( 'allow_dev_auto_core_updates', '__return_false' );
540 add_filter( 'auto_update_plugin', '__return_false' );
541 add_filter( 'auto_update_theme', '__return_false' );
542 add_filter( 'auto_update_translation', '__return_false' );
543 remove_action( 'init', 'wp_schedule_update_checks' );
544 // Disable update emails
545 add_filter( 'auto_core_update_send_email', '__return_false' );
546 add_filter( 'send_core_update_notification_email', '__return_false' );
547 add_filter( 'automatic_updates_send_debug_email', '__return_false' );
548 // Remove Dashboard >> Updates menu
549 add_action( 'admin_menu', [ $disable_components, 'remove_updates_menu' ] );
550 }
551
552 // Disable Smaller Components
553
554 if ( array_key_exists( 'disable_smaller_components', $options ) && $options['disable_smaller_components'] ) {
555
556 if ( array_key_exists( 'disable_head_generator_tag', $options ) && $options['disable_head_generator_tag'] ) {
557 remove_action( 'wp_head', 'wp_generator' );
558 add_filter( 'the_generator', '', 'html' );
559 add_filter( 'the_generator', '', 'xhtml' );
560 }
561
562 if ( array_key_exists( 'disable_head_wlwmanifest_tag', $options ) && $options['disable_head_wlwmanifest_tag'] ) {
563 remove_action( 'wp_head', 'wlwmanifest_link' );
564 }
565 if ( array_key_exists( 'disable_head_rsd_tag', $options ) && $options['disable_head_rsd_tag'] ) {
566 remove_action( 'wp_head', 'rsd_link' );
567 }
568
569 if ( array_key_exists( 'disable_head_shortlink_tag', $options ) && $options['disable_head_shortlink_tag'] ) {
570 remove_action( 'wp_head', 'wp_shortlink_wp_head' );
571 remove_action(
572 'template_redirect',
573 'wp_shortlink_header',
574 100,
575 0
576 );
577 }
578
579 if ( array_key_exists( 'disable_frontend_dashicons', $options ) && $options['disable_frontend_dashicons'] ) {
580 add_action( 'init', [ $disable_components, 'disable_dashicons_public_assets' ] );
581 }
582 if ( array_key_exists( 'disable_emoji_support', $options ) && $options['disable_emoji_support'] ) {
583 add_action( 'init', [ $disable_components, 'disable_emoji_support' ] );
584 }
585 }
586
587 // =================================================================
588 // SECURITY
589 // =================================================================
590 // Instantiate object for Security features
591 $security = new ASENHA\Classes\Security();
592 // Limit Login Attempts
593
594 if ( array_key_exists( 'limit_login_attempts', $options ) && $options['limit_login_attempts'] ) {
595 add_filter(
596 'authenticate',
597 [ $security, 'maybe_allow_login' ],
598 999,
599 3
600 );
601 // Very low priority so it is processed last
602 add_action( 'login_enqueue_scripts', [ $security, 'maybe_hide_login_form' ] );
603 add_action( 'wp_login_failed', [ $security, 'log_failed_login' ], 5 );
604 // Higher priority than one in Change Login URL
605 add_action(
606 'wp_login_errors',
607 [ $security, 'login_error_handler' ],
608 999,
609 2
610 );
611 add_filter( 'login_message', [ $security, 'add_failed_login_message' ] );
612 add_action( 'wp_login', [ $security, 'clear_failed_login_log' ] );
613 }
614
615 // Obfuscate Author Slugs
616
617 if ( array_key_exists( 'obfuscate_author_slugs', $options ) && $options['obfuscate_author_slugs'] ) {
618 add_action( 'pre_get_posts', [ $security, 'alter_author_query' ], 10 );
619 add_filter(
620 'author_link',
621 [ $security, 'alter_author_link' ],
622 10,
623 3
624 );
625 add_filter(
626 'rest_prepare_user',
627 [ $security, 'alter_json_users' ],
628 10,
629 3
630 );
631 }
632
633 // Disable XML-RPC
634
635 if ( array_key_exists( 'disable_xmlrpc', $options ) && $options['disable_xmlrpc'] ) {
636 add_filter( 'xmlrpc_enabled', '__return_false' );
637 add_filter( 'wp_xmlrpc_server_class', [ $security, 'maybe_disable_xmlrpc' ] );
638 }
639
640 // =================================================================
641 // OPTIMIZATIONS
642 // =================================================================
643 // Instantiate object for Optimizations features
644 $optimizations = new ASENHA\Classes\Optimizations();
645 // Image Upload Control
646 if ( array_key_exists( 'image_upload_control', $options ) && $options['image_upload_control'] ) {
647 add_filter( 'wp_handle_upload', [ $optimizations, 'image_upload_handler' ] );
648 }
649 // Revisions Control
650 if ( array_key_exists( 'enable_revisions_control', $options ) && $options['enable_revisions_control'] ) {
651 add_filter(
652 'wp_revisions_to_keep',
653 [ $optimizations, 'limit_revisions_to_max_number' ],
654 10,
655 2
656 );
657 }
658 // Heartbeat Control
659
660 if ( array_key_exists( 'enable_heartbeat_control', $options ) && $options['enable_heartbeat_control'] ) {
661 add_filter(
662 'heartbeat_settings',
663 [ $optimizations, 'maybe_modify_heartbeat_frequency' ],
664 99,
665 2
666 );
667 add_action( 'admin_enqueue_scripts', [ $optimizations, 'maybe_disable_heartbeat' ], 99 );
668 add_action( 'wp_enqueue_scripts', [ $optimizations, 'maybe_disable_heartbeat' ], 99 );
669 }
670
671 // =================================================================
672 // UTILITIES
673 // =================================================================
674 // Instantiate object for Utilities features
675 $utilities = new ASENHA\Classes\Utilities();
676 // SMTP Email Delivery
677 if ( array_key_exists( 'smtp_email_delivery', $options ) && $options['smtp_email_delivery'] ) {
678 add_action( 'phpmailer_init', [ $utilities, 'deliver_email_via_smtp' ] );
679 }
680 // Multiple User Roles
681
682 if ( array_key_exists( 'multiple_user_roles', $options ) && $options['multiple_user_roles'] ) {
683 // Show roles checkboxes
684 add_action( 'show_user_profile', [ $utilities, 'add_multiple_roles_ui' ] );
685 // for when user edits their own profile
686 add_action( 'edit_user_profile', [ $utilities, 'add_multiple_roles_ui' ] );
687 // for when editing other user's profile
688 add_action( 'user_new_form', [ $utilities, 'add_multiple_roles_ui' ] );
689 // new user creation
690 // Save roles selections
691 add_action( 'personal_options_update', [ $utilities, 'save_roles_assignment' ] );
692 // for when user edits their own profile
693 add_action( 'edit_user_profile_update', [ $utilities, 'save_roles_assignment' ] );
694 // for when editing other user's profile
695 add_action( 'user_register', [ $utilities, 'save_roles_assignment' ] );
696 // new user creation
697 }
698
699 // View Admin as Role
700
701 if ( array_key_exists( 'view_admin_as_role', $options ) && $options['view_admin_as_role'] ) {
702 add_action( 'admin_bar_menu', [ $utilities, 'view_admin_as_admin_bar_menu' ], 8 );
703 // Priority 8 so it is next to username section
704 add_action( 'init', [ $utilities, 'role_switcher_to_view_admin_as' ] );
705 add_action( 'wp_die_handler', [ $utilities, 'custom_error_page_on_switch_failure' ] );
706 }
707
708 // Password Protection
709
710 if ( array_key_exists( 'enable_password_protection', $options ) && $options['enable_password_protection'] ) {
711 add_action( 'plugins_loaded', [ $utilities, 'show_password_protection_admin_bar_icon' ] );
712 add_action( 'init', [ $utilities, 'maybe_disable_page_caching' ], 1 );
713 add_action( 'template_redirect', [ $utilities, 'maybe_show_login_form' ], 0 );
714 // load early
715 add_action( 'init', [ $utilities, 'maybe_process_login' ], 1 );
716 add_action( 'asenha_password_protection_error_messages', [ $utilities, 'add_login_error_messages' ] );
717 if ( function_exists( 'wp_site_icon' ) ) {
718 // WP v4.3+
719 add_action( 'asenha_password_protection_login_head', 'wp_site_icon' );
720 }
721 }
722
723 // Maintenance Mode
724
725 if ( array_key_exists( 'maintenance_mode', $options ) && $options['maintenance_mode'] ) {
726 add_action( 'send_headers', [ $utilities, 'maintenance_mode_redirect' ] );
727 add_action( 'plugins_loaded', [ $utilities, 'show_maintenance_mode_admin_bar_icon' ] );
728 }
729
730 // Redirect 404 to Homepage
731 if ( array_key_exists( 'redirect_404_to_homepage', $options ) && $options['redirect_404_to_homepage'] ) {
732 add_filter( 'wp', [ $utilities, 'redirect_404_to_homepage' ] );
733 }
734 }
735
736 }
737 Admin_Site_Enhancements::get_instance();