Automattic\WooCommerce\Internal\Email

DeferredEmailQueue::prepare_arg_for_queueprivateWC 1.0

Convert a queued argument to a JSON-safe value.

Method of the class: DeferredEmailQueue{}

No Hooks.

Returns

Mixed.

Usage

// private - for code of main (parent) class only
$result = $this->prepare_arg_for_queue( $arg );
$arg(mixed) (required)
The argument to convert.

DeferredEmailQueue::prepare_arg_for_queue() code WC 10.9.1

private function prepare_arg_for_queue( $arg ) {
	if ( is_array( $arg ) ) {
		foreach ( $arg as $key => $value ) {
			$arg[ $key ] = $this->prepare_arg_for_queue( $value );
		}

		return $arg;
	}

	if ( is_object( $arg ) ) {
		foreach ( $this->get_supported_object_types() as $type => $object_type ) {
			if ( ! $arg instanceof $object_type['class'] ) {
				continue;
			}

			$id = $object_type['get_id']( $arg );

			if ( empty( $id ) || ( ! is_int( $id ) && ! is_string( $id ) ) ) {
				throw new \UnexpectedValueException( 'Queued email object argument cannot be prepared.' );
			}

			return array(
				self::QUEUED_OBJECT_KEY => array(
					'type' => $type,
					'id'   => $id,
				),
			);
		}

		throw new \UnexpectedValueException( 'Queued email object argument cannot be prepared.' );
	}

	return $arg;
}