PluginProbe
Admin and Site Enhancements (ASE) / 8.4.2
Admin and Site Enhancements (ASE) v8.4.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
1,124 lines 62.6 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 // Refers to a single instance of this class
14 private static $instance = null;
15
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 if ( null == self::$instance ) {
24 self::$instance = new self();
25 }
26 return self::$instance;
27 }
28
29 /**
30 * Initialize plugin functionalities
31 */
32 private function __construct() {
33 global $wp_post_types, $pagenow, $typenow;
34 // Setup admin menu, admin page, settings, settings sections, sections fields, admin scripts, plugin action links, etc.
35 // Register admin menu and add the settings page.
36 add_action( 'admin_menu', 'asenha_register_admin_menu' );
37 // Register plugin settings
38 // Instantiate object for registration of settings section and fields
39 $settings = new ASENHA\Classes\Settings_Sections_Fields();
40 add_action( 'admin_init', [$settings, 'register_sections_fields'] );
41 // Suppress all notices on the plugin's main page. Then add notification for successful settings update.
42 add_action( 'admin_notices', 'asenha_suppress_add_notices', 5 );
43 add_action( 'all_admin_notices', 'asenha_suppress_generic_notices', 5 );
44 // Enqueue admin scripts and styles
45 add_action( 'admin_enqueue_scripts', 'asenha_admin_scripts' );
46 add_action( 'admin_head', 'asenha_admin_menu_organizer_css' );
47 // Enqueue public scripts and styles
48 add_action( 'wp_enqueue_scripts', 'asenha_public_scripts' );
49 // Dequeue scripts that prevents settings page from working
50 add_action( 'wp_print_scripts', 'asenha_dequeue_scritps', PHP_INT_MAX );
51 add_action( 'admin_print_footer_scripts', 'asenha_dequeue_scritps', PHP_INT_MAX );
52 add_action( 'admin_enqueue_scripts-tools_page_admin-site-enhancements', 'asenha_dequeue_scritps', PHP_INT_MAX );
53 add_action( 'admin_print_scripts-tools_page_admin-site-enhancements', 'asenha_dequeue_scritps', PHP_INT_MAX );
54 // Add admin bar inline styles
55 add_action( 'admin_head', 'asenha_admin_bar_item_js_css' );
56 add_action( 'wp_head', 'asenha_admin_bar_item_js_css' );
57 add_filter( 'plugin_action_links_' . ASENHA_SLUG . '/' . ASENHA_SLUG . '.php', 'asenha_plugin_action_links' );
58 // Mark that a user have supported ASE (via AJAX)
59 add_action( 'wp_ajax_have_supported', 'asenha_have_supported' );
60 // Dismiss upgrade nudge (via AJAX)
61 add_action( 'wp_ajax_dismiss_upgrade_nudge', 'asenha_dismiss_upgrade_nudge' );
62 // Dismiss promo nudge (via AJAX)
63 add_action( 'wp_ajax_dismiss_promo_nudge', 'asenha_dismiss_promo_nudge' );
64 // Dismiss support nudge (via AJAX)
65 add_action( 'wp_ajax_dismiss_support_nudge', 'asenha_dismiss_support_nudge' );
66 // Release login lock (via AJAX)
67 add_action( 'wp_ajax_asenha_release_login_lock', 'asenha_release_login_lock' );
68 if ( function_exists( 'bwasenha_fs' ) ) {
69 bwasenha_fs()->add_filter( 'plugin_icon', 'fs_custom_optin_icon__premium_only' );
70 }
71 // Get all ASE options, default to empty array in case it's not been created yet
72 $options = get_option( ASENHA_SLUG_U, array() );
73 // Add style="display:[something];" to the safe CSS attributes.
74 // Ref: https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/kses.php#L2329
75 // Ref: https://wordpress.stackexchange.com/a/195433
76 add_filter( 'safe_style_css', function ( $styles ) {
77 $styles[] = 'display';
78 return $styles;
79 } );
80 // ===== Activate modules based on settings =====
81 // Ensure SVG admin menu icons render with the correct admin color scheme on first paint.
82 // Modules can register SVG data URI icons with this helper and then use a Dashicon placeholder.
83 if ( is_admin() ) {
84 add_action( 'admin_enqueue_scripts', array('ASENHA\\Classes\\Admin_Menu_Svg_Icon_Mask', 'enqueue_mask_css'), 99 );
85 }
86 // Content Duplication
87 if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) {
88 $content_duplication = new ASENHA\Classes\Content_Duplication();
89 add_action( 'admin_action_duplicate_content', [$content_duplication, 'duplicate_content'] );
90 add_filter(
91 'page_row_actions',
92 [$content_duplication, 'add_duplication_action_link'],
93 20,
94 2
95 );
96 add_filter(
97 'post_row_actions',
98 [$content_duplication, 'add_duplication_action_link'],
99 20,
100 2
101 );
102 add_action( 'admin_bar_menu', [$content_duplication, 'add_admin_bar_duplication_link'], 100 );
103 }
104 // Content Order
105 if ( array_key_exists( 'content_order', $options ) && $options['content_order'] ) {
106 if ( array_key_exists( 'content_order_for', $options ) && !empty( $options['content_order_for'] ) || array_key_exists( 'content_order_for_other_post_types', $options ) && !empty( $options['content_order_for_other_post_types'] ) ) {
107 $content_order = new ASENHA\Classes\Content_Order();
108 add_action( 'admin_menu', [$content_order, 'add_content_order_submenu'] );
109 add_action( 'admin_init', [$content_order, 'maybe_perform_menu_link_redirects'] );
110 add_action( 'admin_footer', [$content_order, 'add_additional_elements'] );
111 add_filter( 'admin_enqueue_scripts', [$content_order, 'add_list_tables_scripts'] );
112 add_action( 'wp_ajax_save_custom_order', [$content_order, 'save_custom_content_order'] );
113 add_filter( 'pre_get_posts', [$content_order, 'orderby_menu_order'], PHP_INT_MAX );
114 // TODO: https://developer.wordpress.org/reference/hooks/ajax_query_attachments_args/ (for grid view of media library)
115 add_filter(
116 'save_post',
117 [$content_order, 'set_menu_order_for_new_posts'],
118 10,
119 3
120 );
121 }
122 }
123 // Media Library Access Control
124 if ( array_key_exists( 'media_files_visibility_control', $options ) && $options['media_files_visibility_control'] ) {
125 $media_files_visibility_control = new ASENHA\Classes\Media_Files_Visibility_Control();
126 add_filter( 'ajax_query_attachments_args', [$media_files_visibility_control, 'filter_attachments_grid'] );
127 add_action( 'pre_get_posts', [$media_files_visibility_control, 'filter_attachments_list'] );
128 }
129 // Media Replacement
130 if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) {
131 $media_replacement = new ASENHA\Classes\Media_Replacement();
132 $disable_media_replacement_cache_busting = ( isset( $options['disable_media_replacement_cache_busting'] ) ? $options['disable_media_replacement_cache_busting'] : false );
133 add_filter(
134 'media_row_actions',
135 [$media_replacement, 'modify_media_list_table_edit_link'],
136 10,
137 2
138 );
139 add_filter(
140 'attachment_fields_to_edit',
141 [$media_replacement, 'add_media_replacement_button'],
142 10,
143 2
144 );
145 add_action( 'edit_attachment', [$media_replacement, 'replace_media'] );
146 add_filter( 'post_updated_messages', [$media_replacement, 'attachment_updated_custom_message'] );
147 // Mayve bust browser cache of old/replaced images by appending a time stamp URL parameter
148 if ( !$disable_media_replacement_cache_busting ) {
149 add_filter(
150 'wp_calculate_image_srcset',
151 [$media_replacement, 'append_cache_busting_param_to_image_srcset'],
152 10,
153 5
154 );
155 add_filter(
156 'wp_get_attachment_image_src',
157 [$media_replacement, 'append_cache_busting_param_to_attachment_image_src'],
158 10,
159 2
160 );
161 add_filter(
162 'wp_prepare_attachment_for_js',
163 [$media_replacement, 'append_cache_busting_param_to_attachment_for_js'],
164 10,
165 2
166 );
167 add_filter(
168 'wp_get_attachment_url',
169 [$media_replacement, 'append_cache_busting_param_to_attachment_url'],
170 20,
171 2
172 );
173 }
174 }
175 // Media Library Infinite Scrolling
176 if ( array_key_exists( 'media_library_infinite_scrolling', $options ) && $options['media_library_infinite_scrolling'] ) {
177 add_filter( 'media_library_infinite_scrolling', '__return_true' );
178 }
179 // SVG Upload
180 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'] ) ) {
181 global $roles_svg_upload_enabled;
182 $enable_svg_upload = $options['enable_svg_upload'];
183 $for_roles = $options['enable_svg_upload_for'];
184 // User has role(s). Do further checks.
185 if ( isset( $for_roles ) && count( $for_roles ) > 0 ) {
186 // Assemble single-dimensional array of roles for which SVG upload would be enabled
187 $roles_svg_upload_enabled = array();
188 foreach ( $for_roles as $role_slug => $svg_upload_enabled ) {
189 if ( $svg_upload_enabled ) {
190 $roles_svg_upload_enabled[] = $role_slug;
191 }
192 }
193 }
194 $svg_upload = new ASENHA\Classes\SVG_Upload();
195 add_filter( 'upload_mimes', [$svg_upload, 'add_svg_mime'] );
196 add_filter(
197 'wp_check_filetype_and_ext',
198 [$svg_upload, 'confirm_file_type_is_svg'],
199 10,
200 4
201 );
202 add_filter( 'wp_handle_sideload_prefilter', [$svg_upload, 'sanitize_and_maybe_allow_svg_upload'] );
203 add_filter( 'wp_handle_upload_prefilter', [$svg_upload, 'sanitize_and_maybe_allow_svg_upload'] );
204 add_filter(
205 'xmlrpc_prepare_media_item',
206 [$svg_upload, 'sanitize_xmlrpc_svg_upload'],
207 10,
208 2
209 );
210 add_action(
211 'rest_insert_attachment',
212 [$svg_upload, 'sanitize_after_upload'],
213 10,
214 3
215 );
216 add_filter(
217 'wp_generate_attachment_metadata',
218 [$svg_upload, 'generate_svg_metadata'],
219 10,
220 3
221 );
222 add_filter( 'wp_calculate_image_srcset', [$svg_upload, 'disable_svg_srcset'] );
223 if ( !in_array( 'auto-sizes/auto-sizes.php', get_option( 'active_plugins', array() ) ) ) {
224 // Only add this filter when https://wordpress.org/plugins/auto-sizes/ is not active to prevent PHP deprecation notice
225 add_filter(
226 'wp_calculate_image_sizes',
227 [$svg_upload, 'remove_svg_responsive_image_attr'],
228 10,
229 3
230 );
231 }
232 add_action( 'wp_ajax_svg_get_attachment_url', [$svg_upload, 'get_svg_attachment_url'] );
233 add_filter( 'wp_prepare_attachment_for_js', [$svg_upload, 'get_svg_url_in_media_library'] );
234 }
235 // AVIF Upload
236 if ( array_key_exists( 'enable_avif_upload', $options ) && $options['enable_avif_upload'] ) {
237 $avif_upload = new ASENHA\Classes\AVIF_Upload();
238 add_filter( 'mime_types', [$avif_upload, 'add_avif_mime_type'] );
239 add_filter( 'upload_mimes', [$avif_upload, 'allow_avif_mime_type_upload'] );
240 add_filter( 'getimagesize_mimes_to_exts', [$avif_upload, 'add_avif_mime_type_to_exts'] );
241 add_filter(
242 'wp_generate_attachment_metadata',
243 [$avif_upload, 'add_avif_image_dimension'],
244 10,
245 3
246 );
247 add_filter(
248 'file_is_displayable_image',
249 [$avif_upload, 'make_avif_displayable'],
250 10,
251 2
252 );
253 add_filter(
254 'wp_check_filetype_and_ext',
255 [$avif_upload, 'handle_exif_and_fileinfo_fail'],
256 10,
257 5
258 );
259 }
260 // External Permalinks
261 if ( array_key_exists( 'enable_external_permalinks', $options ) && $options['enable_external_permalinks'] ) {
262 if ( array_key_exists( 'enable_external_permalinks_for', $options ) && !empty( $options['enable_external_permalinks_for'] ) ) {
263 $external_permalinks = new ASENHA\Classes\External_Permalinks();
264 add_action(
265 'add_meta_boxes',
266 [$external_permalinks, 'add_external_permalink_meta_box'],
267 10,
268 2
269 );
270 add_action( 'save_post', [$external_permalinks, 'save_external_permalink'] );
271 // Filter the permalink for use by get_permalink()
272 add_filter(
273 'page_link',
274 [$external_permalinks, 'use_external_permalink_for_pages'],
275 20,
276 2
277 );
278 add_filter(
279 'post_link',
280 [$external_permalinks, 'use_external_permalink_for_posts'],
281 20,
282 2
283 );
284 add_filter(
285 'post_type_link',
286 [$external_permalinks, 'use_external_permalink_for_posts'],
287 20,
288 2
289 );
290 // Enable redirection to external permalink when page/post is opened directly via it's WP permalink
291 add_action( 'wp', [$external_permalinks, 'redirect_to_external_permalink'] );
292 }
293 }
294 // Open All External Links in New Tab
295 if ( array_key_exists( 'external_links_new_tab', $options ) && $options['external_links_new_tab'] ) {
296 $open_external_links_in_new_tab = new ASENHA\Classes\Open_External_Links_In_New_Tab();
297 add_filter( 'the_content', [$open_external_links_in_new_tab, 'add_target_and_rel_atts_to_content_links'] );
298 if ( in_array( 'elementor/elementor.php', get_option( 'active_plugins', array() ) ) ) {
299 add_filter( 'elementor/frontend/the_content', [$open_external_links_in_new_tab, 'add_target_and_rel_atts_to_content_links'] );
300 }
301 }
302 // Allow Custom Menu Links to Open in New Tab
303 if ( array_key_exists( 'custom_nav_menu_items_new_tab', $options ) && $options['custom_nav_menu_items_new_tab'] ) {
304 $custom_nav_menu_items_in_new_tab = new ASENHA\Classes\Custom_Nav_Menu_Items_In_New_Tab();
305 add_filter(
306 'wp_nav_menu_item_custom_fields',
307 [$custom_nav_menu_items_in_new_tab, 'add_custom_nav_menu_open_in_new_tab_field'],
308 10,
309 4
310 );
311 add_action(
312 'wp_update_nav_menu_item',
313 [$custom_nav_menu_items_in_new_tab, 'save_custom_nav_menu_open_in_new_tab_status'],
314 10,
315 3
316 );
317 add_action(
318 'nav_menu_link_attributes',
319 [$custom_nav_menu_items_in_new_tab, 'add_attributes_to_custom_nav_menu_item'],
320 10,
321 3
322 );
323 }
324 // Auto-Publishing of Posts with Missed Schedules
325 if ( array_key_exists( 'enable_missed_schedule_posts_auto_publish', $options ) && $options['enable_missed_schedule_posts_auto_publish'] ) {
326 $auto_publish_posts_with_missed_schedule = new ASENHA\Classes\Auto_Publish_Posts_With_Missed_Schedule();
327 add_action( 'wp_head', [$auto_publish_posts_with_missed_schedule, 'publish_missed_schedule_posts'] );
328 add_action( 'admin_head', [$auto_publish_posts_with_missed_schedule, 'publish_missed_schedule_posts'] );
329 }
330 // Hide or Modify Elements / Clean Up Admin Bar
331 if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) {
332 $cleanup_admin_bar = new ASENHA\Classes\Cleanup_Admin_Bar();
333 // Priority 5 to execute earlier than the normal 10. This is for removing default items.
334 add_filter( 'admin_bar_menu', [$cleanup_admin_bar, 'modify_admin_bar_menu'], 5 );
335 add_filter( 'admin_bar_menu', [$cleanup_admin_bar, 'remove_howdy'], PHP_INT_MAX - 100 );
336 if ( array_key_exists( 'hide_help_drawer', $options ) && $options['hide_help_drawer'] ) {
337 add_action( 'admin_head', [$cleanup_admin_bar, 'hide_help_drawer'] );
338 }
339 }
340 // Hide Admin Notices
341 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
342 $hide_admin_notices = new ASENHA\Classes\Hide_Admin_Notices();
343 add_action( 'admin_footer', [$hide_admin_notices, 'admin_notices_wrapper'], 9 );
344 // add_action( 'all_admin_notices', [ $hide_admin_notices, 'admin_notices_wrapper' ] );
345 // add_action( 'admin_notices', [ $hide_admin_notices, 'show_test_admin_notice_for_all_user_roles' ] );
346 add_action( 'admin_bar_menu', [$hide_admin_notices, 'admin_notices_menu'] );
347 add_action( 'admin_print_styles', [$hide_admin_notices, 'admin_notices_menu_inline_css'] );
348 }
349 // Disable Dashboard Widgets
350 if ( array_key_exists( 'disable_dashboard_widgets', $options ) && $options['disable_dashboard_widgets'] ) {
351 $disable_dashboard_widgets = new ASENHA\Classes\Disable_Dashboard_Widgets();
352 add_action( 'wp_dashboard_setup', [$disable_dashboard_widgets, 'disable_dashboard_widgets'], PHP_INT_MAX );
353 add_action( 'admin_init', [$disable_dashboard_widgets, 'maybe_remove_welcome_panel'] );
354 }
355 // Hide Admin Bar
356 if ( array_key_exists( 'hide_admin_bar', $options ) && $options['hide_admin_bar'] ) {
357 $hide_admin_bar = new ASENHA\Classes\Hide_Admin_Bar();
358 }
359 // On the frontend
360 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'] ) ) {
361 add_filter( 'show_admin_bar', [$hide_admin_bar, 'hide_admin_bar_for_roles_on_frontend'] );
362 }
363 // Wider Admin Menu
364 if ( array_key_exists( 'wider_admin_menu', $options ) && $options['wider_admin_menu'] ) {
365 $wider_admin_menu = new ASENHA\Classes\Wider_Admin_Menu();
366 add_action( 'admin_head', [$wider_admin_menu, 'set_custom_menu_width'], 99 );
367 }
368 // Admin Menu Organizer
369 if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) {
370 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
371 $admin_menu_options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() );
372 $admin_menu_organizer = new ASENHA\Classes\Admin_Menu_Organizer();
373 if ( array_key_exists( 'admin_menu_organizer_sticky_collapse_menu', $options ) && $options['admin_menu_organizer_sticky_collapse_menu'] ) {
374 add_action( 'admin_head', [$admin_menu_organizer, 'make_collapse_menu_item_sticky'] );
375 }
376 add_action( 'admin_menu', [$admin_menu_organizer, 'add_menu_item'] );
377 // add_action( 'wp_ajax_save_custom_menu_order', [ $admin_menu_organizer, 'save_custom_menu_order' ] );
378 // add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_menu_organizer, 'save_hidden_menu_items' ] );
379 if ( array_key_exists( 'custom_menu_order', $admin_menu_options ) ) {
380 add_filter( 'custom_menu_order', '__return_true', PHP_INT_MAX );
381 add_filter( 'menu_order', [$admin_menu_organizer, 'render_custom_menu_order'], PHP_INT_MAX );
382 }
383 if ( array_key_exists( 'custom_menu_titles', $admin_menu_options ) ) {
384 add_action( 'admin_menu', [$admin_menu_organizer, 'apply_custom_menu_item_titles'], 9999999995 );
385 add_action( 'init', [$admin_menu_organizer, 'apply_custom_title_for_posts_menu'] );
386 }
387 if ( array_key_exists( 'custom_menu_hidden', $admin_menu_options ) || array_key_exists( 'custom_menu_always_hidden', $admin_menu_options ) ) {
388 add_action( 'admin_menu', [$admin_menu_organizer, 'hide_menu_items'], 9999999996 );
389 add_action( 'admin_menu', [$admin_menu_organizer, 'add_hidden_menu_toggle'], 9999999997 );
390 add_action( 'admin_enqueue_scripts', [$admin_menu_organizer, 'enqueue_toggle_hidden_menu_script'] );
391 }
392 add_action( 'wp_ajax_save_admin_menu', [$admin_menu_organizer, 'save_admin_menu'] );
393 }
394 // Show Custom Taxonomy Filters
395 if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) {
396 $show_custom_taxonomy_filters = new ASENHA\Classes\Show_Custom_Taxonomy_Filters();
397 add_action( 'restrict_manage_posts', [$show_custom_taxonomy_filters, 'show_custom_taxonomy_filters'] );
398 }
399 // Enhance List Tables
400 if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) {
401 $enhance_list_tables = new ASENHA\Classes\Enhance_List_Tables();
402 // Show Featured Image Column
403 if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) {
404 add_action( 'admin_init', [$enhance_list_tables, 'show_featured_image_column'] );
405 }
406 // Show Excerpt Column
407 if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) {
408 add_action( 'admin_init', [$enhance_list_tables, 'show_excerpt_column'] );
409 }
410 // Show Last Modified Column
411 if ( array_key_exists( 'show_last_modified_column', $options ) && $options['show_last_modified_column'] ) {
412 add_action( 'admin_init', [$enhance_list_tables, 'show_last_modified_column'] );
413 }
414 // Show ID Column
415 if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) {
416 add_action( 'admin_init', [$enhance_list_tables, 'show_id_column'] );
417 }
418 // Show File Size Column in Media Library
419 if ( array_key_exists( 'show_file_size_column', $options ) && $options['show_file_size_column'] ) {
420 add_filter( 'manage_upload_columns', [$enhance_list_tables, 'add_column_file_size'] );
421 add_action(
422 'manage_media_custom_column',
423 [$enhance_list_tables, 'display_file_size'],
424 10,
425 2
426 );
427 add_action( 'admin_head', [$enhance_list_tables, 'add_media_styles'] );
428 }
429 // Show ID in Action Row
430 if ( array_key_exists( 'show_id_in_action_row', $options ) && $options['show_id_in_action_row'] ) {
431 add_action( 'admin_init', [$enhance_list_tables, 'show_id_in_action_row'] );
432 }
433 // Hide Date Column
434 if ( array_key_exists( 'hide_date_column', $options ) && $options['hide_date_column'] ) {
435 add_action( 'admin_init', [$enhance_list_tables, 'hide_date_column'] );
436 }
437 // Hide Comments Column
438 if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) {
439 add_action( 'admin_init', [$enhance_list_tables, 'hide_comments_column'] );
440 }
441 // Hide Post Tags Column
442 if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) {
443 add_action( 'admin_init', [$enhance_list_tables, 'hide_post_tags_column'] );
444 }
445 }
446 // Various Admin UI Enhancements
447 if ( array_key_exists( 'various_admin_ui_enhancements', $options ) && $options['various_admin_ui_enhancements'] ) {
448 $various_admin_ui_enhancements = new ASENHA\Classes\Various_Admin_Ui_Enhancements();
449 // Display Active Plugins First
450 if ( array_key_exists( 'display_active_plugins_first', $options ) && $options['display_active_plugins_first'] ) {
451 add_action( 'admin_head-plugins.php', [$various_admin_ui_enhancements, 'show_active_plugins_first'] );
452 }
453 }
454 // Custom Admin Footer Text
455 if ( array_key_exists( 'custom_admin_footer_text', $options ) && $options['custom_admin_footer_text'] ) {
456 $custom_admin_footer_text = new ASENHA\Classes\Custom_Admin_Footer_Text();
457 // Update footer text
458 if ( is_asenha() ) {
459 add_filter( 'admin_footer_text', 'asenha_footer_text', 20 );
460 } else {
461 add_filter( 'admin_footer_text', [$custom_admin_footer_text, 'custom_admin_footer_text_left'], 20 );
462 }
463 // Update footer version text
464 if ( is_asenha() ) {
465 add_filter( 'update_footer', 'asenha_footer_version_text', 20 );
466 } else {
467 add_filter( 'update_footer', [$custom_admin_footer_text, 'custom_admin_footer_text_right'], 20 );
468 }
469 } else {
470 // Update footer text
471 if ( is_asenha() ) {
472 add_filter( 'admin_footer_text', 'asenha_footer_text', 20 );
473 }
474 // Update footer version text
475 if ( is_asenha() ) {
476 add_filter( 'update_footer', 'asenha_footer_version_text', 20 );
477 }
478 }
479 // =================================================================
480 // LOG IN | LOG OUT
481 // =================================================================
482 // Change Login URL
483 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
484 if ( array_key_exists( 'custom_login_slug', $options ) && !empty( $options['custom_login_slug'] ) ) {
485 $change_login_url = new ASENHA\Classes\Change_Login_URL();
486 add_action( 'init', [$change_login_url, 'redirect_on_custom_login_url'] );
487 if ( in_array( 'gravityforms/gravityforms.php', get_option( 'active_plugins', array() ) ) ) {
488 // Load earlier than Gravity Forms process_exterior_pages()
489 add_action( 'wp', [$change_login_url, 'prevent_redirect_to_custom_login_url'], 0 );
490 }
491 add_filter(
492 'login_url',
493 [$change_login_url, 'customize_login_url'],
494 10,
495 3
496 );
497 add_filter( 'lostpassword_url', [$change_login_url, 'customize_lost_password_url'] );
498 add_filter( 'register_url', [$change_login_url, 'customize_register_url'] );
499 add_action( 'wp_loaded', [$change_login_url, 'redirect_on_default_login_urls'] );
500 add_action( 'wp_login_failed', [$change_login_url, 'redirect_to_custom_login_url_on_login_fail'] );
501 add_filter( 'login_message', [$change_login_url, 'add_failed_login_message'] );
502 // No need to modify logout_url or perform redirect on logout
503 // The customized login URL is already being returned after logout
504 // add_action( 'wp_logout', [ $change_login_url, 'redirect_to_custom_login_url_on_logout_success' ] );
505 // add_filter( 'logout_url', [ $change_login_url, 'customize_logout_url' ], 10, 2 );
506 }
507 }
508 // Login ID Type
509 if ( array_key_exists( 'login_id_type_restriction', $options ) && $options['login_id_type_restriction'] ) {
510 if ( array_key_exists( 'login_id_type', $options ) && !empty( $options['login_id_type'] ) ) {
511 $login_id_type = new ASENHA\Classes\Login_ID_Type();
512 switch ( $options['login_id_type'] ) {
513 case 'username':
514 remove_filter( 'authenticate', 'wp_authenticate_email_password', 20 );
515 add_filter( 'login_form_defaults', [$login_id_type, 'change_login_form_defaults'] );
516 add_filter(
517 'gettext',
518 [$login_id_type, 'gettext_login_id_username'],
519 20,
520 3
521 );
522 break;
523 case 'email':
524 add_filter(
525 'authenticate',
526 [$login_id_type, 'authenticate_email'],
527 20,
528 2
529 );
530 add_filter(
531 'gettext',
532 [$login_id_type, 'gettext_login_id_email'],
533 20,
534 3
535 );
536 break;
537 }
538 }
539 }
540 // Use Site Identity on the Login Page
541 if ( array_key_exists( 'site_identity_on_login', $options ) && $options['site_identity_on_login'] ) {
542 $site_identity_on_login_page = new ASENHA\Classes\Site_Identity_On_Login_Page();
543 add_action( 'login_head', [$site_identity_on_login_page, 'use_site_icon_on_login'] );
544 add_filter( 'login_headerurl', [$site_identity_on_login_page, 'use_site_url_on_login'] );
545 }
546 // Login Logout Menu
547 if ( array_key_exists( 'enable_login_logout_menu', $options ) && $options['enable_login_logout_menu'] ) {
548 $login_logout_menu = new ASENHA\Classes\Login_Logout_Menu();
549 add_action( 'admin_head-nav-menus.php', [$login_logout_menu, 'add_login_logout_metabox'] );
550 add_filter( 'wp_setup_nav_menu_item', [$login_logout_menu, 'set_login_logout_menu_item_dynamic_url'] );
551 add_filter( 'wp_nav_menu_objects', [$login_logout_menu, 'maybe_remove_login_or_logout_menu_item'] );
552 }
553 // Last Login Column
554 if ( array_key_exists( 'enable_last_login_column', $options ) && $options['enable_last_login_column'] ) {
555 $last_login_column = new ASENHA\Classes\Last_Login_Column();
556 add_action(
557 'wp_login',
558 [$last_login_column, 'log_login_datetime'],
559 3,
560 1
561 );
562 // Earlier than Redirect After Login
563 add_filter( 'manage_users_columns', [$last_login_column, 'add_last_login_column'] );
564 add_filter(
565 'manage_users_custom_column',
566 [$last_login_column, 'show_last_login_info'],
567 10,
568 3
569 );
570 add_action( 'admin_print_styles-users.php', [$last_login_column, 'add_column_style'] );
571 }
572 // Registration Date Column
573 if ( array_key_exists( 'registration_date_column', $options ) && $options['registration_date_column'] ) {
574 $registration_date_column = new ASENHA\Classes\Registration_Date_Column();
575 add_filter( 'manage_users_columns', [$registration_date_column, 'add_registration_date_column'] );
576 add_filter(
577 'manage_users_custom_column',
578 [$registration_date_column, 'display_registration_date'],
579 10,
580 3
581 );
582 }
583 // Redirect After Login
584 if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) {
585 if ( array_key_exists( 'redirect_after_login_for', $options ) && !empty( $options['redirect_after_login_for'] ) ) {
586 $redirect_after_login = new ASENHA\Classes\Redirect_After_Login();
587 add_filter(
588 'wp_login',
589 [$redirect_after_login, 'redirect_after_login'],
590 5,
591 2
592 );
593 }
594 }
595 // Redirect After Logout
596 if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) {
597 if ( array_key_exists( 'redirect_after_logout_for', $options ) && !empty( $options['redirect_after_logout_for'] ) ) {
598 $redirect_after_logout = new ASENHA\Classes\Redirect_After_Logout();
599 add_action(
600 'wp_logout',
601 [$redirect_after_logout, 'redirect_after_logout'],
602 5,
603 1
604 );
605 // load earlier than Change Login URL add_action
606 // add_filter( 'logout_redirect', [ $redirect_after_logout, 'apply_custom_logout_redirect' ], PHP_INT_MAX, 3 );
607 // add_filter( 'logout_url', [ $redirect_after_logout, 'add_redirect_to_in_logout_url' ], PHP_INT_MAX, 2 );
608 }
609 }
610 // Enable Custom Admin / Frontend CSS
611 if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] || array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
612 $custom_css = new ASENHA\Classes\Custom_Css();
613 }
614 if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) {
615 // add_filter( 'admin_enqueue_scripts', [ $custom_css, 'custom_admin_css' ] );
616 add_filter( 'admin_print_footer_scripts', [$custom_css, 'custom_admin_css'] );
617 }
618 if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
619 add_filter( 'wp_head', [$custom_css, 'custom_frontend_css'] );
620 }
621 // Insert <head>, <body> and <footer> code
622 if ( array_key_exists( 'insert_head_body_footer_code', $options ) && $options['insert_head_body_footer_code'] ) {
623 $insert_code = new ASENHA\Classes\Insert_Head_Body_Footer_Code();
624 if ( isset( $options['head_code_priority'] ) ) {
625 add_action( 'wp_head', [$insert_code, 'insert_head_code'], $options['head_code_priority'] );
626 } else {
627 add_action( 'wp_head', [$insert_code, 'insert_head_code'], 10 );
628 }
629 if ( function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ) {
630 if ( isset( $options['body_code_priority'] ) ) {
631 add_action( 'wp_body_open', [$insert_code, 'insert_body_code'], $options['body_code_priority'] );
632 } else {
633 add_action( 'wp_body_open', [$insert_code, 'insert_body_code'], 10 );
634 }
635 }
636 if ( isset( $options['footer_code_priority'] ) ) {
637 add_action( 'wp_footer', [$insert_code, 'insert_footer_code'], $options['footer_code_priority'] );
638 } else {
639 add_action( 'wp_footer', [$insert_code, 'insert_footer_code'], 10 );
640 }
641 }
642 // Custom Body Class
643 if ( array_key_exists( 'enable_custom_body_class', $options ) && $options['enable_custom_body_class'] ) {
644 if ( array_key_exists( 'enable_custom_body_class_for', $options ) && !empty( $options['enable_custom_body_class_for'] ) ) {
645 $custom_body_class = new ASENHA\Classes\Custom_Body_Class();
646 add_action(
647 'add_meta_boxes',
648 [$custom_body_class, 'add_custom_body_class_meta_box'],
649 10,
650 2
651 );
652 add_action( 'save_post', [$custom_body_class, 'save_custom_body_class'], 99 );
653 add_filter( 'body_class', [$custom_body_class, 'append_custom_body_class'], 99 );
654 }
655 }
656 // Manage ads.txt and app-ads.txt
657 if ( array_key_exists( 'manage_ads_appads_txt', $options ) && $options['manage_ads_appads_txt'] ) {
658 $manage_ads_appads_txt = new ASENHA\Classes\Manage_Ads_Appads_Txt();
659 add_action( 'init', [$manage_ads_appads_txt, 'show_ads_appads_txt_content'] );
660 }
661 // Manage robots.txt
662 if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) {
663 $manage_robots_txt = new ASENHA\Classes\Manage_Robots_Txt();
664 add_filter(
665 'robots_txt',
666 [$manage_robots_txt, 'maybe_show_custom_robots_txt_content'],
667 PHP_INT_MAX,
668 2
669 );
670 }
671 // =================================================================
672 // DISABLE COMPONENTS
673 // =================================================================
674 // Disable Gutenberg
675 if ( array_key_exists( 'disable_gutenberg', $options ) && $options['disable_gutenberg'] ) {
676 if ( array_key_exists( 'disable_gutenberg_for', $options ) && !empty( $options['disable_gutenberg_for'] ) ) {
677 $disable_gutenberg = new ASENHA\Classes\Disable_Gutenberg();
678 if ( !class_exists( 'Classic_Editor' ) ) {
679 require_once ASENHA_PATH . 'includes/empty-class-classic-editor.php';
680 }
681 add_action( 'admin_init', [$disable_gutenberg, 'disable_gutenberg_for_post_types_admin'] );
682 add_action( 'admin_print_styles', [$disable_gutenberg, 'safari_18_fix'] );
683 if ( array_key_exists( 'disable_gutenberg_frontend_styles', $options ) && $options['disable_gutenberg_frontend_styles'] ) {
684 add_action( 'wp_enqueue_scripts', [$disable_gutenberg, 'disable_gutenberg_for_post_types_frontend'], 999999 );
685 add_action( 'wp_footer', [$disable_gutenberg, 'disable_gutenberg_for_post_types_frontend'] );
686 }
687 }
688 }
689 // Disable Comments
690 if ( array_key_exists( 'disable_comments', $options ) && $options['disable_comments'] ) {
691 if ( array_key_exists( 'disable_comments_for', $options ) && !empty( $options['disable_comments_for'] ) ) {
692 $disable_comments = new ASENHA\Classes\Disable_Comments();
693 add_action( 'admin_init', [$disable_comments, 'disable_comments_for_post_types_edit'] );
694 // also work with 'init', 'admin_init', 'wp_loaded', 'do_meta_boxes' hooks
695 add_action( 'template_redirect', [$disable_comments, 'show_blank_comment_template'] );
696 add_action( 'wp_loaded', [$disable_comments, 'hide_existing_comments_on_frontend'] );
697 add_filter(
698 'comments_array',
699 [$disable_comments, 'maybe_return_empty_comments'],
700 20,
701 2
702 );
703 add_filter(
704 'comments_open',
705 [$disable_comments, 'close_comments_pings_on_frontend'],
706 20,
707 2
708 );
709 add_filter(
710 'pings_open',
711 [$disable_comments, 'close_comments_pings_on_frontend'],
712 20,
713 2
714 );
715 add_filter(
716 'get_comments_number',
717 [$disable_comments, 'return_zero_comments_count'],
718 20,
719 2
720 );
721 // Disable commenting via XML-RPC
722 add_filter( 'xmlrpc_allow_anonymous_comments', '__return_false' );
723 add_filter( 'xmlrpc_methods', [$disable_comments, 'disable_xmlrpc_comments'] );
724 // Disable commenting via REST API
725 add_filter( 'rest_endpoints', [$disable_comments, 'disable_rest_api_comments_endpoints'] );
726 add_filter(
727 'rest_pre_insert_comment',
728 [$disable_comments, 'return_blank_comment'],
729 10,
730 2
731 );
732 }
733 }
734 // Disable REST API
735 if ( array_key_exists( 'disable_rest_api', $options ) && $options['disable_rest_api'] ) {
736 if ( version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
737 $disable_rest_api = new ASENHA\Classes\Disable_REST_API();
738 add_filter( 'rest_authentication_errors', [$disable_rest_api, 'disable_rest_api'] );
739 } else {
740 // REST API 1.x
741 add_filter( 'json_enabled', '__return_false' );
742 add_filter( 'json_jsonp_enabled', '__return_false' );
743 // REST API 2.x
744 add_filter( 'rest_enabled', '__return_false' );
745 add_filter( 'rest_jsonp_enabled', '__return_false' );
746 }
747 remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
748 // Disable REST API links in HTML <head>
749 remove_action(
750 'template_redirect',
751 'rest_output_link_header',
752 11,
753 0
754 );
755 // Disable REST API link in HTTP headers
756 remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
757 // Remove REST API URL from the WP RSD endpoint.
758 }
759 // Disable Feeds
760 if ( array_key_exists( 'disable_feeds', $options ) && $options['disable_feeds'] ) {
761 remove_action( 'wp_head', 'feed_links', 2 );
762 // Remove feed links in <head>
763 remove_action( 'wp_head', 'feed_links_extra', 3 );
764 // Remove feed links in <head>
765 remove_action(
766 'do_feed_rdf',
767 'do_feed_rdf',
768 10,
769 0
770 );
771 remove_action(
772 'do_feed_rss',
773 'do_feed_rss',
774 10,
775 0
776 );
777 remove_action(
778 'do_feed_rss2',
779 'do_feed_rss2',
780 10,
781 1
782 );
783 remove_action(
784 'do_feed_atom',
785 'do_feed_atom',
786 10,
787 1
788 );
789 $disable_feeds = new ASENHA\Classes\Disable_Feeds();
790 add_action(
791 'template_redirect',
792 [$disable_feeds, 'redirect_feed_to_403'],
793 10,
794 1
795 );
796 }
797 // Disable Feeds
798 if ( array_key_exists( 'disable_embeds', $options ) && $options['disable_embeds'] ) {
799 $disable_embeds = new ASENHA\Classes\Disable_Embeds();
800 add_action( 'init', [$disable_embeds, 'disable_embeds_init'], 9999 );
801 }
802 // Disable All Updates
803 if ( array_key_exists( 'disable_all_updates', $options ) && $options['disable_all_updates'] ) {
804 $disable_updates = new ASENHA\Classes\Disable_Updates();
805 add_action( 'admin_init', [$disable_updates, 'disable_update_notices_version_checks'] );
806 // Disable core update
807 add_filter( 'pre_transient_update_core', [$disable_updates, 'override_version_check_info'] );
808 add_filter( 'pre_site_transient_update_core', [$disable_updates, 'override_version_check_info'] );
809 // Disable theme updates
810 add_filter( 'pre_transient_update_themes', [$disable_updates, 'override_version_check_info'] );
811 add_filter( 'pre_site_transient_update_themes', [$disable_updates, 'override_version_check_info'] );
812 add_action( 'pre_set_site_transient_update_themes', [$disable_updates, 'override_version_check_info'], 20 );
813 // Disable plugin updates
814 add_filter( 'pre_transient_update_plugins', [$disable_updates, 'override_version_check_info'] );
815 add_filter( 'pre_site_transient_update_plugins', [$disable_updates, 'override_version_check_info'] );
816 add_action( 'pre_set_site_transient_update_plugins', [$disable_updates, 'override_version_check_info'], 20 );
817 // Disable auto updates
818 add_filter( 'automatic_updater_disabled', '__return_true' );
819 if ( !defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) {
820 define( 'AUTOMATIC_UPDATER_DISABLED', true );
821 }
822 if ( !defined( 'WP_AUTO_UPDATE_CORE' ) ) {
823 define( 'WP_AUTO_UPDATE_CORE', false );
824 }
825 add_filter( 'auto_update_core', '__return_false' );
826 add_filter( 'wp_auto_update_core', '__return_false' );
827 add_filter( 'allow_minor_auto_core_updates', '__return_false' );
828 add_filter( 'allow_major_auto_core_updates', '__return_false' );
829 add_filter( 'allow_dev_auto_core_updates', '__return_false' );
830 add_filter( 'auto_update_plugin', '__return_false' );
831 add_filter( 'auto_update_theme', '__return_false' );
832 add_filter( 'auto_update_translation', '__return_false' );
833 remove_action( 'init', 'wp_schedule_update_checks' );
834 // Disable update emails
835 add_filter( 'auto_core_update_send_email', '__return_false' );
836 add_filter( 'send_core_update_notification_email', '__return_false' );
837 add_filter( 'automatic_updates_send_debug_email', '__return_false' );
838 // Remove Dashboard >> Updates menu
839 add_action( 'admin_menu', [$disable_updates, 'remove_updates_menu'] );
840 }
841 // Disable Author Archives
842 if ( array_key_exists( 'disable_author_archives', $options ) && $options['disable_author_archives'] ) {
843 $disable_author_archives = new ASENHA\Classes\Disable_Author_Archives();
844 add_action( 'template_redirect', [$disable_author_archives, 'redirect_to_404'], 1 );
845 add_filter( 'author_link', [$disable_author_archives, 'disable_frontend_author_link'], PHP_INT_MAX );
846 add_filter( 'user_row_actions', [$disable_author_archives, 'remove_user_view_action'], PHP_INT_MAX );
847 if ( class_exists( 'WP_Sitemaps' ) ) {
848 add_filter(
849 'wp_sitemaps_add_provider',
850 [$disable_author_archives, 'remove_users_from_sitemap'],
851 PHP_INT_MAX,
852 2
853 );
854 }
855 add_filter( 'author_rewrite_rules', [$disable_author_archives, 'disable_rewrite_rules_for_authors'], 10 );
856 }
857 // Disable Smaller Components
858 if ( array_key_exists( 'disable_smaller_components', $options ) && $options['disable_smaller_components'] ) {
859 $disable_smaller_components = new ASENHA\Classes\Disable_Smaller_Components();
860 if ( array_key_exists( 'disable_head_generator_tag', $options ) && $options['disable_head_generator_tag'] ) {
861 remove_action( 'wp_head', 'wp_generator' );
862 }
863 if ( array_key_exists( 'disable_feed_generator_tag', $options ) && $options['disable_feed_generator_tag'] ) {
864 add_filter(
865 'the_generator',
866 [$disable_smaller_components, 'remove_feed_generator_tag'],
867 10,
868 2
869 );
870 }
871 if ( array_key_exists( 'disable_resource_version_number', $options ) && $options['disable_resource_version_number'] ) {
872 add_filter( 'style_loader_src', [$disable_smaller_components, 'remove_resource_version_number'], PHP_INT_MAX );
873 add_filter( 'script_loader_src', [$disable_smaller_components, 'remove_resource_version_number'], PHP_INT_MAX );
874 }
875 if ( array_key_exists( 'disable_head_wlwmanifest_tag', $options ) && $options['disable_head_wlwmanifest_tag'] ) {
876 remove_action( 'wp_head', 'wlwmanifest_link' );
877 }
878 if ( array_key_exists( 'disable_head_rsd_tag', $options ) && $options['disable_head_rsd_tag'] ) {
879 remove_action( 'wp_head', 'rsd_link' );
880 }
881 if ( array_key_exists( 'disable_head_shortlink_tag', $options ) && $options['disable_head_shortlink_tag'] ) {
882 // https://github.com/WordPress/wordpress-develop/blob/646fd2308f87332b0db5218ee2071c0ff8db0d4c/src/wp-includes/default-filters.php#L358
883 remove_action( 'wp_head', 'wp_shortlink_wp_head' );
884 // https://github.com/WordPress/wordpress-develop/blob/646fd2308f87332b0db5218ee2071c0ff8db0d4c/src/wp-includes/default-filters.php#L363
885 remove_action(
886 'template_redirect',
887 'wp_shortlink_header',
888 11,
889 0
890 );
891 }
892 if ( array_key_exists( 'disable_frontend_dashicons', $options ) && $options['disable_frontend_dashicons'] ) {
893 add_action( 'init', [$disable_smaller_components, 'disable_dashicons_public_assets'] );
894 }
895 if ( array_key_exists( 'disable_emoji_support', $options ) && $options['disable_emoji_support'] ) {
896 add_action( 'init', [$disable_smaller_components, 'disable_emoji_support'] );
897 }
898 if ( array_key_exists( 'disable_jquery_migrate', $options ) && $options['disable_jquery_migrate'] ) {
899 add_action( 'wp_default_scripts', [$disable_smaller_components, 'disable_jquery_migrate'] );
900 }
901 if ( array_key_exists( 'disable_block_widgets', $options ) && $options['disable_block_widgets'] ) {
902 // Disables the block editor from managing widgets in the Gutenberg plugin.
903 add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
904 // Disables the block editor from managing widgets.
905 add_filter( 'use_widgets_block_editor', '__return_false' );
906 }
907 if ( array_key_exists( 'disable_lazy_load', $options ) && $options['disable_lazy_load'] ) {
908 add_filter( 'wp_lazy_loading_enabled', '__return_false' );
909 add_filter( 'wp_get_attachment_image_attributes', [$disable_smaller_components, 'eager_load_featured_images'] );
910 }
911 if ( array_key_exists( 'disable_application_passwords', $options ) && $options['disable_application_passwords'] ) {
912 add_filter( 'wp_is_application_passwords_available', '__return_false' );
913 }
914 if ( array_key_exists( 'disable_plugin_theme_editor', $options ) ) {
915 if ( $options['disable_plugin_theme_editor'] ) {
916 add_action( 'admin_init', [$disable_smaller_components, 'disable_plugin_theme_editor'], PHP_INT_MAX );
917 } else {
918 add_action( 'admin_init', [$disable_smaller_components, 'enable_plugin_theme_editor'], PHP_INT_MAX );
919 }
920 }
921 }
922 // =================================================================
923 // SECURITY
924 // =================================================================
925 // Limit Login Attempts
926 if ( array_key_exists( 'limit_login_attempts', $options ) && $options['limit_login_attempts'] ) {
927 $limit_login_attempts = new ASENHA\Classes\Limit_Login_Attempts();
928 add_filter(
929 'authenticate',
930 [$limit_login_attempts, 'maybe_allow_login'],
931 999,
932 3
933 );
934 // Very low priority so it is processed last
935 add_action(
936 'wp_login_errors',
937 [$limit_login_attempts, 'login_error_handler'],
938 999,
939 2
940 );
941 add_action( 'login_enqueue_scripts', [$limit_login_attempts, 'maybe_hide_login_form'] );
942 add_filter( 'login_message', [$limit_login_attempts, 'add_failed_login_message'] );
943 add_action( 'wp_login_failed', [$limit_login_attempts, 'log_failed_login'], 5 );
944 // Higher priority than one in Change Login URL
945 add_action( 'wp_login', [$limit_login_attempts, 'clear_failed_login_log'] );
946 // Log table clean up
947 add_action( 'added_option', [$limit_login_attempts, 'trigger_clear_or_schedule_log_clean_up_by_amount'] );
948 add_action( 'updated_option', [$limit_login_attempts, 'trigger_clear_or_schedule_log_clean_up_by_amount'] );
949 add_action( 'plugins_loaded', [$limit_login_attempts, 'clear_or_schedule_log_clean_up_by_amount'] );
950 add_action( 'asenha_failed_login_attempts_log_cleanup_by_amount', [$limit_login_attempts, 'perform_failed_login_attempts_log_clean_up_by_amount'] );
951 }
952 // Obfuscate Author Slugs
953 if ( array_key_exists( 'obfuscate_author_slugs', $options ) && $options['obfuscate_author_slugs'] ) {
954 $obfuscate_author_slugs = new ASENHA\Classes\Obfuscate_Author_Slugs();
955 add_action( 'pre_get_posts', [$obfuscate_author_slugs, 'alter_author_query'], 10 );
956 add_filter(
957 'author_link',
958 [$obfuscate_author_slugs, 'alter_author_link'],
959 10,
960 3
961 );
962 add_filter(
963 'rest_prepare_user',
964 [$obfuscate_author_slugs, 'alter_json_users'],
965 10,
966 3
967 );
968 }
969 // Email Address Obfuscator
970 if ( array_key_exists( 'obfuscate_email_address', $options ) && $options['obfuscate_email_address'] ) {
971 $email_address_obfuscator = new ASENHA\Classes\Email_Address_Obfuscator();
972 add_shortcode( 'obfuscate', [$email_address_obfuscator, 'obfuscate_string'] );
973 add_filter( 'safe_style_css', [$email_address_obfuscator, 'add_additional_attributes_to_safe_css'] );
974 add_filter( 'widget_text', 'shortcode_unautop' );
975 add_filter( 'widget_text', 'do_shortcode' );
976 }
977 // Disable XML-RPC
978 if ( array_key_exists( 'disable_xmlrpc', $options ) && $options['disable_xmlrpc'] ) {
979 $disable_xml_rpc = new ASENHA\Classes\Disable_XML_RPC();
980 add_filter( 'xmlrpc_enabled', '__return_false' );
981 add_action( 'wp', [$disable_xml_rpc, 'remove_xmlrpc_link'], 11 );
982 add_filter( 'xmlrpc_methods', [$disable_xml_rpc, 'remove_xmlrpc_methods'] );
983 add_filter( 'wp_xmlrpc_server_class', [$disable_xml_rpc, 'maybe_disable_xmlrpc'] );
984 // Hide xmlrpc.php in HTTP response headers
985 add_filter( 'wp_headers', [$disable_xml_rpc, 'hide_xmlrpc_in_http_response_headers'] );
986 add_filter( 'pings_open', '__return_false', PHP_INT_MAX );
987 }
988 // =================================================================
989 // OPTIMIZATIONS
990 // =================================================================
991 // Image Upload Control
992 if ( array_key_exists( 'image_upload_control', $options ) && $options['image_upload_control'] ) {
993 $image_upload_control = new ASENHA\Classes\Image_Upload_Control();
994 // Fix image rotation. Ref: https://plugins.trac.wordpress.org/browser/fix-image-rotation/tags/2.2.2/includes/class-fix-image-rotation.php
995 if ( extension_loaded( 'exif' ) && function_exists( 'exif_read_data' ) ) {
996 add_filter(
997 'wp_handle_upload_prefilter',
998 [$image_upload_control, 'prefilter_maybe_fix_image_orientation'],
999 10,
1000 1
1001 );
1002 add_filter(
1003 'wp_handle_upload',
1004 [$image_upload_control, 'maybe_fix_image_orientation'],
1005 1,
1006 3
1007 );
1008 }
1009 // Resize and convert happens here
1010 add_filter( 'wp_handle_upload', [$image_upload_control, 'image_upload_handler'] );
1011 if ( array_key_exists( 'disabled_image_sizes', $options ) && isset( $options['disabled_image_sizes'] ) ) {
1012 add_filter(
1013 'intermediate_image_sizes_advanced',
1014 [$image_upload_control, 'disable_intermediate_image_sizes__premium_only'],
1015 10,
1016 2
1017 );
1018 }
1019 }
1020 // Revisions Control
1021 if ( array_key_exists( 'enable_revisions_control', $options ) && $options['enable_revisions_control'] ) {
1022 $revisions_control = new ASENHA\Classes\Revisions_Control();
1023 add_filter(
1024 'wp_revisions_to_keep',
1025 [$revisions_control, 'limit_revisions_to_max_number'],
1026 10,
1027 2
1028 );
1029 }
1030 // Heartbeat Control
1031 if ( array_key_exists( 'enable_heartbeat_control', $options ) && $options['enable_heartbeat_control'] ) {
1032 $heartbeat_control = new ASENHA\Classes\Heartbeat_Control();
1033 add_filter(
1034 'heartbeat_settings',
1035 [$heartbeat_control, 'maybe_modify_heartbeat_frequency'],
1036 99,
1037 2
1038 );
1039 add_action( 'admin_enqueue_scripts', [$heartbeat_control, 'maybe_disable_heartbeat'], 99 );
1040 add_action( 'wp_enqueue_scripts', [$heartbeat_control, 'maybe_disable_heartbeat'], 99 );
1041 }
1042 // =================================================================
1043 // UTILITIES
1044 // =================================================================
1045 // SMTP Email Delivery
1046 if ( array_key_exists( 'smtp_email_delivery', $options ) && $options['smtp_email_delivery'] ) {
1047 $email_delivery = new ASENHA\Classes\Email_Delivery();
1048 add_action( 'phpmailer_init', [$email_delivery, 'deliver_email_via_smtp'], 99999 );
1049 add_action( 'wp_ajax_send_test_email', [$email_delivery, 'send_test_email'] );
1050 }
1051 // Multiple User Roles
1052 if ( array_key_exists( 'multiple_user_roles', $options ) && $options['multiple_user_roles'] ) {
1053 $multiple_user_roles = new ASENHA\Classes\Multiple_User_Roles();
1054 // Show roles checkboxes
1055 add_action( 'show_user_profile', [$multiple_user_roles, 'add_multiple_roles_ui'] );
1056 // for when user edits their own profile
1057 add_action( 'edit_user_profile', [$multiple_user_roles, 'add_multiple_roles_ui'] );
1058 // for when editing other user's profile
1059 add_action( 'user_new_form', [$multiple_user_roles, 'add_multiple_roles_ui'] );
1060 // new user creation
1061 // Save roles selections
1062 add_action( 'personal_options_update', [$multiple_user_roles, 'save_roles_assignment'] );
1063 // for when user edits their own profile
1064 add_action( 'edit_user_profile_update', [$multiple_user_roles, 'save_roles_assignment'] );
1065 // for when editing other user's profile
1066 add_action( 'user_register', [$multiple_user_roles, 'save_roles_assignment'] );
1067 // new user creation
1068 }
1069 // Image Sizes Panel
1070 if ( array_key_exists( 'image_sizes_panel', $options ) && $options['image_sizes_panel'] ) {
1071 $image_sizes_panel = new ASENHA\Classes\Image_Sizes_Panel();
1072 add_action( 'add_meta_boxes', array($image_sizes_panel, 'add_image_sizes_meta_box') );
1073 }
1074 // View Admin as Role
1075 if ( array_key_exists( 'view_admin_as_role', $options ) && $options['view_admin_as_role'] ) {
1076 $view_admin_as_role = new ASENHA\Classes\View_Admin_As_Role();
1077 add_action( 'admin_bar_menu', [$view_admin_as_role, 'view_admin_as_admin_bar_menu'], 8 );
1078 // Priority 8 so it is next to username section
1079 add_action( 'init', [$view_admin_as_role, 'role_switcher_to_view_admin_as'] );
1080 add_action( 'profile_update', [$view_admin_as_role, 'maybe_prevent_switchback_to_administrator'], 20 );
1081 // add_action( 'wp_die_handler', [ $view_admin_as_role, 'custom_error_page_on_switch_failure' ] );
1082 add_action( 'admin_footer', [$view_admin_as_role, 'add_floating_reset_button'] );
1083 }
1084 // Password Protection
1085 if ( array_key_exists( 'enable_password_protection', $options ) && $options['enable_password_protection'] ) {
1086 $password_protection = new ASENHA\Classes\Password_Protection();
1087 add_action( 'plugins_loaded', [$password_protection, 'show_password_protection_admin_bar_icon'] );
1088 add_action( 'init', [$password_protection, 'maybe_disable_page_caching'], 1 );
1089 add_action( 'template_redirect', [$password_protection, 'maybe_show_login_form'], 0 );
1090 // load early
1091 add_action( 'init', [$password_protection, 'maybe_process_login'], 1 );
1092 add_action( 'asenha_password_protection_error_messages', [$password_protection, 'add_login_error_messages'] );
1093 if ( function_exists( 'wp_site_icon' ) ) {
1094 // WP v4.3+
1095 add_action( 'asenha_password_protection_login_head', 'wp_site_icon' );
1096 }
1097 }
1098 // Maintenance Mode
1099 if ( array_key_exists( 'maintenance_mode', $options ) && $options['maintenance_mode'] ) {
1100 $maintenance_mode = new ASENHA\Classes\Maintenance_Mode();
1101 add_action( 'send_headers', [$maintenance_mode, 'maintenance_mode_redirect'] );
1102 add_action( 'plugins_loaded', [$maintenance_mode, 'show_maintenance_mode_admin_bar_icon'] );
1103 }
1104 // Redirect 404 to Homepage
1105 if ( array_key_exists( 'redirect_404_to_homepage', $options ) && $options['redirect_404_to_homepage'] ) {
1106 $redirect_fourofour = new ASENHA\Classes\Redirect_Fourofour();
1107 add_filter( 'template_redirect', [$redirect_fourofour, 'redirect_404'], PHP_INT_MAX );
1108 }
1109 // Display System Summary
1110 if ( array_key_exists( 'display_system_summary', $options ) && $options['display_system_summary'] ) {
1111 // require_once ASENHA_PATH . 'includes/premium/display-system-summary/ignore-directories.php';
1112 $display_system_summary = new ASENHA\Classes\Display_System_Summary();
1113 add_action( 'rightnow_end', [$display_system_summary, 'display_system_summary'] );
1114 }
1115 // Search Engines Visibility Status
1116 if ( array_key_exists( 'search_engine_visibility_status', $options ) && $options['search_engine_visibility_status'] ) {
1117 $search_engines_visibility = new ASENHA\Classes\Search_Engines_Visibility();
1118 add_action( 'admin_init', [$search_engines_visibility, 'maybe_display_search_engine_visibility_status'] );
1119 }
1120 }
1121
1122 }
1123
1124 Admin_Site_Enhancements::get_instance();