> Enable Page and Post Duplication if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) { add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] ); add_filter( 'page_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); add_filter( 'post_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); } // Content Management >> Enable Media Replacement if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) { add_filter( 'media_row_actions', [ $content_management, 'modify_media_list_table_edit_link' ], 10, 2 ); add_filter( 'attachment_fields_to_edit', [ $content_management, 'add_media_replacement_button' ] ); add_action( 'edit_attachment', [ $content_management, 'replace_media' ] ); add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] ); } // Content Management >> Enable SVG Upload 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'] ) ) { global $roles_svg_upload_enabled; $enable_svg_upload = $options['enable_svg_upload']; $for_roles = $options['enable_svg_upload_for']; // User has role(s). Do further checks. if ( isset( $for_roles ) && ( count( $for_roles ) > 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' ] ); } // Content Management >> 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' ] ); } // 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' ] ); } // 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' ] ); } } // ===== ADMIN INTERFACE ===== // Instantiate object for Admin Interface features $admin_interface = new ASENHA\Classes\Admin_Interface; // Admin Interface >> Hide Admin Notices if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { 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 } // Admin Interface >> 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' ] ); } // Admin Interface >> View Admin as Role if ( array_key_exists( 'view_admin_as_role', $options ) && $options['view_admin_as_role'] ) { add_action( 'admin_bar_menu', [ $admin_interface, 'view_admin_as_admin_bar_menu' ], 8 ); // Priority 8 so it is next to username section add_action( 'init', [ $admin_interface, 'role_switcher_to_view_admin_as' ] ); add_action( 'wp_die_handler', [ $admin_interface, 'custom_error_page_on_switch_failure' ] ); } // Admin Interface >> 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 } // Admin Interface >> Customize Admin Menu 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' ] ); add_filter( 'custom_menu_order', '__return_true' ); add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ] ); add_action( 'admin_menu', [ $admin_interface, 'apply_custom_menu_item_titles' ], 70 ); add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 80 ); add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ], 90 ); add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] ); } // ===== DISABLE COMPONENTS ====== // Instantiate object for Disable Components features $disable_components = new ASENHA\Classes\Disable_Components; // Disable Components >> Disable Gutenberg if ( array_key_exists( 'disable_gutenberg', $options ) && $options['disable_gutenberg'] ) { if ( array_key_exists( 'disable_gutenberg_for', $options ) && ! empty( $options['disable_gutenberg_for'] ) ) { add_action( 'admin_init', [ $disable_components, 'disable_gutenberg_for_post_types_admin' ] ); if ( array_key_exists( 'disable_gutenberg_frontend_styles', $options ) && $options['disable_gutenberg_frontend_styles'] ) { add_action( 'wp_enqueue_scripts', [ $disable_components, 'disable_gutenberg_for_post_types_frontend' ], 100 ); } } } // Disable Components >> Disable Comments if ( array_key_exists( 'disable_comments', $options ) && $options['disable_comments'] ) { if ( array_key_exists( 'disable_comments_for', $options ) && ! empty( $options['disable_comments_for'] ) ) { add_action( 'do_meta_boxes', [ $disable_components, 'disable_comments_for_post_types_edit' ] ); // also work with 'init', 'admin_init', 'wp_loaded' hooks add_filter( 'comments_array', [ $disable_components, 'hide_existing_comments_on_frontend' ], 10, 2 ); // hide comments add_filter( 'comments_open', [ $disable_components, 'close_commenting_on_frontend' ] ); // close commenting } } // Disable Components >> Disable REST API if ( array_key_exists( 'disable_rest_api', $options ) && $options['disable_rest_api'] ) { if ( version_compare( get_bloginfo('version'), '4.7', '>=' ) ) { add_filter( 'rest_authentication_errors', [ $disable_components, 'disable_rest_api' ] ); } else { // REST API 1.x add_filter( 'json_enabled', '__return_false' ); add_filter( 'json_jsonp_enabled', '__return_false' ); // REST API 2.x add_filter( 'rest_enabled', '__return_false' ); add_filter( 'rest_jsonp_enabled', '__return_false' ); } remove_action('wp_head', 'rest_output_link_wp_head', 10 ); // Disable REST API links in HTML remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); // Disable REST API link in HTTP headers remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' ); // Remove REST API URL from the WP RSD endpoint. } // Disable Components >> Disable Feeds if ( array_key_exists( 'disable_feeds', $options ) && $options['disable_feeds'] ) { remove_action( 'wp_head', 'feed_links', 2 ); // Remove feed links in remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove feed links in remove_action( 'do_feed_rdf', 'do_feed_rdf', 10, 0 ); remove_action( 'do_feed_rss', 'do_feed_rss', 10, 0 ); remove_action( 'do_feed_rss2', 'do_feed_rss2', 10, 1 ); remove_action( 'do_feed_atom', 'do_feed_atom', 10, 1 ); } // ===== SECURITY ===== // Instantiate object for Security features $security = new ASENHA\Classes\Security; // Security >> 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', [ $security, 'redirect_on_custom_login_url' ] ); add_action( 'login_head', [ $security, 'redirect_on_default_login_urls' ] ); add_action( 'wp_login_failed', [ $security, 'redirect_to_custom_login_url_on_login_fail' ] ); add_action( 'wp_logout', [ $security, 'redirect_to_custom_login_url_on_logout_success' ] ); } } // Security >> Limit Login Attempts if ( array_key_exists( 'limit_login_attempts', $options ) && $options['limit_login_attempts'] ) { add_filter( 'authenticate', [ $security, 'maybe_allow_login' ], 999, 3 ); // Very low priority so it is processed last add_action( 'login_enqueue_scripts', [ $security, 'maybe_hide_login_form' ] ); add_action( 'wp_login_failed', [ $security, 'log_failed_login' ], 5 ); // Higher priority than one in Change Login URL add_action( 'wp_login_errors', [ $security, 'login_error_handler' ], 999, 2 ); add_filter( 'login_message', [ $security, 'add_failed_login_message' ] ); add_action( 'wp_login', [ $security, 'clear_failed_login_log' ] ); } // Security >> Obfuscate Author Slugs if ( array_key_exists( 'obfuscate_author_slugs', $options ) && $options['obfuscate_author_slugs'] ) { add_action( 'pre_get_posts', [ $security, 'alter_author_query' ], 10 ); add_filter( 'author_link', [ $security, 'alter_author_link' ], 10, 3 ); add_filter( 'rest_prepare_user', [ $security, 'alter_json_users' ], 10, 3 ); } // Security >> Disable XML-RPC if ( array_key_exists( 'disable_xmlrpc', $options ) && $options['disable_xmlrpc'] ) { add_filter( 'xmlrpc_enabled', '__return_false' ); add_filter( 'wp_xmlrpc_server_class', [ $security, 'maybe_disable_xmlrpc' ] ); } // ===== UTILITIES ====== // Instantiate object for Utilities features $utilities = new ASENHA\Classes\Utilities; // Utilities >> 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', [ $utilities, 'redirect_for_roles_after_login' ], 5, 2 ); } } } // Utilities >> 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', [ $utilities, 'redirect_after_logout' ], 5, 1 ); // load earlier than Change Login URL add_action } } } // Utilities >> Redirect 404 to Homepage if ( array_key_exists( 'redirect_404_to_homepage', $options ) && $options['redirect_404_to_homepage'] ) { add_filter( 'wp', [ $utilities, 'redirect_404_to_homepage' ] ); } // Utilities >> Enable Custom Admin / Frontend CSS if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) { add_filter( 'admin_enqueue_scripts', [ $utilities, 'custom_admin_css' ] ); } if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) { add_filter( 'wp_enqueue_scripts', [ $utilities, 'custom_frontend_css' ] ); } } } Admin_Site_Enhancements::get_instance();