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