Timerange::can_access( awsmug\Torro_Forms\DB_Objects\Forms\Form $form, awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null $submission = null )

Determines whether the current user can access a specific form or submission.

Description

See also

Parameters

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form object.

$submission

(awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null) (Optional) Submission object, or null if no submission is set.

Default value: null

Return

(bool|WP_Error) True if the form or submission can be accessed, false or error object otherwise.

Source

File: src/modules/access-controls/timerange.php

	public function can_access( $form, $submission = null ) {
		$start = $this->get_form_option( $form->id, 'start' );
		$end   = $this->get_form_option( $form->id, 'end' );

		$now = current_time( 'timestamp' );

		if ( $start && $now < strtotime( $start ) ) {
			$message = $this->get_form_option( $form->id, 'not_yet_open_message' );
			if ( empty( $message ) ) {
				$message = $this->get_default_not_yet_open_message();
			}

			return new WP_Error( 'form_not_yet_open', $message );
		}

		if ( $end && $now > strtotime( $end ) ) {
			$message = $this->get_form_option( $form->id, 'no_longer_open_message' );
			if ( empty( $message ) ) {
				$message = $this->get_default_no_longer_open_message();
			}

			return new WP_Error( 'form_no_longer_open', $message );
		}

		return true;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.