'array', 'sanitize_callback' => array( self::class, 'sanitize' ), 'default' => Fontdelbosc_Combustible_Data_Manager::defaults(), 'show_in_rest' => false, ) ); } /** * Sanitizes the settings form. * * @param mixed $input Raw input. * @return array */ public static function sanitize( mixed $input ): array { $input = is_array( $input ) ? $input : array(); $fuels = array(); foreach ( Fontdelbosc_Combustible_Payload::arr( Fontdelbosc_Combustible_Payload::get( $input, 'fuel_types' ) ) as $id ) { $id = Fontdelbosc_Combustible_Payload::int( $id ); if ( null !== $id && $id > 0 ) { $fuels[] = $id; } } return array( 'search_radius_km' => max( 5, min( 50, Fontdelbosc_Combustible_Payload::int( Fontdelbosc_Combustible_Payload::get( $input, 'search_radius_km' ) ) ?? 15 ) ), 'max_stations' => max( 5, min( 20, Fontdelbosc_Combustible_Payload::int( Fontdelbosc_Combustible_Payload::get( $input, 'max_stations' ) ) ?? 10 ) ), 'fuel_types' => array() === $fuels ? Fontdelbosc_Combustible_Fuels::DEFAULT_IDS : array_values( array_unique( $fuels ) ), 'show_only_public' => ! empty( Fontdelbosc_Combustible_Payload::get( $input, 'show_only_public' ) ), 'cache_ttl' => max( 600, min( 86400, Fontdelbosc_Combustible_Payload::int( Fontdelbosc_Combustible_Payload::get( $input, 'cache_ttl' ) ) ?? 3600 ) ), 'show_distance' => ! empty( Fontdelbosc_Combustible_Payload::get( $input, 'show_distance' ) ), 'show_schedule' => ! empty( Fontdelbosc_Combustible_Payload::get( $input, 'show_schedule' ) ), 'sort_by' => ( Fontdelbosc_Combustible_Payload::str( Fontdelbosc_Combustible_Payload::get( $input, 'sort_by' ) ) === 'price_asc' ) ? 'price_asc' : 'distance', 'delete_data_on_uninstall' => ! empty( Fontdelbosc_Combustible_Payload::get( $input, 'delete_data_on_uninstall' ) ), ); } /** * Renders the settings page. */ public static function render_page(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } require FONTDELBOSC_COMBUSTIBLE_DIR . 'admin/views/settings-page.php'; } /** * Handles the flush-cache button. */ public static function handle_flush(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'fontdelbosc-combustible' ) ); } check_admin_referer( 'fontdelbosc_combustible_flush_cache' ); Fontdelbosc_Combustible_Data_Manager::flush_cache(); Fontdelbosc_Combustible_Data_Manager::get_payload( true ); wp_safe_redirect( add_query_arg( array( 'page' => 'fontdelbosc-combustible', 'fontdelbosc_flushed' => 1, ), admin_url( 'options-general.php' ) ) ); exit; } }