Submission::reset_errors( int|null $element_id = null )

Resets all errors, for the entire submission or a specific element.

Description

See also

Parameters

$element_id

(int|null) (Optional) If an element ID is given, only errors for that element are reset.

Default value: null

Return

(bool) True on success, false on failure.

Source

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

	public function reset_errors( $element_id = null ) {
		if ( ! array_key_exists( 'errors', $this->pending_meta ) ) {
			if ( ! $this->primary_property_value() ) {
				return false;
			}

			$this->pending_meta['errors'] = $this->manager->get_meta( $this->primary_property_value(), 'errors', true );
		}

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

			return false;
		}

		if ( null !== $element_id ) {
			if ( ! is_array( $this->pending_meta['errors'] ) || empty( $this->pending_meta['errors'][ $element_id ] ) ) {
				return false;
			}

			unset( $this->pending_meta['errors'][ $element_id ] );

			return true;
		}

		$this->pending_meta['errors'] = null;

		return true;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.