Submission::add_error( int $element_id, string $code, string $message )

Adds an error to the submission.

Description

See also

Parameters

$element_id

(int) (Required) Element ID to add the error for.

$code

(string) (Required) Error code.

$message

(string) (Required) Error message.

Return

(bool) True on success, false on failure.

Source

File: src/db-objects/submissions/submission.php

	public function add_error( $element_id, $code, $message ) {
		if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
			if ( $this->primary_property_value() ) {
				$this->pending_meta['errors'] = $this->manager->get_meta( $this->primary_property_value(), 'errors', true );
			} else {
				$this->pending_meta['errors'] = array();
			}
		}

		if ( ! is_array( $this->pending_meta['errors'] ) ) {
			$this->pending_meta['errors'] = array();
		}

		if ( ! isset( $this->pending_meta['errors'][ $element_id ] ) || ! is_array( $this->pending_meta['errors'][ $element_id ] ) ) {
			$this->pending_meta['errors'][ $element_id ] = array();
		}

		$this->pending_meta['errors'][ $element_id ][ $code ] = $message;

		return true;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.