option_name, array( $this, 'sanitize_settings' ) ); } /** * Rigorously sanitize all inputs before saving to the database. * Zero tolerance for unvalidated data. * * @param array $input The raw data submitted by the admin. * @return array The mathematically clean, sanitized data. */ public function sanitize_settings( $input ) { $sanitized = array(); // 1. Sanitize Logo URL (Must be a valid URL) if ( isset( $input['logo_url'] ) ) { $sanitized['logo_url'] = esc_url_raw( trim( $input['logo_url'] ) ); } // 2. Sanitize Background Color (Must be a valid Hex) if ( isset( $input['bg_color'] ) ) { $sanitized['bg_color'] = sanitize_hex_color( $input['bg_color'] ); } // 3. Sanitize Button Color (Must be a valid Hex) if ( isset( $input['btn_color'] ) ) { $sanitized['btn_color'] = sanitize_hex_color( $input['btn_color'] ); } // 4. Sanitize Custom Login Slug (Must be a valid slug format: no spaces, lowercase) if ( isset( $input['custom_login_slug'] ) ) { // Strip out any slashes or full URLs if the user accidentally pasted one. $slug = sanitize_text_field( wp_unslash( $input['custom_login_slug'] ) ); $slug = sanitize_title( $slug ); // Prevent the admin from locking themselves out by using reserved WordPress slugs $reserved_slugs = array( 'wp-admin', 'wp-login.php', 'dashboard', 'admin' ); if ( in_array( $slug, $reserved_slugs, true ) ) { add_settings_error( $this->option_name, 'invalid_slug', __( 'You cannot use reserved WordPress terms for your custom login slug.', '24tt-login-security-and-brander' ) ); $slug = ''; // Reset to default if illegal } $sanitized['custom_login_slug'] = $slug; } // 5. Sanitize Client Redirect URL (Must be a valid URL) if ( isset( $input['client_redirect_url'] ) ) { $sanitized['client_redirect_url'] = esc_url_raw( trim( $input['client_redirect_url'] ) ); } return $sanitized; } /** * Enqueue specific CSS/JS only on our settings page to prevent backend bloat. * * @param string $hook The current admin page hook. */ public function enqueue_admin_assets( $hook ) { // Only load our scripts on our specific settings page. if ( 'settings_page_24tt-security-brander' !== $hook ) { return; } // Enqueue native WordPress color picker and media uploader wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_media(); // Enqueue our custom admin styling and scripts wp_enqueue_style( 'tt24-admin-css', TT24_PLUGIN_URL . 'admin/css/tt24-admin.css', array(), TT24_VERSION, 'all' ); wp_enqueue_script( 'tt24-admin-js', TT24_PLUGIN_URL . 'admin/js/tt24-admin.js', array( 'jquery', 'wp-color-picker' ), TT24_VERSION, true ); } /** * Render the settings page HTML by requiring the view partial. */ public function display_plugin_setup_page() { // Fetch existing options to populate the form fields $options = get_option( $this->option_name, array() ); require_once TT24_PLUGIN_DIR . 'admin/partials/tt24-settings-display.php'; } }