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