Automattic\WooCommerce\Internal\Email

DeferredEmailQueue::restore_arg_from_queue │ private │ WC 1.0

Restore a queued argument after Action Scheduler storage.

Метод класса: DeferredEmailQueue{}

Хуков нет.

Возвращает

mixed.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->restore_arg_from_queue( $arg );
$arg(разное) (обязательный)
The argument to restore.

Код DeferredEmailQueue::restore_arg_from_queue() WC 11.2.2

private function restore_arg_from_queue( $arg ) {
	if ( ! is_array( $arg ) ) {
		return $arg;
	}

	if ( ! array_key_exists( self::QUEUED_OBJECT_KEY, $arg ) ) {
		foreach ( $arg as $key => $value ) {
			$arg[ $key ] = $this->restore_arg_from_queue( $value );
		}

		return $arg;
	}

	$reference = $arg[ self::QUEUED_OBJECT_KEY ];

	if ( ! is_array( $reference ) || ! isset( $reference['type'], $reference['id'] ) ) {
		throw new \UnexpectedValueException( 'Queued email object reference is invalid.' );
	}

	$id = $reference['id'];

	if ( ! is_int( $id ) && ! is_string( $id ) ) {
		throw new \UnexpectedValueException( 'Queued email object reference is invalid.' );
	}

	$object_type = $this->get_supported_object_types()[ (string) $reference['type'] ] ?? null;

	if ( ! is_array( $object_type ) ) {
		throw new \UnexpectedValueException( 'Queued email object reference is invalid.' );
	}

	$object = $object_type['fetch']( $id );

	if ( ! is_object( $object ) ) {
		throw new \UnexpectedValueException( 'Queued email object reference cannot be restored.' );
	}

	return $object;
}