Category_Visibility extends Abstract_Visibility implements Visibility_Interface
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
Interfaces, Classes and Traits
Table of Contents
- $object_type : string
- The type of object this visibility is for.
- $data_object : object
- The object to retrieve the visibility
- $document_owner : bool
- The document owner can access the document.
- $object_id : int
- The object id.
- $passwords : array<string|int, mixed>
- Array of passwords that can be used to access the document.
- $roles : array<string|int, mixed>
- Array of roles that can access the document.
- $users : array<string|int, mixed>
- Array of users that can access the document.
- $visibility : string
- The visibility level.
- $ancestors : array<string|int, Category_Visibility>
- The ancestors of this term.
- $global_visibility : Global_Visibility
- The global visibility instance.
- __construct() : mixed
- Constructor.
- ancestor_terms() : array<string|int, Category_Visibility>
- Retrieve the ancestor terms for this term. Lazy loaded so it only hits the database once.
- correct_password_entered() : bool
- Check the correct password has been entered.
- current_user_allowed_by_id() : bool
- Is the current user allowed access to this category by ID?
- current_user_allowed_by_role() : bool
- Is the current user allowed access to this category by role?
- get_data_object() : object
- Retrieve the object.
- get_document_owner() : array<string|int, mixed>|false
- Get the document owner for this category.
- get_object_id() : int
- Retrieve the object id.
- get_object_type() : string
- Retrieve the object type.
- get_passwords() : array<string|int, mixed>
- Retrieve this term's passwords.
- get_protection_data() : array<string|int, mixed>
- Retrieve all the protection data for this term.
- get_protection_types() : mixed
- Retrieve all the active protection types for this document.
- get_roles() : array<string|int, mixed>
- Retrieve the list of roles for this term.
- get_term_id() : int
- Retrieve the term ID.
- get_users() : array<string|int, mixed>
- Retrieve the list of users for this term.
- get_visibility() : string
- Retrieve the visibility level for this term.
- has_document_owner_protection() : bool
- Does this object have document owner protection?
- has_password_protection() : bool
- Does this object have password protection?
- has_protection() : bool
- Does this object have any form of protection?
- has_role_protection() : bool
- Does this object have role protection?
- has_user_protection() : bool
- Does this object have user protection?
- initialize_visbility_data() : mixed
- Initialize the visibility data for this term.
- is_hidden() : bool
- Is this category hidden?
- is_inherited() : bool
- Is this visibility level inherited?
- 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_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 document?
- is_role_protected() : bool
- Is this category protected by user role?
- is_unlocked() : bool
- Is this object unlocked by password, role, or user?
- is_unlocked_by_password() : bool
- Is this object unlocked by password?
- is_unlocked_by_role() : bool
- Is this object unlocked by role?
- is_unlocked_by_user() : bool
- Is this category unlocked by the current user?
- is_user_protected() : bool
- Is this category protected by user (i.e. only specific users have access)?
- all_ancestor_terms_inherited() : bool
- Checks whether all ancestor terms are inherited.
- to_term() : WP_Term|array<string|int, mixed>|false
- Convert a term ID to a WP_Term object.
Properties
$object_type
The type of object this visibility is for.
public
string
$object_type
= 'category'
Tags
$data_object
The object to retrieve the visibility
protected
object
$data_object
Tags
$document_owner
The document owner can access the document.
protected
bool
$document_owner
= false
Tags
$object_id
The object id.
protected
int
$object_id
Tags
$passwords
Array of passwords that can be used to access the document.
protected
array<string|int, mixed>
$passwords
= []
Tags
$roles
Array of roles that can access the document.
protected
array<string|int, mixed>
$roles
= []
Tags
$users
Array of users that can access the document.
protected
array<string|int, mixed>
$users
= []
Tags
$visibility
The visibility level.
protected
string
$visibility
Tags
$ancestors
The ancestors of this term.
private
array<string|int, Category_Visibility>
$ancestors
= null
Tags
$global_visibility
The global visibility instance.
private
Global_Visibility
$global_visibility
= null
Tags
Methods
__construct()
Constructor.
public
__construct(WP_Term $term) : mixed
Parameters
- $term : WP_Term
-
The term to retrieve the visibility for
Tags
Return values
mixed —ancestor_terms()
Retrieve the ancestor terms for this term. Lazy loaded so it only hits the database once.
public
ancestor_terms() : array<string|int, Category_Visibility>
Tags
Return values
array<string|int, Category_Visibility> —An array of Category_Visibility objects (one for each ancestor), or an empty array if there are no ancestors
correct_password_entered()
Check the correct password has been entered.
public
correct_password_entered() : bool
Tags
Return values
bool —current_user_allowed_by_id()
Is the current user allowed access to this category by ID?
public
current_user_allowed_by_id() : bool
We include the document owner here if the option is checked.
Tags
Return values
bool —true if the current user is allowed access.
current_user_allowed_by_role()
Is the current user allowed access to this category by role?
public
current_user_allowed_by_role() : bool
Tags
Return values
bool —true if the current user has one of the required roles.
get_data_object()
Retrieve the object.
public
get_data_object() : object
Tags
Return values
object —get_document_owner()
Get the document owner for this category.
public
get_document_owner() : array<string|int, mixed>|false
Tags
Return values
array<string|int, mixed>|false —The document owner, or false if none set
get_object_id()
Retrieve the object id.
public
get_object_id() : int
Tags
Return values
int —get_object_type()
Retrieve the object type.
public
get_object_type() : string
Tags
Return values
string —get_passwords()
Retrieve this term's passwords.
public
get_passwords() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of passwords, or an empty array if none set
get_protection_data()
Retrieve all the protection data for this term.
public
get_protection_data() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_protection_types()
Retrieve all the active protection types for this document.
public
get_protection_types() : mixed
Tags
Return values
mixed —get_roles()
Retrieve the list of roles for this term.
public
get_roles() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_term_id()
Retrieve the term ID.
public
get_term_id() : int
Tags
Return values
int —The term ID
get_users()
Retrieve the list of users for this term.
public
get_users() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_visibility()
Retrieve the visibility level for this term.
public
get_visibility() : string
Tags
Return values
string —has_document_owner_protection()
Does this object have document owner protection?
public
has_document_owner_protection() : bool
Tags
Return values
bool —true if document owner protected
has_password_protection()
Does this object have password protection?
public
has_password_protection() : bool
Tags
Return values
bool —true if password protected
has_protection()
Does this object have any form of protection?
public
has_protection() : bool
Tags
Return values
bool —has_role_protection()
Does this object have role protection?
public
has_role_protection() : bool
Tags
Return values
bool —true if role protected
has_user_protection()
Does this object have user protection?
public
has_user_protection() : bool
Tags
Return values
bool —true if user protected
initialize_visbility_data()
Initialize the visibility data for this term.
public
initialize_visbility_data() : mixed
Tags
Return values
mixed —is_hidden()
Is this category hidden?
public
is_hidden([bool $include_ancestors = true ]) : bool
Parameters
- $include_ancestors : bool = true
-
Whether to check the ancestor terms as well
Tags
Return values
bool —true if hidden, false if not
is_inherited()
Is this visibility level inherited?
public
is_inherited() : bool
Tags
Return values
bool —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
Tags
Return values
bool —true if password protected, 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 $include_ancestors = true ]) : bool
If $include_ancestors is true, and this category is not protected, its ancestor categories and global protection will also be checked. The function halts once the first protected ancestor is found.
Parameters
- $include_ancestors : bool = true
-
Whether to check the ancestor categories as well (if any).
Tags
Return values
bool —true if this category is protected.
is_public()
Is this a public document?
public
is_public() : bool
Tags
Return values
bool —true if the document is public, false if not
is_role_protected()
Is this category protected by user role?
public
is_role_protected([bool $include_ancestors = false ]) : bool
Parameters
- $include_ancestors : bool = false
-
Whether to check the ancestors as well (if any).
Tags
Return values
bool —true if this category is role protected.
is_unlocked()
Is this object unlocked by password, role, or user?
public
is_unlocked() : bool
Tags
Return values
bool —true if unlocked.
is_unlocked_by_password()
Is this object unlocked by password?
public
is_unlocked_by_password() : bool
Tags
Return values
bool —true if unlocked, false otherwise
is_unlocked_by_role()
Is this object unlocked by role?
public
is_unlocked_by_role() : bool
Tags
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
Tags
Return values
bool —true if user protected and the current user is allowed access.
is_user_protected()
Is this category protected by user (i.e. only specific users have access)?
public
is_user_protected([bool $include_ancestors = false ]) : bool
Parameters
- $include_ancestors : bool = false
-
Whether to check the ancestors as well (if any).
Tags
Return values
bool —true if this category is user protected.
all_ancestor_terms_inherited()
Checks whether all ancestor terms are inherited.
private
all_ancestor_terms_inherited() : bool
Tags
Return values
bool —to_term()
Convert a term ID to a WP_Term object.
private
to_term(mixed $term_id) : WP_Term|array<string|int, mixed>|false
Parameters
- $term_id : mixed
-
The term ID to convert
Tags
Return values
WP_Term|array<string|int, mixed>|false —The WP_Term object, or false if not found