true, // keep a log of addresses that end in "not found" 'log404Days' => 30, // forget 404s not seen for this many days 'slugWatch' => true, // a post's address changes: redirect the old one 'keepQuery' => true, // carry the query string to the target 'countHits' => true, // count how often each redirect is used 'fallback404' => 'none', // none | home | url 'fallback404Url' => '', 'fallback404Code' => 302, ); } public static function all(): array { $stored = get_option( self::OPTION, array() ); return array_merge( self::defaults(), is_array( $stored ) ? $stored : array() ); } public static function get( string $key ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : null; } /** @return array the values as stored */ public static function save( array $in ): array { $out = self::all(); foreach ( self::defaults() as $key => $default ) { if ( ! array_key_exists( $key, $in ) ) { continue; } $value = $in[ $key ]; switch ( $key ) { case 'log404Days': $out[ $key ] = max( 1, min( 365, (int) $value ) ); break; case 'fallback404': $out[ $key ] = in_array( $value, array( 'none', 'home', 'url' ), true ) ? $value : 'none'; break; case 'fallback404Url': $value = trim( (string) $value ); $out[ $key ] = $value === '' || preg_match( '#^(/|https?://)#i', $value ) ? esc_url_raw( $value ) : ''; break; case 'fallback404Code': $out[ $key ] = in_array( (int) $value, array( 301, 302, 307 ), true ) ? (int) $value : 302; break; default: $out[ $key ] = rest_sanitize_boolean( $value ); } } update_option( self::OPTION, $out ); return $out; } }