|false The new entry { time, reason, version, options }, or false when it could not be stored. */ public static function create( $reason ) { $reason = preg_replace( '/[^a-z0-9._-]/', '', strtolower( (string) $reason ) ); if ( '' === $reason ) { $reason = 'manual'; } $options = Settings::stored_options(); foreach ( self::OPTIONS as $name ) { $value = get_option( $name, null ); if ( null !== $value ) { $options[ $name ] = $value; } } $entry = [ 'time' => Clock::now(), 'reason' => $reason, 'version' => FORMWRIGHT_VERSION, 'options' => $options, ]; $ring = self::all(); $ring[] = $entry; $ring = array_slice( $ring, -self::KEEP ); // update_option() reports false for "no change", which is what a full ring of identical entries gives; check the stored copy. if ( ! update_option( self::OPTION, $ring, false ) && get_option( self::OPTION ) !== $ring ) { return false; } return $entry; } /** * Every stored backup, oldest first (newest last). Malformed entries are skipped. * * @return array> */ public static function all() { $stored = get_option( self::OPTION, [] ); if ( ! is_array( $stored ) ) { return []; } $found = []; foreach ( $stored as $entry ) { if ( is_array( $entry ) && isset( $entry['time'], $entry['reason'], $entry['version'], $entry['options'] ) && is_array( $entry['options'] ) ) { $found[] = $entry; } } return $found; } }