Title: WP_HTTP_Polling_Sync_Server::process_sync_update
Published: May 20, 2026

---

# WP_HTTP_Polling_Sync_Server::process_sync_update( string $room, int $client_id, int $cursor,  $update ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Processes a sync update based on its type.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#parameters)󠁿

 `$room`stringrequired

Room identifier.

`$client_id`intrequired

Client identifier.

`$cursor`intrequired

Client cursor (marker of last seen update).

string, type: string} $update Sync update.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) True
on success, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on storage failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#source)󠁿

    ```php
    private function process_sync_update( string $room, int $client_id, int $cursor, array $update ) {
    	$data = $update['data'];
    	$type = $update['type'];

    	switch ( $type ) {
    		case self::UPDATE_TYPE_COMPACTION:
    			/*
    			 * Compaction replaces updates the client has already seen. Only remove
    			 * updates with markers before the client's cursor to preserve updates
    			 * that arrived since the client's last sync.
    			 *
    			 * Check for a newer compaction update first. If one exists, skip this
    			 * compaction to avoid overwriting it.
    			 */
    			$updates_after_cursor = $this->storage->get_updates_after_cursor( $room, $cursor );
    			$has_newer_compaction = false;

    			foreach ( $updates_after_cursor as $existing ) {
    				if ( self::UPDATE_TYPE_COMPACTION === $existing['type'] ) {
    					$has_newer_compaction = true;
    					break;
    				}
    			}

    			if ( ! $has_newer_compaction ) {
    				if ( ! $this->storage->remove_updates_before_cursor( $room, $cursor ) ) {
    					return new WP_Error(
    						'rest_sync_storage_error',
    						__( 'Failed to remove updates during compaction.' ),
    						array( 'status' => 500 )
    					);
    				}

    				return $this->add_update( $room, $client_id, $type, $data );
    			}

    			/*
    			 * A newer compaction already advanced the cursor, but we
    			 * can not safely drop an update. The incoming bytes still encode
    			 * operations other clients may not have seen, so store them as a
    			 * regular update. Y.applyUpdateV2 merges state-as-update blobs
    			 * idempotently, so overlap with the existing compaction is safe.
    			 */
    			return $this->add_update( $room, $client_id, self::UPDATE_TYPE_UPDATE, $data );

    		case self::UPDATE_TYPE_SYNC_STEP1:
    		case self::UPDATE_TYPE_SYNC_STEP2:
    		case self::UPDATE_TYPE_UPDATE:
    			/*
    			 * Sync step 1 announces a client's state vector. Other clients need
    			 * to see it so they can respond with sync_step2 containing missing
    			 * updates. The cursor-based filtering prevents re-delivery.
    			 *
    			 * Sync step 2 contains updates for a specific client.
    			 *
    			 * All updates are stored persistently.
    			 */
    			return $this->add_update( $room, $client_id, $type, $data );
    	}

    	return new WP_Error(
    		'rest_invalid_update_type',
    		__( 'Invalid sync update type.' ),
    		array( 'status' => 400 )
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/collaboration/class-wp-http-polling-sync-server.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/collaboration/class-wp-http-polling-sync-server.php#L465)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/collaboration/class-wp-http-polling-sync-server.php#L465-L530)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTTP_Polling_Sync_Server::add_update()](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/add_update/)`wp-includes/collaboration/class-wp-http-polling-sync-server.php` |

Adds an update to a room’s update list via storage.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#)

| Used by | Description | 
| [WP_HTTP_Polling_Sync_Server::handle_request()](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/handle_request/)`wp-includes/collaboration/class-wp-http-polling-sync-server.php` |

Handles request: stores sync updates and awareness data, and returns updates the client is missing.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_http_polling_sync_server/process_sync_update/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_http_polling_sync_server%2Fprocess_sync_update%2F)
before being able to contribute a note or feedback.