Purpose

Control the visibility of a form programmatically. This filter allows developers to conditionally hide forms and display a custom message instead, based on specific criteria.

Usage

add_action( 'wr_form_should_not_be_loaded', array( $this, 'hide_form_for_user_x' ), 10, 3 );

Parameters

  • $flag_and_error_message (array): An array containing:
    • A boolean flag indicating whether the form should be hidden.
    • An optional message object to display instead of the form.
  • $form (Form): The form object, which provides information such as the form’s identifier.
  • $entry (Entry): The entry object associated with the form.

Use Case

This functionality is useful when:

  • Certain users or conditions should restrict access to specific forms.
  • You want to display a custom message instead of a hidden form, explaining why it is not accessible.

Implementation Example

The following example hides a form identified by “identifier” for a user with the ID 2 and displays a warning message:

add_action( 'wr_form_should_not_be_loaded', array( $this, 'hide_form_for_user_x' ), 10, 3 );
 
public function hide_form_for_user_x( array $flag_and_error_message, Form $form, Entry $entry ): array {
	if ( $form->get_identifier() === "identifier" && get_current_user_id() === 2) {
		$message = new HtmlObject( "div", array( "class" => "alert alert-warning" ),__( "You are not allowed to see this form", "your-text-domain" ) );6      	return array( true, $message );
	}
	return $flag_and_error_message;
}