Methods

get_product_categories()

get_product_categories()

get_category_visibility()

get_category_visibility(  $term_id)

Parameters

$term_id

get_the_category_visibility()

get_the_category_visibility(  $post = null)

Parameters

$post

to_category_visibilities()

to_category_visibilities(  $terms)

Parameters

$terms

get_product_id_for_protection_check()

get_product_id_for_protection_check(  $product)

Parameters

$product

is_protected()

is_protected(array|\Barn2\Plugin\WC_Protected_Categories\Category_Visibility  $categories): boolean|string

Determines whether the supplied category or categories are protected.

Checks the supplied categories including all ancestors of those categories (if any). Returns one of the following values:

  • 'password' - One or more categories is password protected
  • 'user' - One or more categories is protected to specific users
  • 'role' - One or more categories is protected to specific user roles
  • 'private' - One or more categories is private
  • false - All categories are public or at least one category has been 'unlocked' (see below).

The function will return false (i.e. not protected) if all categories including ancestors are public.

It also returns false if at least one protected category has been unlocked - e.g. the correct password has been entered, or the user has the required role (depending on the protection type). In this instance, the category is only considered 'unlocked' only if the there are no child categories of that category which are protected by another means.

The function will always return false (i.e. unlocked) if at least one category is unlocked, regardless of the other categories supplied, even if the other categories are protected.

If two or more protected categories are found, or if one protected category has multiple types of protection, the function will return the first type of protection found, in the following order of precedence: password, private, user, role. This can be controlled using the 'wc_ppc_category_protection_priority_order' filter.

Parameters

array|\Barn2\Plugin\WC_Protected_Categories\Category_Visibility $categories

The category or array of Category_Visibility objects to check.

Returns

boolean|string —

false if not protected, otherwise 'password', 'private', 'user' or 'role' to denote the protection type.

set_password_cookie()

set_password_cookie(  $term_id,  $password)

Parameters

$term_id
$password

get_password_cookie()

get_password_cookie()

get_password_form_heading()

get_password_form_heading()

get_password_form_message()

get_password_form_message()

sanitize_whitespace_for_autop()

sanitize_whitespace_for_autop(string  $text): string

Removes any new line characters and long whitespace sequences (2 or more) from HTML output so that wpautop doesn't mess up the formatting.

Parameters

string $text

The text to sanitize.

Returns

string —

The sanitized text, which can be passed safely to wpautop.

prefixing_protected_categories()

prefixing_protected_categories()

showing_protected_categories()

showing_protected_categories()

get_category_visibility_cache()

get_category_visibility_cache()

update_category_visibility_cache()

update_category_visibility_cache(  $term_visibilities)

Parameters

$term_visibilities

build_protection_for_level()

build_protection_for_level(  $protection,  $category,  $level)

Parameters

$protection
$category
$level