value_callback = $callback; $this->escape_callback = $escape_callback; } /** * Inits, and returns, the string value of the string. * * @since 4.9.16 * * @return string The unescaped string value. */ public function __toString() { if ( null === $this->string ) { $this->string = call_user_func( $this->value_callback ); $this->resolved(); } return $this->string; } /** * Returns the HTML ready, escaped version of the string. * * @since 4.9.16 * * @return string The escaped version of the string. */ public function escaped() { if ( null !== $this->escaped ) { return $this->escaped; } $this->escaped = empty( $this->escape_callback ) ? $this->__toString() : call_user_func( $this->escape_callback, $this->__toString() ); return $this->escaped; } /** * Returns the string value, just a proxy of the `__toString` method. * * @since 4.9.16 * * @return string The string value. */ public function value() { return $this->__toString(); } /** * {@inheritDoc} * * @since 4.9.16 */ public function serialize() { $serialized = serialize( [ $this->__toString(), $this->escaped() ] ); unset( $this->value_callback, $this->escape_callback ); return $serialized; } /** * {@inheritDoc} * * @since 4.9.16 */ public function unserialize( $serialized ) { list( $string, $escaped ) = unserialize( $serialized ); $this->string = $string; $this->escaped = $escaped; } /** * {@inheritDoc} */ public function jsonSerialize() { return $this->value(); } }