# Developer Documentation

This document provides a comprehensive reference for the hooks (actions and filters) and public functions available in the Advanced Members plugin.

## Table of Contents

- [Hooks](#hooks)
  - [Actions](#actions)
  - [Filters](#filters)
- [Functions](#functions)
  - [Helper Functions](#helper-functions)
  - [Form Functions](#form-functions)
  - [Field Functions](#field-functions)
  - [User Functions](#user-functions)
  - [Submission Functions](#submission-functions)
- [Examples](#examples)

---

## Hooks

### Actions

#### Plugin Lifecycle

##### `amem/setup_plugin`
Fires when the plugin is setting up.
- **Location**: `advanced-members.php::setup_plugin()`
- **Context**: Executes during plugin initialization, called after constants are defined and text domain is loaded.
- **Arguments**:
    - `$version` (string): The current plugin version.

##### `amem/register_forms`
Fires when forms are being registered. Use this hook to register custom forms programmatically.
- **Location**: `advanced-members.php::load_plugin()`
- **Context**: Used when registering forms after ACF initialization. Use this hook to register custom forms programmatically.

##### `amem/register_actions`
Fires when plugin actions are being registered.
- **Location**: `advanced-members.php::load_plugin()`
- **Context**: Used when registering form actions (login, registration, account, etc.).

##### `amem/register_addons`
Fires when addons are being registered.
- **Location**: `advanced-members.php::load_plugin()`
- **Context**: Used when registering addons.

##### `amem/load`
Fires when the plugin has finished loading.
- **Location**: `advanced-members.php::load_plugin()`
- **Context**: Executes after the plugin has finished loading.

#### Form Actions

##### `amem/form/render`
Fires when a form is being rendered.
- **Location**: `core/functions-forms.php::amem_form()`
- **Context**: Executes when `amem_form()` function is called to render a form. Runs before form HTML output.
- **Arguments**:
    - `$form_id` (int): The ID of the form being rendered.
    - `$args` (array): The arguments passed to the form render function.

##### `amem/form/before_submission`
Fires before form submission is processed.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes before form submission is processed. Allows custom validation or data modification.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/form/before_submission/type={$form_type}`
Fires before form submission for a specific form type.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes before submission for a specific form type.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.
- **Example**: `amem/form/before_submission/type=registration`

##### `amem/form/submission`
Fires when a form is submitted successfully.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes after form submission is successfully completed. The `AMem\Forms\Actions` class uses this hook to handle form type-specific actions.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/form/submission/type={$form_type}`
Fires when a form of a specific type is submitted.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes after submission for a specific form type.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/form/validate`
Fires during form validation.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Called from ACF's `acf/validate_save_post` action, executes during form validation phase.
- **Arguments**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
    - `$fields` (array): The submitted fields.

##### `amem/form/validate/type={$form_type}`
Fires during validation for a specific form type.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes during validation for a specific form type. Each action class (Login, Registration, etc.) uses this hook.
- **Arguments**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
    - `$fields` (array): The submitted fields.

##### `amem/form/create_submission/pre`
Fires before creating a submission object.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes before creating a submission object. Only the form key or ID is passed.
- **Arguments**:
    - `$form_key_or_id` (string|int): The form key or ID.

##### `amem/form/create_submission/before`
Fires before submission data is processed.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes before submission data is processed. Form and args are ready, but field data has not been processed yet.
- **Arguments**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/form/create_submission/before/type={$form_type}`
Fires before submission for a specific form type.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Executes before processing submission data for a specific form type.
- **Arguments**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/form/enqueue_scripts`
Fires when form scripts are being enqueued.
- **Location**: `core/functions-forms.php::amem_enqueue()`
- **Context**: Executes when `amem_enqueue()` function registers form scripts and styles.

##### `amem/form/to_post`
Fires when saving a form array to a post.
- **Location**: `core/functions-forms.php::amem_form_to_post()`
- **Context**: Executes when saving a form array to a post.
- **Arguments**:
    - `$form` (array): The form array.
    - `$post` (WP_Post): The post object.

#### User Actions

##### `amem/user/login`
Fires when a user successfully logs in.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Executes after login form is successfully processed and user is logged in.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/login/after`
Fires after login processing is complete.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Executes after login processing is complete. Runs regardless of success or failure.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/registration`
Fires when a user is being registered.
- **Location**: `core/actions/registration.php::handle_form()`
- **Context**: Executes when user registration is being processed. Runs before user creation.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/registration/after`
Fires after registration processing is complete.
- **Location**: `core/actions/registration.php::handle_form()`
- **Context**: Executes after user registration processing is complete.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/registration/status_set/{$status}`
Fires when a user's registration status is set.
- **Location**: `core/actions/registration.php::handle_form()`
- **Context**: Executes when a user's registration status is set.
- **Arguments**:
    - `$user_id` (int): The user ID.
- **Example**: `amem/user/registration/status_set/approve`

##### `amem/user/created`
Fires when a new user is created.
- **Location**: `core/actions/registration.php::handle_form()`
- **Context**: Executes after a new user is created. Runs after user metadata is saved.
- **Arguments**:
    - `$user` (WP_User): The user object.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/user/updated`
Fires when a user is updated.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes after user information is updated via account update form.
- **Arguments**:
    - `$user` (WP_User): The user object.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/user/delete`
Fires when a user is being deleted via the plugin.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Called from WordPress's `delete_user` or `wpmu_delete_user` actions.
- **Arguments**:
    - `$user_id` (int): The ID of the user being deleted.

##### `amem/user/delete/before`
Fires before a user is deleted.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes before a user is deleted via account deletion form.
- **Arguments**:
    - `$user_id` (int): The user ID.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/user/delete/after`
Fires after a user is deleted.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes after a user is deleted via account deletion form.
- **Arguments**:
    - `$user_id` (int): The user ID.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.

##### `amem/user/status_set/before`
Fires before a user's status is changed.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Executes before a user's account status is changed.
- **Arguments**:
    - `$status` (string): The new status.
    - `$user_id` (int): The ID of the user.

##### `amem/user/status_set/after`
Fires after a user's status has been changed.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Executes after a user's account status has been changed.
- **Arguments**:
    - `$status` (string): The new status.
    - `$user_id` (int): The ID of the user.

##### `amem/user/status/approved/after`
Fires after a user's status has been set to approved.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Executes after user status is set to 'approved'. Runs after approval email is sent.
- **Arguments**:
    - `$user_id` (int): The ID of the user.

##### `amem/user/mail_active/after`
Fires after a user activates their account via email.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Executes after a user activates their account via email link.
- **Arguments**:
    - `$user_id` (int): The user ID.

##### `amem/user/passwordreset`
Fires when a password reset is processed.
- **Location**: `core/actions/password-reset.php::handle_form()`
- **Context**: Executes when password reset form is processed.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/passwordreset/after`
Fires after password reset processing.
- **Location**: `core/actions/password-reset.php::handle_form()`
- **Context**: Executes after password reset processing is complete.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/user/passwordchange/after`
Fires after a user's password is changed.
- **Location**: `core/actions/password-reset.php::handle_form()`
- **Context**: Executes after a user's password is changed.
- **Arguments**:
    - `$user_id` (int): The user ID.

#### Account Actions

##### `amem/account/update`
Fires when an account is being updated.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes when account update form is processed. Runs before user data is updated.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.

##### `amem/account/update/after`
Fires after account update processing.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes after account update processing is complete.
- **Arguments**:
    - `$form` (array): The form array.
    - `$fields` (array): The submitted fields.
    - `$args` (array): Form arguments.
ed
##### `amem/account/content/general`
Fires when rendering the general account tab content.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes when rendering the general account tab content.
- **Arguments**:
    - `$args` (array): Form arguments.
    - `$data` (array): Account data.

##### `amem/account/content/password`
Fires when rendering the password account tab content.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes when rendering the password account tab content.
- **Arguments**:
    - `$args` (array): Form arguments.
    - `$data` (array): Account data.

##### `amem/account/content/delete`
Fires when rendering the delete account tab content.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes when rendering the delete account tab content.
- **Arguments**:
    - `$args` (array): Form arguments.
    - `$data` (array): Account data.

##### `amem/account/content/logged_out`
Fires when rendering content for logged out users.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Executes when rendering content for logged out users.
- **Arguments**:
    - `$args` (array): Form arguments.
    - `$data` (array): Account data.

#### Field Actions

##### `amem/save_all_fields`
Fires after all fields in a form have been saved.
- **Location**: `core/functions-forms.php::amem_save_all_fields()`
- **Context**: Executes after all fields in a form have been saved to an object (user, post, etc.).
- **Arguments**:
    - `$fields` (array): The submitted fields.
    - `$object_id` (int|string): The ID of the object being updated (e.g., user ID).
    - `$excluded_fields` (array): Fields that were excluded from saving.

##### `amem/include_field_types`
Fires when field types are being included.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Used when registering custom field types.
- **Arguments**:
    - `$version` (string): Plugin version.

##### `amem/register_scripts`
Fires when scripts are being registered.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Used when registering field-related scripts.

##### `amem/enqueue_scripts`
Fires when scripts are being enqueued.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Used when enqueuing field-related scripts.

#### Block Actions

##### `amem/blocks/register`
Fires when blocks are being registered.
- **Location**: `core/class-blocks.php::register_blocks()`
- **Context**: Used when registering Gutenberg blocks.

#### Module Actions

##### `amem/module/{$module}/enabled`
Fires when a module is enabled.
- **Location**: `core/class-options.php::get()`
- **Context**: Executes when a module is enabled.
- **Arguments**:
    - `$module` (string): Module name.

##### `amem/module/{$module}/disabled`
Fires when a module is disabled.
- **Location**: `core/class-options.php::get()`
- **Context**: Executes when a module is disabled.
- **Arguments**:
    - `$module` (string): Module name.

### Filters

#### Plugin Filters

##### `amem/allowed_roles`
Filters the list of allowed roles that can be managed or used by the plugin.
- **Location**: `core/functions-helpers.php::amem_allowed_roles()`
- **Context**: Filters the list of roles that can be used by the plugin.
- **Arguments**:
    - `$roles` (array): An associative array of role slugs and names.
- **Return**: `array`

##### `amem/core/page`
Filters the URL of a core plugin page.
- **Location**: `core/functions-helpers.php::amem_get_core_page()`
- **Context**: Filters the URL of core pages (login, register, account, etc.).
- **Arguments**:
    - `$url` (string): The page URL.
    - `$slug` (string): The page slug.
    - `$updated` (bool|string): Whether to add an 'updated' query arg.
- **Return**: `string`

#### Template Filters

##### `amem/template/merge_tags`
Filters the list of search tags (placeholders) for templates.
- **Location**: `core/functions-helpers.php::amem_replace_placeholders()`, `core/class-mail.php::send()`
- **Context**: Filters the list of merge tags used in email templates, success messages, etc. You can add tags like `{username}`, `{email}`, etc.
- **Arguments**:
    - `$search` (array): Array of strings to search for (e.g., `{username}`).
- **Return**: `array`

##### `amem/template/merge_tags/replace`
Filters the list of replacement values for template tags.
- **Location**: `core/functions-helpers.php::amem_replace_placeholders()`, `core/class-mail.php::send()`
- **Context**: Filters the list of replacement values for merge tags used in email templates, success messages, etc. Values must be provided in the same order as `amem/template/merge_tags`.
- **Arguments**:
    - `$replace` (array): Array of replacement values corresponding to the search tags.
- **Return**: `array`

##### `amem/convert_tags`
Filters the value of a specific tag during conversion.
- **Location**: `core/functions-helpers.php::amem_convert_tags()`
- **Context**: Used when converting template tags to actual values. Executes when converting tags in the format `{usermeta:field_name}`.
- **Arguments**:
    - `$value` (mixed): The value to replace the tag with.
    - `$key` (string): The key of the tag (e.g., `usermeta:my_field`).
- **Return**: `mixed`

##### `amem/merge_tags/resolve`
Filters the resolved value of a merge tag.
- **Location**: `core/functions-helpers.php::amem_resolve_merge_tags()`, `core/forms/actions.php::resolve_merge_tag()`
- **Context**: Used when resolving merge tags in the format `{field:FIELD_NAME}`. Used to dynamically insert field values in success messages, error messages, email body, etc.
- **Arguments**:
    - `$value` (string): The resolved value (usually empty initially).
    - `$tag` (string): The tag being resolved (e.g., `field:my_field`).
    - `$fields` (array): The available fields.
- **Return**: `string`

##### `amem/merge_tags/custom`
Filters custom merge tags for a form.
- **Location**: `core/functions-helpers.php::_amem_field_inserter_button()`
- **Context**: Used to add custom merge tags that will be displayed in the admin field inserter button.
- **Arguments**:
    - `$custom_tags` (array): Array of custom tag arrays.
    - `$form` (array): The form array.
- **Return**: `array`

#### User Filters

##### `amem/user/{$key}`
Filters a specific user data value. The `{$key}` dynamic portion refers to the user data key (e.g., `amem/user/user_email`).
- **Location**: `core/functions-helpers.php::amem_user()`
- **Context**: Filters user data when retrieved via `amem_user()` function. Allows modification of specific user meta field values.
- **Arguments**:
    - `$value` (mixed): The value of the user data.
    - `$user_id` (int): The user ID.
- **Return**: `mixed`

##### `amem/user/data`
Filters user data array.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Filters user data array when constructed by `AMem\User` class.
- **Arguments**:
    - `$data` (array): User data array.
    - `$user_id` (int): The user ID.
- **Return**: `array`

##### `amem/user/delete/reassign`
Filters the user ID to reassign content to when deleting a user.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Used to specify the user ID to reassign content to when deleting a user.
- **Arguments**:
    - `$reassign` (int|null): User ID to reassign to.
    - `$user_id` (int): The user being deleted.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `int|null`

##### `amem/user/mail_active/redirect`
Filters the redirect URL after email activation.
- **Location**: `core/class-user.php::delete_hook()`
- **Context**: Filters the redirect URL after a user activates their account via email link.
- **Arguments**:
    - `$redirect` (string): The redirect URL.
    - `$user_id` (int): The user ID.
- **Return**: `string`

#### Form Filters

##### `amem/form/types`
Filters the available form types.
- **Location**: `core/functions-forms.php::amem_form_types()` - Currently commented out
- **Context**: Filters the list of available form types. (Currently commented out)
- **Arguments**:
    - `$types` (array): Array of form types.
- **Return**: `array`

##### `amem/form_types/core`
Filters core form types.
- **Location**: `core/functions-forms.php::amem_form_types()`
- **Context**: Filters the list of core form types (registration, login, account).
- **Arguments**:
    - `$core` (array): Core form types array.
- **Return**: `array`

##### `amem/form_types/local`
Filters local form types.
- **Location**: `core/functions-forms.php::amem_form_types()`
- **Context**: Filters the list of local form types (passwordreset, etc.).
- **Arguments**:
    - `$local` (array): Local form types array.
- **Return**: `array`

##### `amem/form/valid_form`
Filters the default arguments for a valid form array.
- **Location**: `core/functions-forms.php::amem_get_valid_form()`
- **Context**: Filters default arguments for a valid form array. Used when registering forms programmatically.
- **Arguments**:
    - `$args` (array): Default form arguments.
- **Return**: `array`

##### `amem/form/from_local`
Filters a form array loaded from local registration.
- **Location**: `core/functions-forms.php::amem_form_from_local()`
- **Context**: Filters form array when loaded from programmatic registration.
- **Arguments**:
    - `$form` (array): The form array.
- **Return**: `array`

##### `amem/form/from_local/type={$form_type}`
Filters a form array loaded from local registration for a specific type.
- **Location**: `core/functions-forms.php::amem_form_from_local()`
- **Context**: Filters form array when loading a local form of a specific type.
- **Arguments**:
    - `$form` (array): The form array.
- **Return**: `array`

##### `amem/form/from_post`
Filters a form array loaded from a post object.
- **Location**: `core/functions-forms.php::amem_form_from_post()`
- **Context**: Filters form array when loaded from a post. Used when loading forms created in the admin.
- **Arguments**:
    - `$form` (array): The form array.
    - `$form_post` (WP_Post): The original post object.
- **Return**: `array`

##### `amem/form/from_post/type={$form_type}`
Filters a form array loaded from a post for a specific type.
- **Location**: `core/functions-forms.php::amem_form_from_post()`
- **Context**: Filters form array when loading a post form of a specific type.
- **Arguments**:
    - `$form` (array): The form array.
    - `$form_post` (WP_Post): The original post object.
- **Return**: `array`

##### `amem/form/redirects`
Filters the redirect settings for a form.
- **Location**: `core/functions-forms.php::amem_default_form_redirects()`
- **Context**: Filters redirect settings after form submission. Allows modification of `after_submit` and `redirect_url` values.
- **Arguments**:
    - `$_redirects` (array): Array containing `after_submit` and `redirect_url`.
    - `$form_type` (string): The type of the form.
    - `$post_id` (int): The ID of the form post.
- **Return**: `array`

##### `amem/form/redirects/{$form_type}`
Filters redirect settings for a specific form type.
- **Location**: `core/functions-forms.php::amem_default_form_redirects()`
- **Context**: Filters redirect settings for a specific form type.
- **Arguments**:
    - `$_redirects` (array): Array containing `after_submit` and `redirect_url`.
    - `$post_id` (int): The ID of the form post.
- **Return**: `array`

##### `amem/form/success_message`
Filters the success message for a form.
- **Location**: `core/functions-forms.php::amem_form_success_message()`
- **Context**: Filters success message displayed after successful form submission. Executes before merge tag resolution.
- **Arguments**:
    - `$success_message` (string): The success message text.
    - `$form` (array): The form object.
    - `$args` (array): Arguments passed to the success message function.
- **Return**: `string`

##### `amem/form/success_message/type={$form_type}`
Filters the success message for a specific form type.
- **Location**: `core/functions-forms.php::amem_form_success_message()`
- **Context**: Filters success message for a specific form type.
- **Arguments**:
    - `$success_message` (string): The success message text.
    - `$form` (array): The form object.
    - `$args` (array): Arguments passed to the success message function.
- **Return**: `string`

##### `amem/form/updated_message`
Filters the updated message for a form.
- **Location**: `core/functions-forms.php::amem_form_updated_message()`
- **Context**: Filters message displayed after form update. Shown when URL query parameter `updated` is present.
- **Arguments**:
    - `$message` (string): The message text.
    - `$updated_code` (string): The update code.
    - `$form` (array): The form object.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/updated_message/type={$form_type}`
Filters the updated message for a specific form type.
- **Location**: `core/functions-forms.php::amem_form_updated_message()`
- **Context**: Filters updated message for a specific form type.
- **Arguments**:
    - `$message` (string): The message text.
    - `$updated_code` (string): The update code.
    - `$form` (array): The form object.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/error_message`
Filters the error message for a form.
- **Location**: `core/class-errors.php::form_error_message()`
- **Context**: Filters error message that occurred during form submission. Executes before merge tag resolution.
- **Arguments**:
    - `$message` (string): The error message text.
    - `$code` (string): The error code.
    - `$form` (array): The form object.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/error_message/type={$form_type}`
Filters the error message for a specific form type.
- **Location**: `core/class-errors.php::form_error_message()`
- **Context**: Filters error message for a specific form type.
- **Arguments**:
    - `$message` (string): The error message text.
    - `$code` (string): The error code.
    - `$form` (array): The form object.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/ajax/response`
Filters the AJAX response for a form submission.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Filters AJAX response for form submission. Allows modification of success message, redirect URL, etc.
- **Arguments**:
    - `$response` (array): The response array.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/form/ajax/response/type={$form_type}`
Filters the AJAX response for a specific form type.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Filters AJAX response for a specific form type.
- **Arguments**:
    - `$response` (array): The response array.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/form/user_data`
Filters user data before insert/update.
- **Location**: `core/actions/registration.php::handle_form()`, `core/actions/account.php::handle_form()`
- **Context**: Filters user data before insert/update. Executes before `wp_insert_user()` or `wp_update_user()` is called.
- **Arguments**:
    - `$user_data` (array): User data array.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/form/submit_text_default/type={$form_type}`
Filters the default submit button text for a form type.
- **Location**: `core/functions-forms.php::amem_submit_text_default()`
- **Context**: Filters default submit button text for a form type.
- **Arguments**:
    - `$submit_text` (string): The submit text.
    - `$form_id` (int): The form ID.
- **Return**: `string`

##### `amem/form/login/button/text`
Filters the login form submit button text.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Filters login form submit button text.
- **Arguments**:
    - `$submit_text` (string): The submit text.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/login/extra_button/text`
Filters the login form extra button text.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Filters login form extra button text (e.g., registration link).
- **Arguments**:
    - `$extra_btn_text` (string): The button text.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/login/extra_button/url`
Filters the login form extra button URL.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Filters login form extra button URL.
- **Arguments**:
    - `$extra_btn_url` (string): The button URL.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `string`

##### `amem/form/use_raw_record`
Filters fields that should use raw POST data instead of sanitized data.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Specifies field types that should use raw POST data instead of sanitized data during submission processing. By default, `user_password` is included.
- **Arguments**:
    - `$use_raw` (array): Array of field types to use raw data.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/form/submit/redirect/{$form_type}`
Filters the redirect URL after form submission for a specific type.
- **Location**: `core/forms/actions.php::after_submit_redirect()`
- **Context**: Filters redirect URL after form submission for a specific type.
- **Arguments**:
    - `$url` (string): The redirect URL.
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
- **Return**: `string`

#### Field Filters

##### `amem/field/render_include`
Filters the rendered HTML of a field include.
- **Location**: `core/functions-helpers.php::_amem_render_field_include()`
- **Context**: Filters rendered HTML when including fields in email body, success messages, etc. Used when converting field values to HTML.
- **Arguments**:
    - `$output` (string): The rendered HTML.
    - `$field` (array): The field object.
    - `$value` (mixed): The field value.
- **Return**: `string`

##### `amem/field/render_include/name={$field_name}`
Filters the rendered HTML for a specific field by name.
- **Location**: `core/functions-helpers.php::_amem_render_field_include()`
- **Context**: Filters field rendering HTML for a specific field by name.
- **Arguments**:
    - `$output` (string): The rendered HTML.
    - `$field` (array): The field object.
    - `$value` (mixed): The field value.
- **Return**: `string`

##### `amem/field/render_include/key={$field_key}`
Filters the rendered HTML for a specific field by key.
- **Location**: `core/functions-helpers.php::_amem_render_field_include()`
- **Context**: Filters field rendering HTML for a specific field by key.
- **Arguments**:
    - `$output` (string): The rendered HTML.
    - `$field` (array): The field object.
    - `$value` (mixed): The field value.
- **Return**: `string`

##### `amem/predefined_fields`
Filters the list of predefined field types.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Filters the list of predefined field types available in the admin interface.
- **Arguments**:
    - `$fields` (array): Array of predefined fields.
- **Return**: `array`

##### `amem/fields/hidden_types`
Filters field types that should be hidden from field pickers.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Filters the list of field types that should be hidden from field pickers.
- **Arguments**:
    - `$hide_types` (array): Array of field types to hide.
- **Return**: `array`

##### `amem/fields/get_field_type`
Filters the field type for a field.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Filters the field type. Used when changing ACF field types.
- **Arguments**:
    - `$type` (string): The field type.
    - `$field` (array): The field array.
- **Return**: `string`

##### `amem/fields/truefalse_types`
Filters field types that should be treated as true/false for conditional logic.
- **Location**: `core/class-fields.php::register_scripts()`
- **Context**: Filters the list of field types that should be treated as true/false for conditional logic.
- **Arguments**:
    - `$truefalse_types` (array): Array of field types.
- **Return**: `array`

#### Account Filters

##### `amem/account/local_fields/general`
Filters local fields for the general account tab.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Filters local fields displayed in the general account tab. Allows adding or modifying default user information fields.
- **Arguments**:
    - `$fields` (array): Array of field arrays.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/account/local_fields/password`
Filters local fields for the password account tab.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Filters local fields displayed in the password account tab.
- **Arguments**:
    - `$fields` (array): Array of field arrays.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/account/local_fields/delete`
Filters local fields for the delete account tab.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Filters local fields displayed in the delete account tab.
- **Arguments**:
    - `$fields` (array): Array of field arrays.
    - `$args` (array): Form arguments.
- **Return**: `array`

##### `amem/account/{$tab_key}/require_password`
Filters whether password validation is required for an account tab.
- **Location**: `core/actions/account.php::process_delete()`
- **Context**: Filters whether password validation is required for an account tab.
- **Arguments**:
    - `$is_required` (bool): Whether password is required.
- **Return**: `bool`
- **Example**: `amem/account/general/require_password`

#### Settings Filters

##### `amem/settings/enqueue_validation_hotfix`
Filters whether to enqueue the validation hotfix script.
- **Location**: `core/functions-forms.php::amem_enqueue()`
- **Context**: Filters whether to enqueue the validation hotfix script that fixes the issue where validation applies to all forms when multiple forms are on the same page.
- **Arguments**:
    - `$enqueue` (bool): Whether to enqueue (default: false).
- **Return**: `bool`

##### `amem/settings/cookie_name`
Filters the cookie name used for submissions.
- **Location**: `core/forms/submissions.php::process_submission()`
- **Context**: Filters the cookie name used for storing submission data. Default is 'amem_submission'.
- **Arguments**:
    - `$cookie_name` (string): The cookie name (default: 'amem_submission').
- **Return**: `string`

#### Error Filters

##### `amem/error/messages`
Filters error messages.
- **Location**: `core/class-errors.php::form_error_message()`
- **Context**: Filters the list of error messages used by the plugin. Allows adding custom error messages.
- **Arguments**:
    - `$messages` (array): Array of error messages.
- **Return**: `array`

#### Authentication Filters

##### `amem/authenticate/error_codes`
Filters error codes that should be handled by third-party authentication.
- **Location**: `core/actions/login.php::handle_form()`
- **Context**: Filters error codes that should be handled for integration with third-party authentication plugins.
- **Arguments**:
    - `$codes` (array): Array of error codes.
- **Return**: `array`

#### Option Filters

##### `amem/option/get/{$option_key}`
Filters an option value when retrieved.
- **Location**: `core/class-options.php::get()`
- **Context**: Filters option value when retrieved. Allows dynamic modification of specific option values.
- **Arguments**:
    - `$value` (mixed): The option value.
- **Return**: `mixed`

##### `amem/option/set/{$option_key}`
Filters an option value before it's saved.
- **Location**: `core/class-options.php::get()`
- **Context**: Filters option value before it's saved.
- **Arguments**:
    - `$value` (mixed): The option value.
- **Return**: `mixed`

##### `amem/option/core_page_id`
Filters the option name for a core page ID.
- **Location**: `core/class-options.php::get()`
- **Context**: Filters the option name for storing core page ID.
- **Arguments**:
    - `$option_name` (string): The option name.
- **Return**: `string`

##### `amem/option/getmodule/{$module_key}`
Filters a module option value when retrieved.
- **Location**: `core/class-options.php::get()`
- **Context**: Filters module option value when retrieved.
- **Arguments**:
    - `$value` (mixed): The module option value.
- **Return**: `mixed`

##### `amem/admin/options/sanitizers`
Filters the sanitizer map for admin options.
- **Location**: `core/class-options.php::get()`
- **Context**: Filters the sanitizer map for admin options. Allows adding custom sanitizers.
- **Arguments**:
    - `$map` (array): Array of sanitizer functions.
- **Return**: `array`

#### Sanitization Filters

##### `amem/sanitize/data/method={$method}`
Filters data sanitization for a specific method.
- **Location**: `core/functions-helpers.php::amem_sanitize_data()`
- **Context**: Filters data when sanitizing with a specific sanitization method.
- **Arguments**:
    - `$value` (mixed): The value to sanitize.
- **Return**: `mixed`

##### `amem/sanitize/data/name={$name}`
Filters data sanitization for a specific option name.
- **Location**: `core/functions-helpers.php::amem_sanitize_data()`
- **Context**: Filters data when sanitizing with a specific option name.
- **Arguments**:
    - `$value` (mixed): The value to sanitize.
- **Return**: `mixed`

#### Email Filters

##### `amem/email/notifications`
Filters email notification templates.
- **Location**: `core/class-config.php::__construct()`
- **Context**: Filters the list of email notification templates. Allows adding custom email templates.
- **Arguments**:
    - `$notifications` (array): Array of notification templates.
- **Return**: `array`

#### Core Page Filters

##### `amem/core/pages`
Filters core pages configuration.
- **Location**: `core/class-config.php::__construct()`
- **Context**: Filters core pages configuration (login, register, account, etc.).
- **Arguments**:
    - `$core_pages` (array): Array of core page configurations.
- **Return**: `array`

#### Restriction Filters

##### `amem/restriction/post_types`
Filters post types that can be restricted.
- **Location**: `core/modules/class-restriction.php::post_types()`
- **Context**: Filters the list of post types that can be restricted.
- **Arguments**:
    - `$post_types` (array): Array of post type names.
- **Return**: `array`

##### `amem/restriction/taxonomies`
Filters taxonomies that can be restricted.
- **Location**: `core/modules/class-restriction.php::post_types()`
- **Context**: Filters the list of taxonomies that can be restricted.
- **Arguments**:
    - `$taxonomies` (array): Array of taxonomy names.
- **Return**: `array`

##### `amem/restriction/post/restricted`
Filters whether a post is restricted.
- **Location**: `core/modules/class-restriction.php::post_types()`
- **Context**: Filters whether a specific post is restricted.
- **Arguments**:
    - `$restricted` (bool): Whether the post is restricted.
    - `$post_id` (int): The post ID.
    - `$instant` (bool): Whether to check instant restriction.
- **Return**: `bool`

#### Avatar Filters

##### `amem/avatar/sizes`
Filters available avatar sizes.
- **Location**: `core/modules/class-avatar.php::avatar_sizes()`
- **Context**: Filters the list of sizes available for avatar image generation.
- **Arguments**:
    - `$sizes` (array): Array of size values.
- **Return**: `array`

##### `amem/avatar/jpeg_quality`
Filters JPEG quality for avatar images.
- **Location**: `core/modules/class-avatar.php::avatar_sizes()`
- **Context**: Filters JPEG quality when saving avatar images.
- **Arguments**:
    - `$jpeg_quality` (int): JPEG quality (default: 90).
- **Return**: `int`

#### Block Filters

##### `amem/blocks/assets/form_args`
Filters form arguments for block rendering.
- **Location**: `core/class-blocks.php::register_blocks()`
- **Context**: Filters form arguments used when rendering forms in Gutenberg blocks.
- **Arguments**:
    - `$form_args` (array): Form arguments array.
- **Return**: `array`

##### `amem/blocks/cache/defaults`
Filters whether to use cache defaults for blocks.
- **Location**: `core/class-blocks.php::register_blocks()`
- **Context**: Filters whether to use cache when rendering blocks.
- **Arguments**:
    - `$use_cache` (bool): Whether to use cache (default: false).
- **Return**: `bool`

#### File Filters

##### `amem/upload_basedir`
Filters the upload base directory.
- **Location**: `core/class-files.php::setup_paths()`
- **Context**: Filters the upload base directory.
- **Arguments**:
    - `$upload_basedir` (string): The upload base directory.
- **Return**: `string`

##### `amem/upload_baseurl`
Filters the upload base URL.
- **Location**: `core/class-files.php::setup_paths()`
- **Context**: Filters the upload base URL.
- **Arguments**:
    - `$upload_baseurl` (string): The upload base URL.
- **Return**: `string`

---

## Functions

### Helper Functions

#### `amem_get_path( $filename = '', $base = null )`
Returns the plugin path to a specified file.
- **Parameters**:
    - `$filename` (string): The specified file.
    - `$base` (string): Base path (optional). Can be 'assets' or 'pro'.
- **Return**: `string`

#### `amem_get_url( $filename = '', $base = null )`
Returns the plugin URL to a specified file.
- **Parameters**:
    - `$filename` (string): The specified file.
    - `$base` (string): Base path (optional). Can be 'assets' or 'pro'.
- **Return**: `string`

#### `amem_include( $filename = '', $base = null )`
Includes a file from the plugin directory.
- **Parameters**:
    - `$filename` (string): The specified file.
    - `$base` (string): Base path (optional).
- **Return**: `mixed` (Return value of included file)

#### `amem_get_view( $view_path = '', $view_args = array(), $base_path = '' )`
Loads a file from the 'admin/views' folder and allows variables to be passed through.
- **Parameters**:
    - `$view_path` (string): Path to the view file.
    - `$view_args` (array): Associative array of variables to extract in the view.
    - `$base_path` (string): Base path of `$view_path`.

#### `amem_get_core_page( $slug, $updated = false, $redirect_to = '' )`
Get the URL of a core plugin page (e.g., login, register).
- **Parameters**:
    - `$slug` (string): The slug of the core page.
    - `$updated` (bool|string): Whether to add an 'updated' query arg.
    - `$redirect_to` (string): URL to redirect to.
- **Return**: `string`

#### `amem_get_core_page_id( $slug )`
Get the post ID of a core plugin page.
- **Parameters**:
    - `$slug` (string): The slug of the core page.
- **Return**: `int`

#### `amem_is_core_page( $slug )`
Check if the current page is a specific AMem Core Page.
- **Parameters**:
    - `$slug` (string): AMem core page slug (e.g., 'login', 'register').
- **Return**: `bool`

#### `amem_allowed_roles()`
Returns a list of allowed roles for the plugin.
- **Return**: `array`

#### `amem_is_core_post( $post, $slugs = [] )`
Checks if a post corresponds to a core plugin page.
- **Parameters**:
    - `$post` (WP_Post): The post object.
    - `$slugs` (array|string): Array of slugs to check against, or 'all'.
- **Return**: `bool`

#### `amem_get_role_label( $role_slug )`
Get the display label for a role slug.
- **Parameters**:
    - `$role_slug` (string): The role slug.
- **Return**: `string`

#### `amem_user( $key, $attrs = null )`
Retrieves a value for the current user or a specified user.
- **Parameters**:
    - `$key` (string): The user data key (e.g., 'ID', 'user_email', 'user_login').
    - `$attrs` (mixed): Optional attributes.
- **Return**: `mixed`
- **Special Keys**:
    - `user_activation_link`: Returns the activation link URL.
    - `password_reset_link`: Returns the password reset link URL.

#### `amem_resolve_merge_tags( $input, $fields = false )`
Searches input for tags `{field:FIELD_NAME}` and replaces them with field values.
- **Parameters**:
    - `$input` (string): The string containing tags.
    - `$fields` (array): Optional array of fields to use for resolution.
- **Return**: `string`

#### `amem_replace_placeholders()`
Gets an array of search and replace placeholders for templates.
- **Return**: `array` (Associative array with search keys and replace values)

#### `amem_convert_tags( $content, $args = array(), $with_kses = true )`
Converts template tags in content to their values.
- **Parameters**:
    - `$content` (string): The content with tags.
    - `$args` (array): Optional array with 'tags' and 'tags_replace' keys.
    - `$with_kses` (bool): Whether to apply wp_kses_decode_entities.
- **Return**: `string`

#### `amem_get_current_url()`
Get the current URL, handling AJAX requests.
- **Return**: `string`

#### `amem_is_screen( $id = '' )`
Returns true if current screen id matches given.
- **Parameters**:
    - `$id` (string|array): Screen ID(s) to check.
- **Return**: `bool`

#### `amem_is_front()`
Check if current request is frontend.
- **Return**: `bool`

#### `amem_array_insert_after( $array, $key, $new_key, $new_value = null )`
Insert a new key-value pair after a specific key in an array.
- **Parameters**:
    - `$array` (array): The array to modify.
    - `$key` (string): The key to insert after.
    - `$new_key` (string|array): The new key or array of key-value pairs.
    - `$new_value` (mixed): The new value (if $new_key is string).
- **Return**: `array`

#### `amem_is_pro()`
Check if Advanced Members Pro is active.
- **Return**: `bool`

#### `amem_addon_slug( $slug )`
Get plugin path from text domain slug.
- **Parameters**:
    - `$slug` (string): Text domain slug.
- **Return**: `string|false`

#### `amem_register_script( $handle, $src, $deps = array(), $ver = false, $args = array() )`
Register a script with asset file support.
- **Parameters**:
    - `$handle` (string): Script handle.
    - `$src` (string): Script source URL.
    - `$deps` (array): Dependencies.
    - `$ver` (string|bool): Version.
    - `$args` (array): Additional arguments. Can include 'asset_path' for asset file.
- **Return**: `string|bool` (Version)

#### `amem_enqueue_script( $handle, $src, $deps = array(), $ver = false, $args = array() )`
Enqueue a script with asset file support.
- **Parameters**:
    - `$handle` (string): Script handle.
    - `$src` (string): Script source URL.
    - `$deps` (array): Dependencies.
    - `$ver` (string|bool): Version.
    - `$args` (array): Additional arguments.
- **Return**: `string|bool` (Version)

#### `amem_assets_url( $path = '' )`
Retrieves full URL (with trailing slash) to the plugin assets folder.
- **Parameters**:
    - `$path` (string): Additional path.
- **Return**: `string`

#### `amem_nonce_input( $nonce = '_amem_nonce' )`
Create a basic nonce input field.
- **Parameters**:
    - `$nonce` (string): Nonce action name.

#### `amem_verify_nonce( $value = '_amem_nonce' )`
Validate nonce from amem_nonce_input().
- **Parameters**:
    - `$value` (string): Nonce action name.
- **Return**: `bool`

#### `amem_verify_ajax()`
Check if AJAX request is valid.
- **Return**: `bool`

#### `amem_sanitize_input( $data = false )`
Sanitize input data.
- **Parameters**:
    - `$data` (mixed): Data to sanitize.
- **Return**: `mixed`

#### `amem_sanitize_array( $data = array() )`
Sanitize array data recursively.
- **Parameters**:
    - `$data` (array): Array to sanitize.
- **Return**: `array`

#### `amem_sanitize_vars( $vars, $sanitize = null )`
Sanitize vars with non-wp_kses.
- **Parameters**:
    - `$vars` (mixed): Variables to sanitize.
    - `$sanitize` (string|null): Sanitization method ('kses', 'number', 'text', etc.).
- **Return**: `mixed`

#### `amem_sanitize_data( $data, $sanitizers = [] )`
Sanitize $_POST or options data with defined sanitizers.
- **Parameters**:
    - `$data` (array): Data to sanitize.
    - `$sanitizers` (array): Array of sanitizer methods.
- **Return**: `array`

#### `amem_sanitize_html( $body )`
Sanitize HTML or Email Body.
- **Parameters**:
    - `$body` (string): HTML content.
- **Return**: `string`

#### `amem_format_message( $message, $shortcode = false, $autop = true )`
Format and escape message text to print.
- **Parameters**:
    - `$message` (string): Message text.
    - `$shortcode` (bool): Whether to process shortcodes.
    - `$autop` (bool): Whether to apply wpautop.
- **Return**: `string`

### Form Functions

#### `amem_form( $form_id, $args = array() )`
The main function used to output a form.
- **Parameters**:
    - `$form_id` (int|string): The ID or key of the form.
    - `$args` (array): Array of arguments for rendering.
        - `echo` (bool): Whether to echo output (default: true).
        - `user` (int|string): User ID or 'new' for new user.
        - `redirect` (string): Redirect URL after submission.
- **Return**: `string` (The form HTML)

#### `amem_get_form( $form_id_or_key )`
Retrieves a form by form key or form ID.
- **Parameters**:
    - `$form_id_or_key` (mixed): Form ID or Key.
- **Return**: `array|false`

#### `amem_get_forms( $args = '' )`
Returns all forms, both those saved as posts and those registered locally.
- **Parameters**:
    - `$args` (array): Query arguments (WP_Query compatible).
- **Return**: `array`

#### `amem_register_form( $form )`
Used to register a form programmatically.
- **Parameters**:
    - `$form` (array): The form array with required 'key' and optional 'type', 'title', etc.
- **Return**: `array|false`

#### `amem_form_type( $form_id = null )`
Get the type of a given form.
- **Parameters**:
    - `$form_id` (int|array|null): The form ID, form array, or null for current form.
- **Return**: `string|false`

#### `amem_form_types( $type = 'core' )`
Get available form types.
- **Parameters**:
    - `$type` (string): 'core', 'local', or 'all'.
- **Return**: `array`

#### `amem_get_valid_form( $form )`
Validates and fills a form array with default values.
- **Parameters**:
    - `$form` (array): Form array to validate.
- **Return**: `array|false`

#### `amem_is_valid_form_key( $key )`
Checks if the passed key is a valid form key (begins with form_).
- **Parameters**:
    - `$key` (string): The key to check.
- **Return**: `bool`

#### `amem_form_from_key( $key )`
Retrieves a form by its key.
- **Parameters**:
    - `$key` (string): The form key.
- **Return**: `array|false`

#### `amem_form_from_post( $form_post )`
Generates a form array from a form post object.
- **Parameters**:
    - `$form_post` (WP_Post|int): Post object or ID.
- **Return**: `array|false`

#### `amem_form_from_local( $form )`
Processes a locally registered form.
- **Parameters**:
    - `$form` (array): Form array.
- **Return**: `array`

#### `amem_form_post_from_key( $key )`
Retrieves a form post by key if one exists.
- **Parameters**:
    - `$key` (string): The form key.
- **Return**: `WP_Post|false`

#### `amem_form_post_id_from_key( $key )`
Get form post ID from key.
- **Parameters**:
    - `$key` (string): The form key.
- **Return**: `int|false`

#### `amem_form_to_post( $form, $post )`
Save a form array to a form post.
- **Parameters**:
    - `$form` (array): The form array.
    - `$post` (WP_Post|int): Post object or ID.
- **Return**: `WP_Post`

#### `amem_default_form_redirects( $form )`
Sets default redirect settings for a form based on its type.
- **Parameters**:
    - `$form` (array): Form array.
- **Return**: `array`

#### `amem_get_form_field_groups( $form_key )`
Returns all field groups used by specified form.
- **Parameters**:
    - `$form_key` (string|array): The form key or form array.
- **Return**: `array`

#### `amem_get_form_fields( $form_key, $type = 'all' )`
Returns all fields assigned to a form.
- **Parameters**:
    - `$form_key` (string): The form key.
    - `$type` (string): 'all' or 'regular' (excludes repeaters, flexible content, etc.).
- **Return**: `array`

#### `amem_get_local_field_groups( $form_key )`
Get locally registered field groups for a form.
- **Parameters**:
    - `$form_key` (string|array): The form key or form array.
- **Return**: `array`

#### `amem_get_field_group_sort( $form_key_or_id )`
Get field group sort order for a form.
- **Parameters**:
    - `$form_key_or_id` (string|int): Form key or ID.
- **Return**: `array`

#### `amem_sort_form_field_groups( $groups, $form_key = null )`
Sort field groups according to saved order.
- **Parameters**:
    - `$groups` (array): Array of field groups.
    - `$form_key` (string|null): Form key.
- **Return**: `array`

#### `amem_form_success_message( $form, $args, $echo = false )`
Renders the success message for a form.
- **Parameters**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
    - `$echo` (bool): Whether to echo output.
- **Return**: `string`

#### `amem_form_updated_message( $form, $args, $echo = false )`
Renders the updated message for a form.
- **Parameters**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
    - `$echo` (bool): Whether to echo output.
- **Return**: `string|false`

#### `amem_form_error_message( $form, $args, $echo = false )`
Renders the error message for a form.
- **Parameters**:
    - `$form` (array): The form array.
    - `$args` (array): Form arguments.
    - `$echo` (bool): Whether to echo output.
- **Return**: `string`

#### `amem_enqueue()`
Enqueues the necessary scripts and styles for a form.

#### `amem_submit_text_default( $form_id )`
Get default submit button text for a form.
- **Parameters**:
    - `$form_id` (int): The form ID.
- **Return**: `string`

### Field Functions

#### `amem_get_field( $field_key_or_name, $fields = false )`
Helper function to extract a specific field value from submitted fields.
- **Parameters**:
    - `$field_key_or_name` (string): The key or name of the field.
    - `$fields` (array): Optional array of fields to search in.
- **Return**: `mixed|false`

#### `amem_save_field( $field_key_or_name, $object_id )`
Save submitted field directly to an object (post, user, term) with ACF naming.
- **Parameters**:
    - `$field_key_or_name` (string): The key or name of the field.
    - `$object_id` (int|string): The object ID (e.g., 'user_123' for users).
- **Return**: `bool`

#### `amem_save_all_fields( $object_id, $excluded_fields = array() )`
Save all submitted fields directly to an object.
- **Parameters**:
    - `$object_id` (int|string): The object ID.
    - `$excluded_fields` (array): Array of field names to exclude.
- **Return**: `bool`

#### `amem_get_field_object( $field_key_or_name, $fields = [] )`
Helper function to extract a full field object from submitted fields.
- **Parameters**:
    - `$field_key_or_name` (string): The key or name of the field.
    - `$fields` (array): Optional array of fields.
- **Return**: `array|false`

#### `amem_pick_sub_field( $field, $selector )`
Find a nested sub field based on some selector.
- **Parameters**:
    - `$field` (array): The top-level field.
    - `$selector` (array): Array of field names to navigate (e.g., ['group1', 'group2', 'field1']).
- **Return**: `array|false`

#### `amem_pick_sub_field_value( $field, $selector )`
Find a nested value of a sub field based on some selector.
- **Parameters**:
    - `$field` (array): The top-level field.
    - `$selector` (array): Array of field names to navigate.
- **Return**: `mixed|false`

#### `_amem_render_field_include( $field, $value = false )`
Renders a single field include (for emails, success messages etc.).
- **Parameters**:
    - `$field` (array): The field object.
    - `$value` (mixed): Optional value override.
- **Return**: `string`

#### `_amem_render_field_include_value( $value )`
Handle the different shapes field values may take and create an appropriate string.
- **Parameters**:
    - `$value` (mixed): The value to render.
- **Return**: `string`

#### `_amem_field_inserter_button( $form, $type = 'all', $floating = false )`
Output an "Insert field" button populated with $fields.
- **Parameters**:
    - `$form` (array): The form array.
    - `$type` (string): 'all' or 'regular'.
    - `$floating` (bool): Adds class "floating" to the wrapper.

#### `_amem_form_field_choices( $form_key, $type = 'all' )`
Generates choices for a form field picker.
- **Parameters**:
    - `$form_key` (string): The form key.
    - `$type` (string): 'all' or 'regular'.
- **Return**: `array`

#### `_amem_resolve_field_picker_value( $value )`
Get value of field picker from current form.
- **Parameters**:
    - `$value` (array): Array with 'field' and 'format' keys.
- **Return**: `string|false`

### Submission Functions

#### `amem_has_submission( $hash = false )`
Return true if a submission exists.
- **Parameters**:
    - `$hash` (string|false): Optional hash to verify against.
- **Return**: `bool`

#### `amem_submission_failed( $key = false )`
Return true if submission failed.
- **Parameters**:
    - `$key` (string|false): Optional form key to check.
- **Return**: `bool`

#### `amem_add_submission_error( $message, $input = null )`
Adds a general error for a form submission.
- **Parameters**:
    - `$message` (string): Error message.
    - `$input` (string|null): Input name.
- **Return**: `bool`

#### `amem_add_error( $field_key_or_name, $message )`
Add an error for a specific field.
- **Parameters**:
    - `$field_key_or_name` (string): Field key or name.
    - `$message` (string): Error message.

#### `amem_add_form_error( $code, $message )`
Add inline error message without submission.
- **Parameters**:
    - `$code` (string): Error code.
    - `$message` (string): Error message.
- **Return**: `bool`

#### `amem_form_instance_hash( $form_key, $args )`
Calculates a unique hash for a form instance.
- **Parameters**:
    - `$form_key` (string): The form key.
    - `$args` (array): Form arguments.
- **Return**: `string`

#### `amem_encrypt( $data = array() )`
Encrypt an array using PHP.
- **Parameters**:
    - `$data` (array): Data to encrypt.
- **Return**: `string|false`

#### `amem_decrypt( $data = '' )`
Decrypt an encrypted string using PHP.
- **Parameters**:
    - `$data` (string): Encrypted data.
- **Return**: `array|false`

---

## Examples

### Registering a Custom Form

```php
add_action( 'amem/register_forms', function() {
  amem_register_form( [
    'key' => 'form_custom_registration',
    'title' => 'Custom Registration',
    'type' => 'registration',
    'active' => true,
    'data' => [
      'success_message' => 'Thank you for registering!',
      'after_submit' => 'redirect_home',
    ],
  ] );
} );
```

### Custom Form Validation

```php
add_action( 'amem/form/validate/type=registration', function( $form, $args, $fields ) {
  $email = amem_get_field( 'user_email' );
  
  if ( ! is_email( $email ) ) {
    amem_add_error( 'user_email', 'Please enter a valid email address.' );
  }
}, 10, 3 );
```

### Modifying User Data Before Save

```php
add_filter( 'amem/form/user_data', function( $user_data, $form, $args ) {
  if ( $form['type'] === 'registration' ) {
    $user_data['role'] = 'subscriber';
  }
  
  return $user_data;
}, 10, 3 );
```

### Custom Success Message

```php
add_filter( 'amem/form/success_message/type=registration', function( $message, $form, $args ) {
  return 'Welcome! Your account has been created successfully.';
}, 10, 3 );
```

### Custom Redirect After Submission

```php
add_filter( 'amem/form/redirects/registration', function( $_redirects, $post_id ) {
  $_redirects['after_submit'] = 'redirect_url';
  $_redirects['redirect_url'] = home_url( '/welcome/' );
  
  return $_redirects;
}, 10, 2 );
```

### Adding Custom Merge Tags

```php
add_filter( 'amem/template/merge_tags', function( $search ) {
  $search[] = '{custom_field}';
  return $search;
} );

add_filter( 'amem/template/merge_tags/replace', function( $replace ) {
  $replace[] = 'Custom Value';
  return $replace;
} );
```

### Custom Field Rendering

```php
add_filter( 'amem/field/render_include/name=my_custom_field', function( $output, $field, $value ) {
  return '<div class="custom-field">' . esc_html( $value ) . '</div>';
}, 10, 3 );
```

### Hooking into User Creation

```php
add_action( 'amem/user/created', function( $user, $form, $args ) {
  // Send custom notification
  wp_mail( 'admin@example.com', 'New User', 'User ' . $user->user_email . ' has registered.' );
}, 10, 3 );
```

### Custom Account Tab Fields

```php
add_filter( 'amem/account/local_fields/general', function( $fields, $args ) {
  $fields['custom_field'] = [
    'key' => 'custom_field',
    'label' => 'Custom Field',
    'name' => 'custom_field',
    'type' => 'text',
    '_amem_local' => true,
  ];
  
  return $fields;
}, 10, 2 );
```

---

## Support

For more information, visit [plugin website](https://danbilabs.com/) or check the plugin source code.
