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