Container::duplicate( int $form_id )

Duplicates the container including all of its contents.

Description

See also

Parameters

$form_id

(int) (Required) New parent form ID to use for the container.

Return

(awsmug\Torro_Forms\DB_Objects\Containers\Container|WP_Error) New container object on success, error object on failure.

Source

File: src/db-objects/containers/container.php

	public function duplicate( $form_id ) {
		$new_container = $this->manager->create();

		foreach ( $this->to_json() as $key => $value ) {
			if ( 'id' === $key ) {
				continue;
			}

			if ( 'form_id' === $key ) {
				$new_container->form_id = $form_id;
				continue;
			}

			$new_container->$key = $value;
		}

		$status = $new_container->sync_upstream();
		if ( is_wp_error( $status ) ) {
			return $status;
		}

		foreach ( $this->get_elements() as $element ) {
			$element->duplicate( $new_container->id );
		}

		return $new_container;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.