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