PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 4.7.4
Admin and Site Enhancements (ASE) v4.7.4
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 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / bootstrap.php
admin-site-enhancements Last commit date
assets 3 years ago classes 3 years ago includes 3 years ago vendor 3 years ago LICENSE.md 3 years ago README.md 3 years ago admin-site-enhancements.php 3 years ago bootstrap.php 3 years ago settings.php 3 years ago
bootstrap.php
594 lines
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 /**
9 * Main class of the plugin used to add functionalities
10 *
11 * @since 1.0.0
12 */
13 class Admin_Site_Enhancements {
14
15 // Refers to a single instance of this class
16 private static $instance = null;
17
18 /**
19 * Creates or returns a single instance of this class
20 *
21 * @return Admin_Site_Enhancements a single instance of this class
22 * @since 1.0.0
23 */
24 public static function get_instance() {
25
26 if ( null == self::$instance ) {
27
28 self::$instance = new self;
29
30 }
31
32 return self::$instance;
33
34 }
35
36 /**
37 * Initialize plugin functionalities
38 */
39 private function __construct() {
40
41 // Setup admin menu, admin page, settings, settings sections, sections fields, admin scripts, plugin action links, etc.
42
43 // Register admin menu and add the settings page.
44 add_action( 'admin_menu', 'asenha_register_admin_menu' );
45
46 // Register plugin settings
47
48 // Instantiate object for registration of settings section and fields
49 $settings = new ASENHA\Classes\Settings_Sections_Fields;
50
51 add_action( 'admin_init', [ $settings, 'register_sections_fields' ] );
52
53 // Suppress all notices on the plugin's main page. Then add notification for successful settings update.
54 add_action( 'admin_notices', 'asenha_suppress_notices', 5 );
55 add_action( 'all_admin_notices', 'asenha_suppress_generic_notices', 5 );
56
57 // Enqueue admin scripts and styles only on the plugin's main page
58 add_action( 'admin_enqueue_scripts', 'asenha_admin_scripts' );
59
60 // Enqueue public scripts and styles
61 add_action( 'wp_enqueue_scripts', 'asenha_public_scripts' );
62
63 // Add action links in plugins page
64 add_filter( 'plugin_action_links_' . ASENHA_SLUG . '/' . ASENHA_SLUG . '.php', 'asenha_plugin_action_links' );
65
66 // Update footer text
67 add_filter( 'admin_footer_text', 'asenha_footer_text' );
68
69 // ===== Activate features based on settings =====
70
71 // Get all WP Enhancements options, default to empty array in case it's not been created yet
72 $options = get_option( ASENHA_SLUG_U, array() );
73
74 // =================================================================
75 // CONTENT MANAGEMENT
76 // =================================================================
77
78 // Instantiate object for Content Management features
79 $content_management = new ASENHA\Classes\Content_Management;
80
81 // Enable Page and Post Duplication
82 if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) {
83 add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] );
84 add_filter( 'page_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 );
85 add_filter( 'post_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 );
86 }
87
88 // Enable Media Replacement
89 if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) {
90 add_filter( 'media_row_actions', [ $content_management, 'modify_media_list_table_edit_link' ], 10, 2 );
91 add_filter( 'attachment_fields_to_edit', [ $content_management, 'add_media_replacement_button' ], 10, 2 );
92 add_action( 'edit_attachment', [ $content_management, 'replace_media' ] );
93 add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] );
94 }
95
96 // Enable SVG Upload
97 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'] ) ) {
98
99 global $roles_svg_upload_enabled;
100
101 $enable_svg_upload = $options['enable_svg_upload'];
102 $for_roles = $options['enable_svg_upload_for'];
103
104 // User has role(s). Do further checks.
105 if ( isset( $for_roles ) && ( count( $for_roles ) > 0 ) ) {
106
107 // Assemble single-dimensional array of roles for which SVG upload would be enabled
108 $roles_svg_upload_enabled = array();
109 foreach( $for_roles as $role_slug => $svg_upload_enabled ) {
110 if ( $svg_upload_enabled ) {
111 $roles_svg_upload_enabled[] = $role_slug;
112 }
113 }
114
115 }
116
117 add_filter( 'upload_mimes', [ $content_management, 'add_svg_mime' ] );
118 add_filter( 'wp_check_filetype_and_ext', [ $content_management, 'confirm_file_type_is_svg' ], 10, 4 );
119 add_filter( 'wp_handle_upload_prefilter', [ $content_management, 'sanitize_and_maybe_allow_svg_upload' ] );
120 add_filter( 'wp_generate_attachment_metadata', [ $content_management, 'generate_svg_metadata' ], 10, 3 );
121 add_action( 'wp_ajax_svg_get_attachment_url', [ $content_management, 'get_svg_attachment_url' ] );
122 add_filter( 'wp_prepare_attachment_for_js', [ $content_management, 'get_svg_url_in_media_library' ] );
123 }
124
125 // Enable External Permalinks
126 if ( array_key_exists( 'enable_external_permalinks', $options ) && $options['enable_external_permalinks'] ) {
127 if ( array_key_exists( 'enable_external_permalinks_for', $options ) && ! empty( $options['enable_external_permalinks_for'] ) ) {
128 add_action( 'add_meta_boxes', [ $content_management, 'add_external_permalink_meta_box' ], 10, 2 );
129 add_action( 'save_post', [ $content_management, 'save_external_permalink' ] );
130
131 // Filter the permalink for use by get_permalink()
132 add_filter( 'page_link', [ $content_management, 'use_external_permalink_for_pages' ], 20, 2 );
133 add_filter( 'post_link', [ $content_management, 'use_external_permalink_for_posts' ], 20, 2 );
134 add_filter( 'post_type_link', [ $content_management, 'use_external_permalink_for_posts' ], 20, 2 );
135
136 // Enable redirection to external permalink when page/post is opened directly via it's WP permalink
137 add_action( 'wp', [ $content_management, 'redirect_to_external_permalink' ] );
138 }
139 }
140
141 // Enable Auto-Publishing of Posts with Missed Schedules
142 if ( array_key_exists( 'enable_missed_schedule_posts_auto_publish', $options ) && $options['enable_missed_schedule_posts_auto_publish'] ) {
143 add_action( 'wp_head', [ $content_management, 'publish_missed_schedule_posts' ] );
144 add_action( 'admin_head', [ $content_management, 'publish_missed_schedule_posts' ] );
145 }
146
147 // Enhance List Tables
148 if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) {
149
150 // Show Featured Image Column
151 if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) {
152 add_action( 'admin_init', [ $content_management, 'show_featured_image_column' ] );
153 }
154
155 // Show Excerpt Column
156 if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) {
157 add_action( 'admin_init', [ $content_management, 'show_excerpt_column' ] );
158 }
159
160 // Show ID Column
161 if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) {
162 add_action( 'admin_init', [ $content_management, 'show_id_column' ] );
163 }
164
165 // Show ID in Action Row
166 if ( array_key_exists( 'show_id_in_action_row', $options ) && $options['show_id_in_action_row'] ) {
167 add_action( 'admin_init', [ $content_management, 'show_id_in_action_row' ] );
168 }
169
170 // Show Custom Taxonomy Filters
171 if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) {
172 add_action( 'restrict_manage_posts', [ $content_management, 'show_custom_taxonomy_filters' ] );
173 }
174
175 // Hide Comments Column
176 if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) {
177 add_action( 'admin_init', [ $content_management, 'hide_comments_column' ] );
178 }
179
180 // Hide Post Tags Column
181 if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) {
182 add_action( 'admin_init', [ $content_management, 'hide_post_tags_column' ] );
183 }
184
185 }
186
187 // =================================================================
188 // ADMIN INTERFACE
189 // =================================================================
190
191 // Instantiate object for Admin Interface features
192 $admin_interface = new ASENHA\Classes\Admin_Interface;
193
194 // Hide Admin Notices
195 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
196 add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] );
197 add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] );
198 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] ); // wp-admin
199 }
200
201 // Hide Admin Bar
202 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'] ) ) {
203 add_filter( 'show_admin_bar', [ $admin_interface, 'hide_admin_bar_for_roles' ] );
204 }
205
206 // Disable Dashboard Widgets
207 if ( array_key_exists( 'disable_dashboard_widgets', $options ) && $options['disable_dashboard_widgets'] ) {
208 add_action( 'wp_dashboard_setup', [ $admin_interface, 'disable_dashboard_widgets' ], 99 );
209 }
210
211 // Hide or Modify Elements
212 if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) {
213 add_filter( 'admin_bar_menu', [ $admin_interface, 'modify_admin_bar_menu' ], 5 ); // priority 5 to execute earlier than the normal 10
214
215 if ( array_key_exists( 'hide_help_drawer', $options ) && $options['hide_help_drawer'] ) {
216 add_action( 'admin_head', [ $admin_interface, 'hide_help_drawer' ] );
217 }
218
219 }
220
221 // Customize Admin Menu
222
223 if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) {
224 // add_action( 'wp_ajax_save_custom_menu_order', [ $admin_interface, 'save_custom_menu_order' ] );
225 // add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_interface, 'save_hidden_menu_items' ] );
226 if ( array_key_exists( 'custom_menu_order', $options ) ) {
227 add_filter( 'custom_menu_order', '__return_true' );
228 add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ] );
229 }
230 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
231 add_action( 'admin_menu', [ $admin_interface, 'apply_custom_menu_item_titles' ], 1000 );
232 }
233 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
234 add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 1001 );
235 add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ], 1002 );
236 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] );
237 }
238 }
239
240 // =================================================================
241 // LOG IN | LOG OUT
242 // =================================================================
243
244 // Instantiate object for Log In Log Out features
245 $login_logout = new ASENHA\Classes\Login_Logout;
246
247 // Change Login URL
248 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
249 if ( array_key_exists( 'custom_login_slug', $options ) && ! empty( $options['custom_login_slug'] ) ) {
250 add_action( 'init', [ $login_logout, 'redirect_on_custom_login_url' ] );
251 add_action( 'login_head', [ $login_logout, 'redirect_on_default_login_urls' ] );
252 add_action( 'wp_login_failed', [ $login_logout, 'redirect_to_custom_login_url_on_login_fail' ] );
253 add_action( 'wp_logout', [ $login_logout, 'redirect_to_custom_login_url_on_logout_success' ] );
254 }
255 }
256
257 // Enable Login Logout Menu
258
259 if ( array_key_exists( 'enable_login_logout_menu', $options ) && $options['enable_login_logout_menu'] ) {
260 add_action( 'admin_head-nav-menus.php', [ $login_logout, 'add_login_logout_metabox' ] );
261 add_filter( 'wp_setup_nav_menu_item', [ $login_logout, 'set_login_logout_menu_item_dynamic_url' ] );
262 add_filter( 'wp_nav_menu_objects', [ $login_logout, 'maybe_remove_login_or_logout_menu_item' ] );
263 }
264
265 // Enable Last Login Column
266
267 if ( array_key_exists( 'enable_last_login_column', $options ) && $options['enable_last_login_column'] ) {
268 add_action( 'wp_login', [ $login_logout, 'log_login_datetime' ] );
269 add_filter( 'manage_users_columns', [ $login_logout, 'add_last_login_column' ] );
270 add_filter( 'manage_users_custom_column', [ $login_logout, 'show_last_login_info' ], 10, 3 );
271 add_action( 'admin_print_styles-users.php', [ $login_logout, 'add_column_style' ] );
272 }
273
274 // Redirect After Login
275
276 if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) {
277 if ( array_key_exists( 'redirect_after_login_to_slug', $options ) && ! empty( $options['redirect_after_login_to_slug'] ) ) {
278 if ( array_key_exists( 'redirect_after_login_for', $options ) && ! empty( $options['redirect_after_login_for'] ) ) {
279 add_filter( 'wp_login', [ $login_logout, 'redirect_for_roles_after_login' ], 5, 2 );
280 }
281 }
282 }
283
284 // Redirect After Logout
285
286 if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) {
287 if ( array_key_exists( 'redirect_after_logout_to_slug', $options ) && ! empty( $options['redirect_after_logout_to_slug'] ) ) {
288 if ( array_key_exists( 'redirect_after_logout_for', $options ) && ! empty( $options['redirect_after_logout_for'] ) ) {
289 add_action( 'wp_logout', [ $login_logout, 'redirect_after_logout' ], 5, 1 ); // load earlier than Change Login URL add_action
290 }
291 }
292 }
293
294 // =================================================================
295 // CUSTOM CODE
296 // =================================================================
297
298 // Instantiate object for Custom Code features
299 $custom_code = new ASENHA\Classes\Custom_Code;
300
301 // Enable Custom Admin / Frontend CSS
302
303 if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) {
304 add_filter( 'admin_enqueue_scripts', [ $custom_code, 'custom_admin_css' ] );
305 }
306
307 if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
308 add_filter( 'wp_enqueue_scripts', [ $custom_code, 'custom_frontend_css' ] );
309 }
310
311 // Custom Body Class
312 if ( array_key_exists( 'enable_custom_body_class', $options ) && $options['enable_custom_body_class'] ) {
313 if ( array_key_exists( 'enable_custom_body_class_for', $options ) && ! empty( $options['enable_custom_body_class_for'] ) ) {
314 add_action( 'add_meta_boxes', [ $custom_code, 'add_custom_body_class_meta_box' ], 10, 2 );
315 add_action( 'save_post', [ $custom_code, 'save_custom_body_class' ], 99 );
316 add_filter( 'body_class', [ $custom_code, 'append_custom_body_class'], 99 );
317 }
318 }
319
320 // Manage ads.txt and app-ads.txt
321
322 if ( array_key_exists( 'manage_ads_appads_txt', $options ) && $options['manage_ads_appads_txt'] ) {
323 add_action( 'init', [ $custom_code, 'show_ads_appads_txt_content' ] );
324 }
325
326 // Manage robots.txt
327
328 if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) {
329 add_filter( 'robots_txt', [ $custom_code, 'maybe_show_custom_robots_txt_content' ], 10, 2 );
330 }
331
332 // Insert <head>, <body> and <footer> code
333
334 if ( array_key_exists( 'insert_head_body_footer_code', $options ) && $options['insert_head_body_footer_code'] ) {
335
336 if ( isset( $options['head_code_priority'] ) ) {
337 add_action( 'wp_head', [ $custom_code, 'insert_head_code' ], $options['head_code_priority'] );
338 } else {
339 add_action( 'wp_head', [ $custom_code, 'insert_head_code' ], 10 );
340 }
341
342 if ( function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ) {
343
344 if ( isset( $options['body_code_priority'] ) ) {
345 add_action( 'wp_body_open', [ $custom_code, 'insert_body_code' ], $options['body_code_priority'] );
346 } else {
347 add_action( 'wp_body_open', [ $custom_code, 'insert_body_code' ], 10 );
348 }
349 }
350
351 if ( isset( $options['footer_code_priority'] ) ) {
352 add_action( 'wp_footer', [ $custom_code, 'insert_footer_code' ], $options['footer_code_priority'] );
353 } else {
354 add_action( 'wp_footer', [ $custom_code, 'insert_footer_code' ], 10 );
355 }
356
357 }
358
359 // =================================================================
360 // DISABLE COMPONENTS
361 // =================================================================
362
363 // Instantiate object for Disable Components features
364 $disable_components = new ASENHA\Classes\Disable_Components;
365
366 // Disable Gutenberg
367 if ( array_key_exists( 'disable_gutenberg', $options ) && $options['disable_gutenberg'] ) {
368 if ( array_key_exists( 'disable_gutenberg_for', $options ) && ! empty( $options['disable_gutenberg_for'] ) ) {
369 add_action( 'admin_init', [ $disable_components, 'disable_gutenberg_for_post_types_admin' ] );
370 if ( array_key_exists( 'disable_gutenberg_frontend_styles', $options ) && $options['disable_gutenberg_frontend_styles'] ) {
371 add_action( 'wp_enqueue_scripts', [ $disable_components, 'disable_gutenberg_for_post_types_frontend' ], 100 );
372 }
373 }
374 }
375
376 // Disable Comments
377 if ( array_key_exists( 'disable_comments', $options ) && $options['disable_comments'] ) {
378 if ( array_key_exists( 'disable_comments_for', $options ) && ! empty( $options['disable_comments_for'] ) ) {
379 add_action( 'do_meta_boxes', [ $disable_components, 'disable_comments_for_post_types_edit' ] ); // also work with 'init', 'admin_init', 'wp_loaded' hooks
380 add_filter( 'comments_array', [ $disable_components, 'hide_existing_comments_on_frontend' ], 10, 2 ); // hide comments
381 add_filter( 'comments_open', [ $disable_components, 'close_commenting_on_frontend' ] ); // close commenting
382 }
383 }
384
385 // Disable REST API
386 if ( array_key_exists( 'disable_rest_api', $options ) && $options['disable_rest_api'] ) {
387 if ( version_compare( get_bloginfo('version'), '4.7', '>=' ) ) {
388 add_filter( 'rest_authentication_errors', [ $disable_components, 'disable_rest_api' ] );
389 } else {
390 // REST API 1.x
391 add_filter( 'json_enabled', '__return_false' );
392 add_filter( 'json_jsonp_enabled', '__return_false' );
393 // REST API 2.x
394 add_filter( 'rest_enabled', '__return_false' );
395 add_filter( 'rest_jsonp_enabled', '__return_false' );
396 }
397 remove_action('wp_head', 'rest_output_link_wp_head', 10 ); // Disable REST API links in HTML <head>
398 remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); // Disable REST API link in HTTP headers
399 remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' ); // Remove REST API URL from the WP RSD endpoint.
400 }
401
402 // Disable Feeds
403 if ( array_key_exists( 'disable_feeds', $options ) && $options['disable_feeds'] ) {
404 remove_action( 'wp_head', 'feed_links', 2 ); // Remove feed links in <head>
405 remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove feed links in <head>
406 remove_action( 'do_feed_rdf', 'do_feed_rdf', 10, 0 );
407 remove_action( 'do_feed_rss', 'do_feed_rss', 10, 0 );
408 remove_action( 'do_feed_rss2', 'do_feed_rss2', 10, 1 );
409 remove_action( 'do_feed_atom', 'do_feed_atom', 10, 1 );
410 }
411
412 // Disable All Updates
413 if ( array_key_exists( 'disable_all_updates', $options ) && $options['disable_all_updates'] ) {
414 add_action( 'admin_init', [ $disable_components, 'disable_update_notices_version_checks' ] );
415
416 // Disable core update
417 add_filter( 'pre_transient_update_core', [ $disable_components, 'override_version_check_info' ] );
418 add_filter( 'pre_site_transient_update_core', [ $disable_components, 'override_version_check_info' ] );
419
420 // Disable theme updates
421 add_filter( 'pre_transient_update_themes', [ $disable_components, 'override_version_check_info' ] );
422 add_filter( 'pre_site_transient_update_themes', [ $disable_components, 'override_version_check_info' ] );
423 add_action( 'pre_set_site_transient_update_themes', [ $disable_components, 'override_version_check_info' ], 20 );
424
425 // Disable plugin updates
426 add_filter( 'pre_transient_update_plugins', [ $disable_components, 'override_version_check_info' ] );
427 add_filter( 'pre_site_transient_update_plugins', [ $disable_components, 'override_version_check_info' ] );
428 add_action( 'pre_set_site_transient_update_plugins', [ $disable_components, 'override_version_check_info' ], 20 );
429
430 // Disable auto updates
431 add_filter( 'automatic_updater_disabled', '__return_true' );
432 if ( ! defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) {
433 define( 'AUTOMATIC_UPDATER_DISABLED', true );
434 }
435 if ( ! defined( 'WP_AUTO_UPDATE_CORE') ) {
436 define( 'WP_AUTO_UPDATE_CORE', false );
437 }
438
439 add_filter( 'auto_update_core', '__return_false' );
440 add_filter( 'wp_auto_update_core', '__return_false' );
441 add_filter( 'allow_minor_auto_core_updates', '__return_false' );
442 add_filter( 'allow_major_auto_core_updates', '__return_false' );
443 add_filter( 'allow_dev_auto_core_updates', '__return_false' );
444
445 add_filter( 'auto_update_plugin', '__return_false' );
446 add_filter( 'auto_update_theme', '__return_false' );
447 add_filter( 'auto_update_translation', '__return_false' );
448
449 remove_action( 'init', 'wp_schedule_update_checks' );
450
451 // Disable update emails
452 add_filter( 'auto_core_update_send_email', '__return_false' );
453 add_filter( 'send_core_update_notification_email', '__return_false' );
454 add_filter( 'automatic_updates_send_debug_email', '__return_false' );
455
456 // Remove Dashboard >> Updates menu
457 add_action( 'admin_menu', [ $disable_components, 'remove_updates_menu' ] );
458
459 }
460
461 // Disable Smaller Components
462 if ( array_key_exists( 'disable_smaller_components', $options ) && $options['disable_smaller_components'] ) {
463
464 if ( array_key_exists( 'disable_head_generator_tag', $options ) && $options['disable_head_generator_tag'] ) {
465 remove_action( 'wp_head', 'wp_generator' );
466 add_filter( 'the_generator', '', 'html' );
467 add_filter( 'the_generator', '', 'xhtml' );
468 }
469
470 if ( array_key_exists( 'disable_head_wlwmanifest_tag', $options ) && $options['disable_head_wlwmanifest_tag'] ) {
471 remove_action( 'wp_head', 'wlwmanifest_link' );
472 }
473
474 if ( array_key_exists( 'disable_head_rsd_tag', $options ) && $options['disable_head_rsd_tag'] ) {
475 remove_action( 'wp_head', 'rsd_link' );
476 }
477
478 if ( array_key_exists( 'disable_head_shortlink_tag', $options ) && $options['disable_head_shortlink_tag'] ) {
479 remove_action( 'wp_head', 'wp_shortlink_wp_head' );
480 remove_action ( 'template_redirect', 'wp_shortlink_header', 100, 0 );
481 }
482
483 if ( array_key_exists( 'disable_frontend_dashicons', $options ) && $options['disable_frontend_dashicons'] ) {
484 add_action( 'init', [ $disable_components, 'disable_dashicons_public_assets' ] );
485 }
486
487 if ( array_key_exists( 'disable_emoji_support', $options ) && $options['disable_emoji_support'] ) {
488 add_action( 'init', [ $disable_components, 'disable_emoji_support' ] );
489 }
490
491 }
492
493 // =================================================================
494 // SECURITY
495 // =================================================================
496
497 // Instantiate object for Security features
498 $security = new ASENHA\Classes\Security;
499
500 // Limit Login Attempts
501 if ( array_key_exists( 'limit_login_attempts', $options ) && $options['limit_login_attempts'] ) {
502 add_filter( 'authenticate', [ $security, 'maybe_allow_login' ], 999, 3 ); // Very low priority so it is processed last
503 add_action( 'login_enqueue_scripts', [ $security, 'maybe_hide_login_form' ] );
504 add_action( 'wp_login_failed', [ $security, 'log_failed_login' ], 5 ); // Higher priority than one in Change Login URL
505 add_action( 'wp_login_errors', [ $security, 'login_error_handler' ], 999, 2 );
506 add_filter( 'login_message', [ $security, 'add_failed_login_message' ] );
507 add_action( 'wp_login', [ $security, 'clear_failed_login_log' ] );
508 }
509
510 // Obfuscate Author Slugs
511 if ( array_key_exists( 'obfuscate_author_slugs', $options ) && $options['obfuscate_author_slugs'] ) {
512 add_action( 'pre_get_posts', [ $security, 'alter_author_query' ], 10 );
513 add_filter( 'author_link', [ $security, 'alter_author_link' ], 10, 3 );
514 add_filter( 'rest_prepare_user', [ $security, 'alter_json_users' ], 10, 3 );
515 }
516
517 // Disable XML-RPC
518 if ( array_key_exists( 'disable_xmlrpc', $options ) && $options['disable_xmlrpc'] ) {
519 add_filter( 'xmlrpc_enabled', '__return_false' );
520 add_filter( 'wp_xmlrpc_server_class', [ $security, 'maybe_disable_xmlrpc' ] );
521 }
522
523 // =================================================================
524 // OPTIMIZATIONS
525 // =================================================================
526
527 // Instantiate object for Optimizations features
528 $optimizations = new ASENHA\Classes\Optimizations;
529
530 // Image Upload Control
531 if ( array_key_exists( 'image_upload_control', $options ) && $options['image_upload_control'] ) {
532 add_filter( 'wp_handle_upload', [ $optimizations, 'image_upload_handler' ] );
533 }
534
535 // Revisions Control
536 if ( array_key_exists( 'enable_revisions_control', $options ) && $options['enable_revisions_control'] ) {
537 add_filter( 'wp_revisions_to_keep', [ $optimizations, 'limit_revisions_to_max_number' ], 10, 2 );
538 }
539
540 // Heartbeat Control
541 if ( array_key_exists( 'enable_heartbeat_control', $options ) && $options['enable_heartbeat_control'] ) {
542 add_filter( 'heartbeat_settings', [ $optimizations, 'maybe_modify_heartbeat_frequency' ], 99, 2 );
543 add_action( 'admin_enqueue_scripts', [ $optimizations, 'maybe_disable_heartbeat' ], 99 );
544 add_action( 'wp_enqueue_scripts', [ $optimizations, 'maybe_disable_heartbeat' ], 99 );
545 }
546
547 // =================================================================
548 // UTILITIES
549 // =================================================================
550
551 // Instantiate object for Utilities features
552 $utilities = new ASENHA\Classes\Utilities;
553
554 // SMTP Email Delivery
555 if ( array_key_exists( 'smtp_email_delivery', $options ) && $options['smtp_email_delivery'] ) {
556 add_action( 'phpmailer_init', [ $utilities, 'deliver_email_via_smtp' ] );
557 }
558
559 // View Admin as Role
560 if ( array_key_exists( 'view_admin_as_role', $options ) && $options['view_admin_as_role'] ) {
561 add_action( 'admin_bar_menu', [ $utilities, 'view_admin_as_admin_bar_menu' ], 8 ); // Priority 8 so it is next to username section
562 add_action( 'init', [ $utilities, 'role_switcher_to_view_admin_as' ] );
563 add_action( 'wp_die_handler', [ $utilities, 'custom_error_page_on_switch_failure' ] );
564 }
565
566 // Password Protection
567 if ( array_key_exists( 'enable_password_protection', $options ) && $options['enable_password_protection'] ) {
568 add_action( 'plugins_loaded', [ $utilities, 'show_password_protection_admin_bar_icon' ] );
569 add_action( 'init', [ $utilities, 'maybe_disable_page_caching' ], 1 );
570 add_action( 'template_redirect', [ $utilities, 'maybe_show_login_form' ], 0 ); // load early
571 add_action( 'init', [ $utilities, 'maybe_process_login' ], 1 );
572 add_action( 'asenha_password_protection_error_messages', [ $utilities, 'add_login_error_messages' ] );
573 if ( function_exists( 'wp_site_icon' ) ) { // WP v4.3+
574 add_action( 'asenha_password_protection_login_head', 'wp_site_icon' );
575 }
576 }
577
578 // Maintenance Mode
579 if ( array_key_exists( 'maintenance_mode', $options ) && $options['maintenance_mode'] ) {
580 add_action( 'send_headers', [ $utilities, 'maintenance_mode_redirect' ] );
581 add_action( 'plugins_loaded', [ $utilities, 'show_maintenance_mode_admin_bar_icon' ] );
582 }
583
584 // Redirect 404 to Homepage
585
586 if ( array_key_exists( 'redirect_404_to_homepage', $options ) && $options['redirect_404_to_homepage'] ) {
587 add_filter( 'wp', [ $utilities, 'redirect_404_to_homepage' ] );
588 }
589
590 }
591
592 }
593
594 Admin_Site_Enhancements::get_instance();