Util

Utility functions for WooCommerce Protected Categories.

Tags
author

Barn2 Plugins info@barn2.co.uk

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

get_category_visibility()  : mixed
get_password_cookie()  : mixed
get_password_form_heading()  : mixed
get_password_form_message()  : mixed
get_product_categories()  : mixed
get_product_id_for_protection_check()  : mixed
get_the_category_visibility()  : mixed
is_protected()  : bool|string
Determines whether the supplied category or categories are protected.
prefixing_protected_categories()  : mixed
sanitize_whitespace_for_autop()  : 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.
set_password_cookie()  : mixed
showing_protected_categories()  : mixed
to_category_visibilities()  : mixed
build_protection_for_level()  : mixed
get_category_visibility_cache()  : mixed
update_category_visibility_cache()  : mixed

Methods

get_category_visibility()

public static get_category_visibility(mixed $term_id) : mixed
Parameters
$term_id : mixed
Return values
mixed
public static get_password_cookie() : mixed
Return values
mixed

get_password_form_heading()

public static get_password_form_heading() : mixed
Return values
mixed

get_password_form_message()

public static get_password_form_message() : mixed
Return values
mixed

get_product_categories()

public static get_product_categories() : mixed
Return values
mixed

get_product_id_for_protection_check()

public static get_product_id_for_protection_check(mixed $product) : mixed
Parameters
$product : mixed
Return values
mixed

get_the_category_visibility()

public static get_the_category_visibility([mixed $post = null ]) : mixed
Parameters
$post : mixed = null
Return values
mixed

is_protected()

Determines whether the supplied category or categories are protected.

public static is_protected(array<string|int, mixed>|Category_Visibility $categories) : bool|string

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
$categories : array<string|int, mixed>|Category_Visibility

The category or array of Category_Visibility objects to check.

Return values
bool|string

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

prefixing_protected_categories()

public static prefixing_protected_categories() : mixed
Return values
mixed

sanitize_whitespace_for_autop()

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

public static sanitize_whitespace_for_autop(string $text) : string
Parameters
$text : string

The text to sanitize.

Return values
string

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

public static set_password_cookie(mixed $term_id, mixed $password) : mixed
Parameters
$term_id : mixed
$password : mixed
Return values
mixed

showing_protected_categories()

public static showing_protected_categories() : mixed
Return values
mixed

to_category_visibilities()

public static to_category_visibilities(mixed $terms) : mixed
Parameters
$terms : mixed
Return values
mixed

build_protection_for_level()

private static build_protection_for_level(mixed &$protection, mixed $category, mixed $level) : mixed
Parameters
$protection : mixed
$category : mixed
$level : mixed
Return values
mixed

get_category_visibility_cache()

private static get_category_visibility_cache() : mixed
Return values
mixed

update_category_visibility_cache()

private static update_category_visibility_cache(mixed $term_visibilities) : mixed
Parameters
$term_visibilities : mixed
Return values
mixed

Search results