0 ) {
// Assemble single-dimensional array of roles for which SVG upload would be enabled
$roles_svg_upload_enabled = array();
foreach ( $for_roles as $role_slug => $svg_upload_enabled ) {
if ( $svg_upload_enabled ) {
$roles_svg_upload_enabled[] = $role_slug;
}
}
}
add_filter( 'upload_mimes', [ $content_management, 'add_svg_mime' ] );
add_filter(
'wp_check_filetype_and_ext',
[ $content_management, 'confirm_file_type_is_svg' ],
10,
4
);
add_filter( 'wp_handle_upload_prefilter', [ $content_management, 'sanitize_and_maybe_allow_svg_upload' ] );
add_filter(
'wp_generate_attachment_metadata',
[ $content_management, 'generate_svg_metadata' ],
10,
3
);
add_action( 'wp_ajax_svg_get_attachment_url', [ $content_management, 'get_svg_attachment_url' ] );
add_filter( 'wp_prepare_attachment_for_js', [ $content_management, 'get_svg_url_in_media_library' ] );
}
// Enable External Permalinks
if ( array_key_exists( 'enable_external_permalinks', $options ) && $options['enable_external_permalinks'] ) {
if ( array_key_exists( 'enable_external_permalinks_for', $options ) && !empty($options['enable_external_permalinks_for']) ) {
add_action(
'add_meta_boxes',
[ $content_management, 'add_external_permalink_meta_box' ],
10,
2
);
add_action( 'save_post', [ $content_management, 'save_external_permalink' ] );
// Filter the permalink for use by get_permalink()
add_filter(
'page_link',
[ $content_management, 'use_external_permalink_for_pages' ],
20,
2
);
add_filter(
'post_link',
[ $content_management, 'use_external_permalink_for_posts' ],
20,
2
);
add_filter(
'post_type_link',
[ $content_management, 'use_external_permalink_for_posts' ],
20,
2
);
// Enable redirection to external permalink when page/post is opened directly via it's WP permalink
add_action( 'wp', [ $content_management, 'redirect_to_external_permalink' ] );
}
}
// Open All External Links in New Tab
if ( array_key_exists( 'external_links_new_tab', $options ) && $options['external_links_new_tab'] ) {
add_filter( 'the_content', [ $content_management, 'add_target_and_rel_atts_to_content_links' ] );
}
// Enable Auto-Publishing of Posts with Missed Schedules
if ( array_key_exists( 'enable_missed_schedule_posts_auto_publish', $options ) && $options['enable_missed_schedule_posts_auto_publish'] ) {
add_action( 'wp_head', [ $content_management, 'publish_missed_schedule_posts' ] );
add_action( 'admin_head', [ $content_management, 'publish_missed_schedule_posts' ] );
}
// Enhance List Tables
if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) {
// Show Featured Image Column
if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) {
add_action( 'admin_init', [ $content_management, 'show_featured_image_column' ] );
}
// Show Excerpt Column
if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) {
add_action( 'admin_init', [ $content_management, 'show_excerpt_column' ] );
}
// Show ID Column
if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) {
add_action( 'admin_init', [ $content_management, 'show_id_column' ] );
}
// Show ID in Action Row
if ( array_key_exists( 'show_id_in_action_row', $options ) && $options['show_id_in_action_row'] ) {
add_action( 'admin_init', [ $content_management, 'show_id_in_action_row' ] );
}
// Show Custom Taxonomy Filters
if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) {
add_action( 'restrict_manage_posts', [ $content_management, 'show_custom_taxonomy_filters' ] );
}
// Hide Comments Column
if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) {
add_action( 'admin_init', [ $content_management, 'hide_comments_column' ] );
}
// Hide Post Tags Column
if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) {
add_action( 'admin_init', [ $content_management, 'hide_post_tags_column' ] );
}
}
// =================================================================
// ADMIN INTERFACE
// =================================================================
// Instantiate object for Admin Interface features
$admin_interface = new ASENHA\Classes\Admin_Interface();
// Hide Admin Notices
if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
add_action( 'admin_notices', [ $admin_interface, 'admin_notices_wrapper' ], 9 );
// add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] );
add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] );
add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] );
// wp-admin
}
// Hide Admin Bar
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'] ) ) {
add_filter( 'show_admin_bar', [ $admin_interface, 'hide_admin_bar_for_roles' ] );
}
// Disable Dashboard Widgets
if ( array_key_exists( 'disable_dashboard_widgets', $options ) && $options['disable_dashboard_widgets'] ) {
add_action( 'wp_dashboard_setup', [ $admin_interface, 'disable_dashboard_widgets' ], 99 );
}
// Hide or Modify Elements
if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) {
add_filter( 'admin_bar_menu', [ $admin_interface, 'modify_admin_bar_menu' ], 5 );
// priority 5 to execute earlier than the normal 10
if ( array_key_exists( 'hide_help_drawer', $options ) && $options['hide_help_drawer'] ) {
add_action( 'admin_head', [ $admin_interface, 'hide_help_drawer' ] );
}
}
// Wider Admin Menu
if ( array_key_exists( 'wider_admin_menu', $options ) && $options['wider_admin_menu'] ) {
add_action( 'admin_head', [ $admin_interface, 'set_custom_menu_width' ], 99 );
}
// Admin Menu Organizer
if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) {
// add_action( 'wp_ajax_save_custom_menu_order', [ $admin_interface, 'save_custom_menu_order' ] );
// add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_interface, 'save_hidden_menu_items' ] );
if ( array_key_exists( 'custom_menu_order', $options ) ) {
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ] );
}
if ( array_key_exists( 'custom_menu_titles', $options ) ) {
add_action( 'admin_menu', [ $admin_interface, 'apply_custom_menu_item_titles' ], 1000 );
}
if ( array_key_exists( 'custom_menu_hidden', $options ) || array_key_exists( 'custom_menu_always_hidden', $options ) ) {
add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 1001 );
add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ], 1002 );
add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] );
}
}
// =================================================================
// LOG IN | LOG OUT
// =================================================================
// Instantiate object for Log In Log Out features
$login_logout = new ASENHA\Classes\Login_Logout();
// Change Login URL
if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
if ( array_key_exists( 'custom_login_slug', $options ) && !empty($options['custom_login_slug']) ) {
add_action( 'init', [ $login_logout, 'redirect_on_custom_login_url' ] );
add_action( 'login_head', [ $login_logout, 'redirect_on_default_login_urls' ] );
add_action( 'wp_login_failed', [ $login_logout, 'redirect_to_custom_login_url_on_login_fail' ] );
add_action( 'wp_logout', [ $login_logout, 'redirect_to_custom_login_url_on_logout_success' ] );
}
}
// Enable Login Logout Menu
if ( array_key_exists( 'enable_login_logout_menu', $options ) && $options['enable_login_logout_menu'] ) {
add_action( 'admin_head-nav-menus.php', [ $login_logout, 'add_login_logout_metabox' ] );
add_filter( 'wp_setup_nav_menu_item', [ $login_logout, 'set_login_logout_menu_item_dynamic_url' ] );
add_filter( 'wp_nav_menu_objects', [ $login_logout, 'maybe_remove_login_or_logout_menu_item' ] );
}
// Enable Last Login Column
if ( array_key_exists( 'enable_last_login_column', $options ) && $options['enable_last_login_column'] ) {
add_action( 'wp_login', [ $login_logout, 'log_login_datetime' ] );
add_filter( 'manage_users_columns', [ $login_logout, 'add_last_login_column' ] );
add_filter(
'manage_users_custom_column',
[ $login_logout, 'show_last_login_info' ],
10,
3
);
add_action( 'admin_print_styles-users.php', [ $login_logout, 'add_column_style' ] );
}
// Redirect After Login
if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) {
if ( array_key_exists( 'redirect_after_login_to_slug', $options ) && !empty($options['redirect_after_login_to_slug']) ) {
if ( array_key_exists( 'redirect_after_login_for', $options ) && !empty($options['redirect_after_login_for']) ) {
add_filter(
'wp_login',
[ $login_logout, 'redirect_for_roles_after_login' ],
5,
2
);
}
}
}
// Redirect After Logout
if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) {
if ( array_key_exists( 'redirect_after_logout_to_slug', $options ) && !empty($options['redirect_after_logout_to_slug']) ) {
if ( array_key_exists( 'redirect_after_logout_for', $options ) && !empty($options['redirect_after_logout_for']) ) {
add_action(
'wp_logout',
[ $login_logout, 'redirect_after_logout' ],
5,
1
);
// load earlier than Change Login URL add_action
}
}
}
// =================================================================
// CUSTOM CODE
// =================================================================
// Instantiate object for Custom Code features
$custom_code = new ASENHA\Classes\Custom_Code();
// Enable Custom Admin / Frontend CSS
if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) {
add_filter( 'admin_enqueue_scripts', [ $custom_code, 'custom_admin_css' ] );
}
if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
add_filter( 'wp_enqueue_scripts', [ $custom_code, 'custom_frontend_css' ] );
}
// Custom Body Class
if ( array_key_exists( 'enable_custom_body_class', $options ) && $options['enable_custom_body_class'] ) {
if ( array_key_exists( 'enable_custom_body_class_for', $options ) && !empty($options['enable_custom_body_class_for']) ) {
add_action(
'add_meta_boxes',
[ $custom_code, 'add_custom_body_class_meta_box' ],
10,
2
);
add_action( 'save_post', [ $custom_code, 'save_custom_body_class' ], 99 );
add_filter( 'body_class', [ $custom_code, 'append_custom_body_class' ], 99 );
}
}
// Manage ads.txt and app-ads.txt
if ( array_key_exists( 'manage_ads_appads_txt', $options ) && $options['manage_ads_appads_txt'] ) {
add_action( 'init', [ $custom_code, 'show_ads_appads_txt_content' ] );
}
// Manage robots.txt
if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) {
add_filter(
'robots_txt',
[ $custom_code, 'maybe_show_custom_robots_txt_content' ],
10,
2
);
}
// Insert
, and