Element_Choice::duplicate( int $element_id )

Duplicates the element choice.

Description

See also

Parameters

$element_id

(int) (Required) New parent element ID to use for the element choice.

Return

(awsmug\Torro_Forms\DB_Objects\Element_Choices\Element_Choice|awsmug\Torro_Forms\DB_Objects\Element_Choices\WP_Error) New element choice object on success, error object on failure.

Source

File: src/db-objects/element-choices/element-choice.php

	public function duplicate( $element_id ) {
		$new_element_choice = $this->manager->create();

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

			if ( 'element_id' === $key ) {
				$new_element_choice->element_id = $element_id;
				continue;
			}

			$new_element_choice->$key = $value;
		}

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

		return $new_element_choice;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.