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

display_deprecated_notice()  : void
Helper method to display a styled deprecation notice for categories marked as private.
get_category_visibility()  : mixed
get_login_page_id()  : int
Returns the login page ID.
get_login_page_mode()  : string
Returns the login page mode.
get_pages()  : array<string|int, mixed>
Get an array of pages of the site.
get_password_cookie()  : mixed
get_password_form_heading()  : mixed
get_password_form_message()  : mixed
get_plugin_settings_list()  : array<string|int, mixed>
Get the list of settings for the admin panel.
get_product_categories()  : mixed
get_product_id_for_protection_check()  : mixed
get_term_passwords()  : string|array<string|int, mixed>
Get term passwords list.
get_the_category_visibility()  : mixed
get_when_logged_out_mode()  : string
Returns the redirect mode for guest users.
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

display_deprecated_notice()

Helper method to display a styled deprecation notice for categories marked as private.

public static display_deprecated_notice() : void

We need the inline styling because WP moves notices below the 1st h1 tag automatically.

Return values
void

get_category_visibility()

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

get_login_page_id()

Returns the login page ID.

public static get_login_page_id() : int

Includes backwards compat for the previous redirect option.

Return values
int

get_login_page_mode()

Returns the login page mode.

public static get_login_page_mode() : string

Possible values: 'wplogin', 'page'.

Return values
string

get_pages()

Get an array of pages of the site.

public static get_pages([bool $exclude_empty = false ]) : array<string|int, mixed>
Parameters
$exclude_empty : bool = false

whether or not an empty option should be displayed within the dropdown.

Return values
array<string|int, 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_plugin_settings_list()

Get the list of settings for the admin panel.

public static get_plugin_settings_list(Plugin $plugin) : array<string|int, mixed>
Parameters
$plugin : Plugin
Return values
array<string|int, 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_term_passwords()

Get term passwords list.

public static get_term_passwords(string|int $term_id) : string|array<string|int, mixed>
Parameters
$term_id : string|int
Return values
string|array<string|int, mixed>

get_the_category_visibility()

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

get_when_logged_out_mode()

Returns the redirect mode for guest users.

public static get_when_logged_out_mode() : string

This method is used within the "handle_user_protection" method of the Template_Handlers class and mapped to handle backwards compat of the if/else statements in the class.

Return values
string

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