id, 'mapfield-spots-settings' ) === false ) {
return;
}
global $wp_settings_errors;
get_settings_errors(); // merges the transient into $wp_settings_errors and deletes it.
$wp_settings_errors = array();
}
/**
* Styled toast (.mapfield_spots-toast, admin.css) replacing WP's own
* "Settings saved." banner — this page renders its own template, so
* nothing shows a confirmation without this. Covers both the settings
* save and the "Restore default settings" redirect.
*/
public function maybe_render_saved_toast(): void {
$screen = get_current_screen();
if ( ! $screen || strpos( $screen->id, 'mapfield-spots-settings' ) === false ) {
return;
}
// Read-only UI flags from an already-nonce-verified redirect, not form data.
// Checked independently (not elseif) so both can show at once.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['mapfield_spots_reset'] ) ) {
?>
get_option( self::OPTION_TOKEN, '' ),
// streets-v9 and other classic styles are retired; v12 is the current equivalent.
'style_url' => get_option( self::OPTION_STYLE, 'mapbox://styles/mapbox/streets-v12' ),
);
}
/** Mapbox's core styles, all same pricing. Shared by Settings and each Map Type's picker. */
public static function style_presets(): array {
return array(
'mapbox://styles/mapbox/streets-v12' => __( 'Streets', 'mapfield-spots' ),
'mapbox://styles/mapbox/outdoors-v12' => __( 'Outdoors', 'mapfield-spots' ),
'mapbox://styles/mapbox/light-v11' => __( 'Light', 'mapfield-spots' ),
'mapbox://styles/mapbox/dark-v11' => __( 'Dark', 'mapfield-spots' ),
'mapbox://styles/mapbox/satellite-streets-v12' => __( 'Satellite Streets', 'mapfield-spots' ),
'mapbox://styles/mapbox/satellite-v9' => __( 'Satellite', 'mapfield-spots' ),
'mapbox://styles/mapbox/navigation-day-v1' => __( 'Navigation Day', 'mapfield-spots' ),
'mapbox://styles/mapbox/navigation-night-v1' => __( 'Navigation Night', 'mapfield-spots' ),
);
}
/**
* Grid of clickable style cards (live MapLibre previews, style-picker.js)
* bound to a text input. Only used for a Map Type's own style field now —
* a former site-wide default picker was removed as confusing (two
* overlapping controls).
*
* @param string $placeholder In practice never shown; every Map Type resolves to a real style URL.
*/
public static function render_style_picker( string $input_id, string $current_value, string $placeholder = '' ): void {
$presets = self::style_presets();
$is_custom = '' === $current_value || ! isset( $presets[ $current_value ] );
?>