Term_Visibility
This class represents a term (WP_Term instance) with various functions to test for its visibility.
It's constructed from the WP_Term object rather than extending it.
Tags
Table of Contents
- $term : mixed
- $visibility : mixed
- $ancestors : mixed
- $passwords : mixed
- $roles : mixed
- $users : mixed
- __construct() : mixed
- ancestors() : array<string|int, mixed>
- Retrieve the ancestor terms for this term. Lazy loaded so it only hits the database once.
- check_password() : bool|WP_Term
- Is the password valid for this term?
- correct_password_entered() : bool
- Check the correct password has been entered.
- get_passwords() : mixed
- get_roles() : mixed
- get_users() : mixed
- get_visibility() : mixed
- has_password_protection() : bool
- Does this category have password protection?
- has_private_protection() : bool
- Does this category have private protection?
- has_protection() : bool
- Does this category have password, role or user protection?
- has_role_protection() : bool
- Does this category have role protection?
- has_user_protection() : bool
- Does this category have user protection?
- is_hidden() : mixed
- is_password_protected() : bool
- Is this a password protected term? If $include_ancestors is set, ancestor terms will also be checked and it will return true if any ancestor is password protected.
- is_private() : bool
- Is this a private term? If $include_ancestors is set, ancestor terms will also be checked and it will return true if any ancestor is private.
- is_protected() : bool
- Is this category protected? 'Protected' can mean a password is required, or the category is locked to specific roles or users.
- is_public() : bool
- Is this a public? If $include_ancestors is set, ancestor terms will also be checked and it will return true if all ancestors are also public.
- is_role_protected() : bool
- Is this category protected by user role?
- is_unlocked() : bool
- Is this category unlocked by password, role, user, or for private access?
- is_unlocked_by_role() : bool
- Is this category unlocked by role?
- is_unlocked_by_user() : bool
- Is this category unlocked by the current user?
- is_unlocked_for_private_access() : bool
- Is this category private and unlocked by the current user?
- is_user_protected() : bool
- Is this category protected by user (i.e. only specific users have access)?
- _get_passwords() : array<string|int, mixed>
- Retrieve this term's passwords.
- current_user_allowed_by_id() : mixed
- current_user_allowed_by_role() : mixed
- current_user_allowed_private_access() : mixed
- is_unlocked_by_password() : bool
- Is this term unlocked?
- to_term() : mixed
Properties
$term
public
mixed
$term
$visibility
public
mixed
$visibility
= 'public'
$ancestors
private
mixed
$ancestors
= null
$passwords
private
mixed
$passwords
= []
$roles
private
mixed
$roles
= []
$users
private
mixed
$users
= []
Methods
__construct()
public
__construct(WP_Term $term) : mixed
Parameters
- $term : WP_Term
Return values
mixed —ancestors()
Retrieve the ancestor terms for this term. Lazy loaded so it only hits the database once.
public
ancestors() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of Term_Visibility objects (one for each ancestor), or an empty array if there are no ancestors
check_password()
Is the password valid for this term?
public
check_password(string $password[, boolea $include_ancestors = true ]) : bool|WP_Term
Parameters
- $password : string
-
The password to check
- $include_ancestors : boolea = true
-
Whether to check the password against ancestor terms
Return values
bool|WP_Term —The term the password is valid for, or false if not a valid password
correct_password_entered()
Check the correct password has been entered.
public
correct_password_entered() : bool
Return values
bool —get_passwords()
public
get_passwords() : mixed
Return values
mixed —get_roles()
public
get_roles() : mixed
Return values
mixed —get_users()
public
get_users() : mixed
Return values
mixed —get_visibility()
public
get_visibility() : mixed
Return values
mixed —has_password_protection()
Does this category have password protection?
public
has_password_protection() : bool
Return values
bool —true if password protected
has_private_protection()
Does this category have private protection?
public
has_private_protection() : bool
Return values
bool —true if private protection set
has_protection()
Does this category have password, role or user protection?
public
has_protection() : bool
Return values
bool —true if protected
has_role_protection()
Does this category have role protection?
public
has_role_protection() : bool
Return values
bool —true if role protected
has_user_protection()
Does this category have user protection?
public
has_user_protection() : bool
Return values
bool —true if user protected
is_hidden()
public
is_hidden([mixed $include_ancestors = true ]) : mixed
Parameters
- $include_ancestors : mixed = true
Return values
mixed —is_password_protected()
Is this a password protected term? If $include_ancestors is set, ancestor terms will also be checked and it will return true if any ancestor is password protected.
public
is_password_protected([bool $include_ancestors = true ]) : bool
Parameters
- $include_ancestors : bool = true
-
Whether to check the ancestor terms as well
Return values
bool —true if password protected, false if not
is_private()
Is this a private term? If $include_ancestors is set, ancestor terms will also be checked and it will return true if any ancestor is private.
public
is_private([bool $include_ancestors = true ]) : bool
Parameters
- $include_ancestors : bool = true
-
Whether to check the ancestor terms as well
Return values
bool —true if private, false if not
is_protected()
Is this category protected? 'Protected' can mean a password is required, or the category is locked to specific roles or users.
public
is_protected([bool $check_ancestors = false ]) : bool
This function will return false for private categories, and there is a separate function (is_private) to check for private level access.
If $check_ancestors is true, and this category is not protected, its ancestor categories will also be checked. The function halts once the first protected ancestor is found. *
Parameters
- $check_ancestors : bool = false
-
Whether to check the ancestor categories as well (if any).
Return values
bool —true if this category is protected.
is_public()
Is this a public? If $include_ancestors is set, ancestor terms will also be checked and it will return true if all ancestors are also public.
public
is_public([bool $include_ancestors = true ]) : bool
Parameters
- $include_ancestors : bool = true
-
Whether to check the ancestor terms as well
Return values
bool —true if the term is public, false if not
is_role_protected()
Is this category protected by user role?
public
is_role_protected([bool $check_ancestors = false ]) : bool
Parameters
- $check_ancestors : bool = false
-
Whether to check the ancestor categories as well (if any).
Return values
bool —true if this category is role protected.
is_unlocked()
Is this category unlocked by password, role, user, or for private access?
public
is_unlocked() : bool
Return values
bool —true if unlocked.
is_unlocked_by_role()
Is this category unlocked by role?
public
is_unlocked_by_role() : bool
Return values
bool —true if role protected and the current user has one of the required roles.
is_unlocked_by_user()
Is this category unlocked by the current user?
public
is_unlocked_by_user() : bool
Return values
bool —true if user protected and the current user is allowed access.
is_unlocked_for_private_access()
Is this category private and unlocked by the current user?
public
is_unlocked_for_private_access() : bool
Return values
bool —true if unlocked for private access.
is_user_protected()
Is this category protected by user (i.e. only specific users have access)?
public
is_user_protected([bool $check_ancestors = false ]) : bool
Parameters
- $check_ancestors : bool = false
-
Whether to check the ancestor categories as well (if any).
Return values
bool —true if this category is user protected.
_get_passwords()
Retrieve this term's passwords.
private
_get_passwords() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of passwords, or an empty array if none set
current_user_allowed_by_id()
private
current_user_allowed_by_id() : mixed
Return values
mixed —current_user_allowed_by_role()
private
current_user_allowed_by_role() : mixed
Return values
mixed —current_user_allowed_private_access()
private
current_user_allowed_private_access() : mixed
Return values
mixed —is_unlocked_by_password()
Is this term unlocked?
private
is_unlocked_by_password() : bool
Return values
bool —true if unlocked, false otherwise
to_term()
private
to_term(mixed $term_id) : mixed
Parameters
- $term_id : mixed