Access_Control

Base class for an access control.

Description

Source

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

abstract class Access_Control extends Submodule implements Meta_Submodule_Interface, Settings_Submodule_Interface {
	use Meta_Submodule_Trait, Settings_Submodule_Trait {
		Meta_Submodule_Trait::get_meta_fields as protected _get_meta_fields;
	}

	/**
	 * Checks whether the access control is enabled for a specific form.
	 *
	 * @since 1.0.0
	 *
	 * @param Form $form Form object to check.
	 * @return bool True if the access control is enabled, false otherwise.
	 */
	public function enabled( $form ) {
		return $this->get_form_option( $form->id, 'enabled', false );
	}

	/**
	 * Determines whether the current user can access a specific form or submission.
	 *
	 * @since 1.0.0
	 *
	 * @param Form            $form       Form object.
	 * @param Submission|null $submission Submission object, or null if no submission is set.
	 * @return bool|WP_Error True if the form or submission can be accessed, false or error object otherwise.
	 */
	public abstract function can_access( $form, $submission = null );

	/**
	 * Returns the available meta fields for the submodule.
	 *
	 * @since 1.0.0
	 *
	 * @return array Associative array of `$field_slug => $field_args` pairs.
	 */
	public function get_meta_fields() {
		$meta_fields = $this->_get_meta_fields();

		$meta_fields['enabled'] = array(
			'type'         => 'checkbox',
			'label'        => _x( 'Enable?', 'access control', 'torro-forms' ),
			'visual_label' => _x( 'Status', 'access control', 'torro-forms' ),
		);

		return $meta_fields;
	}
}

Changelog

Changelog
Version Description
1.0.0 Introduced.

Methods

  • bootstrap — Bootstraps the submodule by setting properties.
  • can_access — Determines whether the current user can access a specific form or submission.
  • enabled — Checks whether the access control is enabled for a specific form.
  • get_default_already_submitted_message — Returns the default message to display when the user is not logged in.
  • get_meta_fields — Returns the available meta fields for the submodule.
  • set_submission_data — Sets additional data for a submission when it is created.