WP_HTTP_Polling_Sync_Server::register_routes()

In this article

Registers REST API routes.

Source

public function register_routes(): void {
	$typed_update_args = array(
		'properties' => array(
			'data' => array(
				'type'      => 'string',
				'required'  => true,
				'maxLength' => self::MAX_UPDATE_DATA_SIZE,
			),
			'type' => array(
				'type'     => 'string',
				'required' => true,
				'enum'     => array(
					self::UPDATE_TYPE_COMPACTION,
					self::UPDATE_TYPE_SYNC_STEP1,
					self::UPDATE_TYPE_SYNC_STEP2,
					self::UPDATE_TYPE_UPDATE,
				),
			),
		),
		'required'   => true,
		'type'       => 'object',
	);

	$room_args = array(
		'after'     => array(
			'minimum'  => 0,
			'required' => true,
			'type'     => 'integer',
		),
		'awareness' => array(
			'required' => true,
			'type'     => array( 'object', 'null' ),
		),
		'client_id' => array(
			'minimum'  => 1,
			'required' => true,
			'type'     => 'integer',
		),
		'room'      => array(
			'required' => true,
			'type'     => 'string',
			'pattern'  => '^[^/]+/[^/:]+(?::\\S+)?$',
		),
		'updates'   => array(
			'items'    => $typed_update_args,
			'minItems' => 0,
			'required' => true,
			'type'     => 'array',
		),
	);

	register_rest_route(
		self::REST_NAMESPACE,
		'/updates',
		array(
			'methods'             => array( WP_REST_Server::CREATABLE ),
			'callback'            => array( $this, 'handle_request' ),
			'permission_callback' => array( $this, 'check_permissions' ),
			'validate_callback'   => array( $this, 'validate_request' ),
			'args'                => array(
				'rooms' => array(
					'items'    => array(
						'properties' => $room_args,
						'type'       => 'object',
					),
					'maxItems' => self::MAX_ROOMS_PER_REQUEST,
					'required' => true,
					'type'     => 'array',
				),
			),
		)
	);
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.