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