' . esc_html__( 'Settings saved.', 'aftercare' ) . '
'; } echo ''; Menu::footer(); } public static function handle_save(): void { if ( ! current_user_can( Menu::CAP ) ) { wp_die( esc_html__( 'You do not have permission to do that.', 'aftercare' ) ); } check_admin_referer( 'aftercare_save_settings' ); // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- each field sanitized below. $urls = array(); foreach ( preg_split( '/\r\n|\r|\n/', (string) wp_unslash( $_POST['tracked_urls'] ?? '' ) ) as $line ) { $url = esc_url_raw( trim( $line ) ); if ( '' !== $url ) { $urls[] = $url; } } $budgets_in = (array) wp_unslash( $_POST['budgets'] ?? array() ); $budgets = array(); foreach ( array_keys( Options::defaults()['budgets'] ) as $metric ) { $budgets[ $metric ] = max( 0, (float) ( $budgets_in[ $metric ] ?? Options::defaults()['budgets'][ $metric ] ) ); } $new = array( 'api_key' => sanitize_text_field( wp_unslash( $_POST['api_key'] ?? '' ) ), 'tracked_urls' => $urls, 'budgets' => $budgets, 'rum_enabled' => ! empty( $_POST['rum_enabled'] ), 'lab_enabled' => ! empty( $_POST['lab_enabled'] ), 'error_watch' => ! empty( $_POST['error_watch'] ), 'availability_watch' => ! empty( $_POST['availability_watch'] ), 'rum_sample_rate' => isset( $_POST['rum_sample_rate'] ) ? max( 1, min( 100, absint( wp_unslash( $_POST['rum_sample_rate'] ) ) ) ) : 10, 'alert_email' => sanitize_email( wp_unslash( $_POST['alert_email'] ?? '' ) ), 'weekly_digest' => ! empty( $_POST['weekly_digest'] ), 'keep_data_on_uninstall' => ! empty( $_POST['keep_data_on_uninstall'] ), ); // Only write add-on settings that were actually rendered, so a stored // value is never silently cleared by a form that did not contain it. if ( class_exists( Slack::class ) && class_exists( Webhook::class ) ) { $new['slack_webhook'] = esc_url_raw( wp_unslash( $_POST['slack_webhook'] ?? '' ) ); $new['webhook_url'] = esc_url_raw( wp_unslash( $_POST['webhook_url'] ?? '' ) ); } if ( class_exists( ReportBuilder::class ) ) { $branding_in = (array) wp_unslash( $_POST['branding'] ?? array() ); $accent = sanitize_hex_color( (string) ( $branding_in['accent'] ?? '' ) ); $new['client_recipients'] = sanitize_text_field( wp_unslash( $_POST['client_recipients'] ?? '' ) ); $new['branding'] = array( 'logo_url' => esc_url_raw( (string) ( $branding_in['logo_url'] ?? '' ) ), 'accent' => $accent ? $accent : '#0f766e', 'footer_text' => sanitize_text_field( (string) ( $branding_in['footer_text'] ?? '' ) ), 'sender_name' => sanitize_text_field( (string) ( $branding_in['sender_name'] ?? '' ) ), 'reply_to' => sanitize_email( (string) ( $branding_in['reply_to'] ?? '' ) ), ); } // phpcs:enable Options::update( $new ); wp_safe_redirect( admin_url( 'admin.php?page=aftercare-settings&updated=1' ) ); exit; } }