*/ public static function defaults() { return array( 'slice_seconds' => 0, // 0 = automatic (20 s local, 15 s elsewhere, below max_execution_time). 'remote_ms' => 8000, // Time a source may spend building one response. 'remote_bytes' => 8388608, // Target bytes per response (8 MB). 'stmt_bytes' => 1048576, // Max bytes per INSERT statement (1 MB). 'small_file' => 4194304, // Files up to this size are sent in batches. 'range_bytes' => 8388608, // Big files are read in ranges of this size. 'extra_excludes' => '', // One pattern per line, relative to wp-content. 'include_transients' => false, 'keep_sets' => 5, // Pull sets kept per source (0 = keep all). ); } /** * All settings merged with defaults. * * @return array */ public static function all() { $saved = get_option( self::OPTION, array() ); return array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); } /** * One setting. * * @param string $key Key. * @return mixed */ public static function get( $key ) { $all = self::all(); return isset( $all[ $key ] ) ? $all[ $key ] : null; } /** * Saves sanitised settings. * * @param array $input Raw values. */ public static function save( array $input ) { $current = self::all(); $clean = array( 'slice_seconds' => isset( $input['slice_seconds'] ) ? max( 0, min( 240, (int) $input['slice_seconds'] ) ) : $current['slice_seconds'], 'remote_ms' => isset( $input['remote_ms'] ) ? max( 2000, min( 60000, (int) $input['remote_ms'] ) ) : $current['remote_ms'], 'remote_bytes' => isset( $input['remote_bytes'] ) ? max( 1048576, min( 33554432, (int) $input['remote_bytes'] ) ) : $current['remote_bytes'], 'stmt_bytes' => isset( $input['stmt_bytes'] ) ? max( 262144, min( 4194304, (int) $input['stmt_bytes'] ) ) : $current['stmt_bytes'], 'small_file' => $current['small_file'], 'range_bytes' => $current['range_bytes'], 'extra_excludes' => isset( $input['extra_excludes'] ) ? sanitize_textarea_field( (string) $input['extra_excludes'] ) : $current['extra_excludes'], 'include_transients' => ! empty( $input['include_transients'] ), 'keep_sets' => isset( $input['keep_sets'] ) ? max( 0, min( 100, (int) $input['keep_sets'] ) ) : $current['keep_sets'], ); update_option( self::OPTION, $clean, false ); } }