Protection_Field
Protection Field utilities
Tags
Table of Contents
- DEFAULT_STRUCTURE = ['passwords' => [''], 'user_roles' => [], 'users' => [], 'document_owner' => '1']
- Default protection data structure.
- PROTECTION_TYPES = ['password', 'user_role', 'user', 'document_owner']
- List of protection types
- enqueue_assets() : mixed
- Enqueue protection field assets
- has_been_saved() : bool
- Determine if protection settings have been previously saved for a given context
- is_protection_active() : bool
- Check if a specific protection type is active
- normalize() : array<string|int, mixed>
- Normalize protection data
- normalize_saved_data() : array<string|int, mixed>
- Get default protection data
- render_fieldset() : string
- Render complete protection fieldset
- get_field_name() : string
- Get field name based on context
- render_document_owner_option() : mixed
- Render document owner protection option (category context only)
- render_password_option() : mixed
- Render password protection option and section
- render_password_section() : mixed
- Render password protection section
- render_roles_section() : mixed
- Render user roles section
- render_user_option() : mixed
- Render user protection option and section
- render_user_role_option() : mixed
- Render user role protection option and section
- render_users_section() : mixed
- Render specific users section
Constants
DEFAULT_STRUCTURE
Default protection data structure.
public
array<string|int, mixed>
DEFAULT_STRUCTURE
= ['passwords' => [''], 'user_roles' => [], 'users' => [], 'document_owner' => '1']
Tags
PROTECTION_TYPES
List of protection types
public
array<string|int, mixed>
PROTECTION_TYPES
= ['password', 'user_role', 'user', 'document_owner']
Tags
Methods
enqueue_assets()
Enqueue protection field assets
public
static enqueue_assets([string $context = 'global' ]) : mixed
Parameters
- $context : string = 'global'
-
Context ('global', 'category', 'document')
Tags
Return values
mixed —has_been_saved()
Determine if protection settings have been previously saved for a given context
public
static has_been_saved(string $context[, int|null $object_id = null ]) : bool
Parameters
- $context : string
-
The context ('global', 'category', 'document')
- $object_id : int|null = null
-
The object ID (term_id or post_id)
Tags
Return values
bool —Whether protection settings have been saved before
is_protection_active()
Check if a specific protection type is active
public
static is_protection_active(mixed $data, mixed $protection_type) : bool
Parameters
- $data : mixed
- $protection_type : mixed
Tags
Return values
bool —normalize()
Normalize protection data
public
static normalize(array<string|int, mixed> $data[, string $context = 'global' ][, int|null $object_id = null ][, bool|null $has_been_saved = null ]) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
-
Protection data to normalize
- $context : string = 'global'
-
The context ('global', 'category', 'document')
- $object_id : int|null = null
-
The object ID (term_id or post_id)
- $has_been_saved : bool|null = null
-
Whether data has been previously saved (if null, will be determined automatically)
Tags
Return values
array<string|int, mixed> —Normalized protection data
normalize_saved_data()
Get default protection data
public
static normalize_saved_data(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
-
Protection data to normalize
Tags
Return values
array<string|int, mixed> —Default protection data
render_fieldset()
Render complete protection fieldset
public
static render_fieldset(array<string|int, mixed> $args) : string
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
Tags
Return values
string —HTML output
get_field_name()
Get field name based on context
private
static get_field_name(array<string|int, mixed> $args, string $field_type) : string
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $field_type : string
-
The field type
Tags
Return values
string —The field name
render_document_owner_option()
Render document owner protection option (category context only)
private
static render_document_owner_option(array<string|int, mixed> $args, array<string|int, mixed> $protection_data) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $protection_data : array<string|int, mixed>
-
Current protection data
Tags
Return values
mixed —render_password_option()
Render password protection option and section
private
static render_password_option(array<string|int, mixed> $args, array<string|int, mixed> $protection_data) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $protection_data : array<string|int, mixed>
-
Current protection data
Tags
Return values
mixed —render_password_section()
Render password protection section
private
static render_password_section(array<string|int, mixed> $args, array<string|int, mixed> $passwords, bool $is_visible) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $passwords : array<string|int, mixed>
-
Current password data
- $is_visible : bool
-
Whether the section is visible
Tags
Return values
mixed —render_roles_section()
Render user roles section
private
static render_roles_section(array<string|int, mixed> $args, array<string|int, mixed> $roles, bool $is_visible) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $roles : array<string|int, mixed>
-
Current role data
- $is_visible : bool
-
Whether the section is visible
Tags
Return values
mixed —render_user_option()
Render user protection option and section
private
static render_user_option(array<string|int, mixed> $args, array<string|int, mixed> $protection_data) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $protection_data : array<string|int, mixed>
-
Current protection data
Tags
Return values
mixed —render_user_role_option()
Render user role protection option and section
private
static render_user_role_option(array<string|int, mixed> $args, array<string|int, mixed> $protection_data) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $protection_data : array<string|int, mixed>
-
Current protection data
Tags
Return values
mixed —render_users_section()
Render specific users section
private
static render_users_section(array<string|int, mixed> $args, array<string|int, mixed> $users, bool $is_visible) : mixed
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments
- $users : array<string|int, mixed>
-
Current user data
- $is_visible : bool
-
Whether the section is visible