Category_Visibility

This class represents a WooCommerce category with various functions to test its visibility.

Tags
author

Barn2 Plugins info@barn2.co.uk

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$ancestors  : mixed
$passwords  : mixed
$roles  : mixed
$term_id  : mixed
$users  : mixed
$visibility  : mixed
__construct()  : mixed
ancestors()  : array<string|int, mixed>
Get the ancestors for this category as an array of Category_Visibility objects.
check_password()  : bool|int
Checks if the supplied password is valid for this category. If the password is valid, it returns the term_id (an integer) for the category the password is valid for.
get_passwords()  : mixed
get_roles()  : mixed
get_term_id()  : 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_password_protected()  : bool
Is this category password protected?
is_private()  : bool
Is this category private? A private category is one that can only be viewed by users with the 'read_private_products' capability.
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 category 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_password()  : bool
Is this category unlocked by password?
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)?
correct_password_entered()  : bool
Returns true if this category has had the correct password entered by the current user. The category password cookie is checked, and if it matches any one of the passwords for this category, then it returns true, otherwise returns false.
current_user_allowed_by_id()  : mixed
current_user_allowed_by_role()  : mixed
current_user_allowed_private_access()  : mixed

Properties

Methods

__construct()

public __construct(mixed $term_id) : mixed
Parameters
$term_id : mixed
Return values
mixed

ancestors()

Get the ancestors for this category as an array of Category_Visibility objects.

public ancestors() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of Category_Visibility objects or an empty array if no ancestors.

check_password()

Checks if the supplied password is valid for this category. If the password is valid, it returns the term_id (an integer) for the category the password is valid for.

public check_password(string $password[, bool $check_ancestors = true ]) : bool|int
Parameters
$password : string

The password to check

$check_ancestors : bool = true

Whether to check passwords against ancestor categories as well.

Return values
bool|int

The term ID the password is valid for, or false if not valid.

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_password_protected()

Is this category password protected?

public is_password_protected([bool $check_ancestors = false ]) : bool

If $check_ancestors is true, and this category is not password protected, the ancestors will also be checked. The function halts once the first password 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 password protected.

is_private()

Is this category private? A private category is one that can only be viewed by users with the 'read_private_products' capability.

public is_private([bool $check_ancestors = false ]) : bool

If $check_ancestors is true, and this category is not private, its ancestor categories will also be checked. The function halts once the first private ancestor is found.

Parameters
$check_ancestors : bool = false

Whether to check the ancestors as well.

Return values
bool

true if private.

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 category public?

public is_public([bool $check_ancestors = false ]) : bool

If $check_ancestors is true, and this category is public, all ancestor categories will also be checked. If any are not public, then this function returns false.

Parameters
$check_ancestors : bool = false

Whether the check the ancestors as well.

Return values
bool

true if public.

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_password()

Is this category unlocked by password?

public is_unlocked_by_password() : bool
Return values
bool

true if password protected and the correct password has been entered.

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.

correct_password_entered()

Returns true if this category has had the correct password entered by the current user. The category password cookie is checked, and if it matches any one of the passwords for this category, then it returns true, otherwise returns false.

private correct_password_entered() : bool
Return values
bool

true if the correct password has been entered.

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

Search results