> */ public static function get_presets(): array { return [ 'performance' => [ 'label' => __( 'Performance & Cleanup', 'admin-optimizer' ), 'description' => __( 'Remove WordPress bloat to speed up your frontend.', 'admin-optimizer' ), 'modules' => [ 'disable_emojis' => 1, 'disable_jquery_migrate' => 1, 'disable_404_redirect' => 1, 'remove_oembed' => 1, 'enable_heartbeat_control' => 1, 'enable_db_cleaner' => 1, ], ], 'security' => [ 'label' => __( 'Security Hardening', 'admin-optimizer' ), 'description' => __( 'Lock down your site against common WordPress attacks.', 'admin-optimizer' ), 'modules' => [ 'hide_wp_version' => 1, 'disable_xmlrpc' => 1, 'enable_custom_login_url' => 1, 'enable_block_login' => 1, 'enable_2fa' => 1, 'enable_user_access_manager' => 1, 'remove_rest_api_link' => 1, 'remove_rsd' => 1, 'remove_shortlink' => 1, 'remove_pingback_header' => 1, 'remove_powered_by_header' => 1, ], ], 'agency' => [ 'label' => __( 'Agency / Developer', 'admin-optimizer' ), 'description' => __( 'Custom content architecture, media tools, and tighter access control.', 'admin-optimizer' ), 'modules' => [ 'enable_custom_post_types' => 1, 'enable_custom_taxonomies' => 1, 'enable_custom_post_status' => 1, 'enable_svg_upload' => 1, 'enable_page_ordering' => 1, 'enable_txt_management' => 1, 'enable_custom_login_url' => 1, 'enable_xml_sitemap' => 1, 'enable_user_access_manager' => 1, 'enable_redirect_manager' => 1, 'enable_custom_code' => 1, 'enable_form_builder' => 1, ], ], 'blogger' => [ 'label' => __( 'Content Creator', 'admin-optimizer' ), 'description' => __( 'Productivity tools for writers and editorial teams managing lots of posts.', 'admin-optimizer' ), 'modules' => [ 'enable_publish_missed_posts' => 1, 'enable_post_cloner' => 1, 'manage_post_modified_date' => 1, 'enable_auto_add_anchor' => 1, ], ], 'membership' => [ 'label' => __( 'Membership / Multi-User', 'admin-optimizer' ), 'description' => __( 'Manage subscribers, editors, and client access on multi-user sites.', 'admin-optimizer' ), 'modules' => [ 'enable_2fa' => 1, 'enable_block_login' => 1, 'disable_user_account' => 1, 'enable_user_access_manager' => 1, 'enable_user_login_tracking' => 1, 'display_user_registration_date' => 1, 'disable_user_signup_notification' => 1, 'hide_update_notices' => 1, ], ], ]; } /** * Register the "Quick Setup" nav tab, prepended so it appears first. * * @param array> $nav_tab Existing tabs. * * @return array> */ public function add_settings_navtab( array $nav_tab ): array { return array_merge( [ 'presets' => [ 'title' => __( 'Quick Setup', 'admin-optimizer' ), 'slug' => 'adminoptim-presets', 'custom_render' => [ $this, 'render_presets_tab' ], ], ], $nav_tab ); } /** * Render the presets tab content. * * @return void */ public function render_presets_tab(): void { $presets = self::get_presets(); $current_opts = (array) get_option( MODULES_OPTION, [] ); $nonce = wp_create_nonce( 'adminoptim_apply_preset' ); ?>

$preset ) : ?> 0 && ! $is_fully_active ); ?>

__( 'Insufficient permissions.', 'admin-optimizer' ) ] ); } $preset_key = sanitize_key( wp_unslash( $_POST['preset'] ?? '' ) ); if ( 'reset' === $preset_key ) { update_option( MODULES_OPTION, [] ); wp_send_json_success( [ 'message' => __( 'All modules disabled. Reloading…', 'admin-optimizer' ) ] ); } $presets = self::get_presets(); if ( ! isset( $presets[ $preset_key ] ) ) { wp_send_json_error( [ 'message' => __( 'Unknown preset.', 'admin-optimizer' ) ] ); } $current = (array) get_option( MODULES_OPTION, [] ); $merged = array_merge( $current, $presets[ $preset_key ]['modules'] ); update_option( MODULES_OPTION, $merged ); wp_send_json_success( [ 'message' => sprintf( /* translators: %s: preset label */ __( '"%s" preset applied successfully. Reloading…', 'admin-optimizer' ), $presets[ $preset_key ]['label'] ), ] ); } /** * Localise the preset error strings onto the already-enqueued settings script. * * Runs on admin_enqueue_scripts so the handle is guaranteed to be registered * before we call wp_localize_script. * * @return void */ public function localize_preset_script(): void { if ( ! $this->is_settings_page() ) { return; } wp_localize_script( 'adminoptim-admin-settings', 'adminoptimPresets', [ 'errorGeneric' => __( 'Something went wrong. Please try again.', 'admin-optimizer' ), 'errorNetwork' => __( 'Request failed. Please check your connection and try again.', 'admin-optimizer' ), ] ); } /** * Returns a human-readable label for a module option key. * * @param string $key Module option key. * * @return string */ private static function get_module_label( string $key ): string { $labels = [ 'disable_emojis' => __( 'Disable Emojis', 'admin-optimizer' ), 'disable_jquery_migrate' => __( 'Disable jQuery Migrate', 'admin-optimizer' ), 'remove_rest_api_link' => __( 'Remove REST API Link', 'admin-optimizer' ), 'remove_rsd' => __( 'Remove RSD Link', 'admin-optimizer' ), 'remove_shortlink' => __( 'Remove Shortlink', 'admin-optimizer' ), 'remove_oembed' => __( 'Remove oEmbed', 'admin-optimizer' ), 'remove_pingback_header' => __( 'Remove Pingback Header', 'admin-optimizer' ), 'remove_powered_by_header' => __( 'Remove Powered-By Header', 'admin-optimizer' ), 'enable_heartbeat_control' => __( 'Heartbeat Control', 'admin-optimizer' ), 'enable_db_cleaner' => __( 'Database Cleaner', 'admin-optimizer' ), 'hide_wp_version' => __( 'Hide WP Version', 'admin-optimizer' ), 'hide_update_notices' => __( 'Hide Update Notices', 'admin-optimizer' ), 'disable_xmlrpc' => __( 'Disable XML-RPC', 'admin-optimizer' ), 'enable_custom_login_url' => __( 'Custom Login URL', 'admin-optimizer' ), 'enable_block_login' => __( 'Block Failed Login', 'admin-optimizer' ), 'enable_2fa' => __( 'Two Factor Authentication (2FA)', 'admin-optimizer' ), 'enable_user_access_manager' => __( 'User Access Manager', 'admin-optimizer' ), 'enable_custom_post_types' => __( 'Custom Post Types', 'admin-optimizer' ), 'enable_custom_taxonomies' => __( 'Custom Taxonomies', 'admin-optimizer' ), 'enable_custom_post_status' => __( 'Custom Post Status', 'admin-optimizer' ), 'enable_svg_upload' => __( 'SVG Upload', 'admin-optimizer' ), 'enable_page_ordering' => __( 'Page Ordering', 'admin-optimizer' ), 'enable_txt_management' => __( 'Robots / Ads / App-Ads Txt', 'admin-optimizer' ), 'enable_publish_missed_posts' => __( 'Auto Publish Posts', 'admin-optimizer' ), 'enable_post_cloner' => __( 'Post Cloning', 'admin-optimizer' ), 'manage_post_modified_date' => __( 'Lock Post Modified Date', 'admin-optimizer' ), 'enable_auto_add_anchor' => __( 'Auto Add HTML Anchor', 'admin-optimizer' ), 'disable_404_redirect' => __( 'Disable 404 URL Redirect', 'admin-optimizer' ), 'enable_image_alt_text' => __( 'Set Image Filename as Alt Text', 'admin-optimizer' ), 'enable_image_underscore_to_hyphen' => __( 'Convert Underscore to Hyphen in Filenames', 'admin-optimizer' ), 'enable_limit_image_upload_size' => __( 'Limit Image Upload File Size', 'admin-optimizer' ), 'disable_category_archive' => __( 'Disable Category Archive Page', 'admin-optimizer' ), 'disable_tag_archive' => __( 'Disable Tag Archive Page', 'admin-optimizer' ), 'disable_author_archive' => __( 'Disable Author Archive Page', 'admin-optimizer' ), 'disable_date_archive' => __( 'Disable Date Archive Page', 'admin-optimizer' ), 'disable_gutenberg_editor' => __( 'Disable Gutenberg Editor', 'admin-optimizer' ), 'enable_smtp_mail' => __( 'SMTP Mail', 'admin-optimizer' ), 'enable_user_login_tracking' => __( 'Track User Last Login', 'admin-optimizer' ), 'display_user_registration_date' => __( 'Display User Registration Date', 'admin-optimizer' ), 'disable_user_account' => __( 'Disable User Account', 'admin-optimizer' ), 'disable_user_signup_notification' => __( 'Disable New User Notification', 'admin-optimizer' ), 'enable_redirect_manager' => __( 'Redirect Manager', 'admin-optimizer' ), 'enable_custom_code' => __( 'Custom Code Snippets', 'admin-optimizer' ), 'enable_form_builder' => __( 'Form Builder', 'admin-optimizer' ), ]; return $labels[ $key ] ?? ucwords( str_replace( '_', ' ', $key ) ); } /** * Whether the current admin page is the plugin's settings page. * * @return bool */ private function is_settings_page(): bool { $screen = get_current_screen(); return $screen && 'toplevel_page_' . ADMINOPTIMIZER_MODULES_MENU_SLUG === $screen->id; } }