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