html = $html; } /** * Gets the trusted HTML of a value. * * @since 7.2.0 * * @param mixed $value Any value. * @return string|null The HTML of the token if the value is a token whose constructor * ran, or `null` for any other value. */ public static function get_html( $value ): ?string { return $value instanceof self ? $value->html : null; } /** * Makes a token restored by unserialization inert. * * Clears the HTML, so the token never renders, and reports the unserialization * instead of throwing, so a page that cached a token keeps working. * * @since 7.2.0 */ public function __wakeup(): void { $this->html = null; _doing_it_wrong( __METHOD__, __( 'A token that marks HTML as trusted should not be unserialized. The unserialized token holds no HTML and does not render.' ), '7.2.0' ); } /** * Gets the value that JSON encoding prints in place of the token. * * It is the same for every token and holds none of its HTML. * * @since 7.2.0 * * @return array The marker: a single `wpServerHtml` entry set to `true`, * which `json_encode()` prints as `{"wpServerHtml":true}`. */ public function jsonSerialize(): array { return array( 'wpServerHtml' => true ); } /** * Gets the iterator that `foreach` and the fallback of `wp_json_encode()` read. * * It yields the same single entry as {@see WP_Interactivity_Dangerous_HTML::jsonSerialize()} * and none of the token's HTML. * * @since 7.2.0 * * @return Traversable An iterator yielding `wpServerHtml` => `true`, once. */ public function getIterator(): Traversable { return new ArrayIterator( $this->jsonSerialize() ); } }