PPC_Util

Utility functions for Password Protected Categories.

Tags
author

Barn2 Plugins support@barn2.co.uk

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

COOKIE_PREFIX  = 'wp-postpass_'
OPTION_NAME  = 'ppc_options'
$options  : mixed
default_options()  : mixed
delete_option()  : bool
Remove a PPC option from the database.
display_deprecated_notice()  : void
Helper method to display a styled deprecation notice for categories marked as private.
get_central_login_page_id()  : string
Get the ID number of the central login page.
get_hidden_terms()  : array<string|int, mixed>
Retrieve an array of all hidden terms for the current user. If the user can view private posts (e.g. user is an administrator) then these terms will not be included in the result.
get_login_form_button_text()  : mixed
get_login_form_label()  : mixed
get_login_form_message()  : mixed
get_login_page_title()  : mixed
get_option()  : mixed
Retrive a specific plugin option using the $option key specified.
get_option_name()  : The
Get the option name to use in the "name" attributes for form fields on the plugin settings page.
get_options()  : array<string|int, mixed>
Retrieve the plugin options.
get_pages()  : array<string|int, mixed>
Get an array of pages of the site.
get_password_protected_terms()  : array<string|int, mixed>
Get an array of password protected terms for the specified taxonomies. If no taxonomies passed, retrieve all password protected terms.
get_protectable_taxonomies()  : array<string|int, mixed>
Retrieve a list of all protectable taxonomies from the list of currently registered taxonomies.
get_term_passwords()  : array<string|int, mixed>
Get the list of passwords for the specified term.
get_term_visibility()  : bool|Term_Visibility
Retrieve the Term_Visibility instance for the specified term.
get_term_visibility_cache()  : mixed
get_terms()  : array<string|int, mixed>
Wrapper function to get_terms() to handle parameter change in WP 4.5.
get_the_term_visibility()  : array<string|int, mixed>
Retrive a list of Term_Visibility objects for the specified post.
get_unlocked_term()  : bool|array<string|int, mixed>
Returns the currently unlocked category or term (if any) as an array in the following format:
get_visibility()  : string
Get the visibility for the specified term.
help_tip()  : string
Print an help tooltip.
is_hidden_post()  : bool
Is this a hidden post (i.e. private or password protected)? Defaults to the current post if not specified.
is_protectable_category()  : bool
Are we viewing a category/taxonomy archive page (for any post type) which can be protected by the plugin?
is_protectable_single_post()  : bool
Are we viewing a single post (for any post type) which can be protected by the plugin?
is_protected()  : bool|string
Determines whether the supplied category or categories are protected.
is_protection_empty()  : bool
If the term visibility is set to protected but the protection has no value
is_unlocked_post()  : bool
Determine if the given post is unlocked or has no protection.
merge_form_values()  : array<string|int, mixed>
Merge category login form values with shortcode
replace_tags()  : 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.
save_category_login_page()  : void
Programmatically insert the category login shortcode into the selected central login page.
set_password_cookie()  : mixed
to_term_visibilities()  : mixed
update_option()  : bool
Programmatically update an option value.
update_options()  : mixed
Update the plugin options.
update_term_visibility_cache()  : mixed
build_protection_for_level()  : mixed
sanitize_tooltip()  : string
Sanitize the html content of a tooltip.

Constants

public mixed COOKIE_PREFIX = 'wp-postpass_'

OPTION_NAME

public mixed OPTION_NAME = 'ppc_options'

Properties

$options

private static mixed $options = false

Methods

default_options()

public static default_options() : mixed
Return values
mixed

delete_option()

Remove a PPC option from the database.

public static delete_option(string $key[, mixed $bypass_cap = false ]) : bool
Parameters
$key : string
$bypass_cap : mixed = false
Return values
bool

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

Get the ID number of the central login page.

public static get_central_login_page_id() : string
Return values
string

get_hidden_terms()

Retrieve an array of all hidden terms for the current user. If the user can view private posts (e.g. user is an administrator) then these terms will not be included in the result.

public static get_hidden_terms(array<string|int, mixed> $taxonomies[,  $fields = 'all' ]) : array<string|int, mixed>

If the user has previously unlocked a term, then this will be excluded from the result.

Parameters
$taxonomies : array<string|int, mixed>

A list of taxonomies for which to retrieve the hidden terms

$fields : = 'all'

The fields to retrieve. @see get_terms()

Return values
array<string|int, mixed>

An array of WP_Term objects or an empty array if none found

get_login_form_button_text()

public static get_login_form_button_text() : mixed
Return values
mixed

get_login_form_label()

public static get_login_form_label() : mixed
Return values
mixed

get_login_form_message()

public static get_login_form_message() : mixed
Return values
mixed

get_login_page_title()

public static get_login_page_title() : mixed
Return values
mixed

get_option()

Retrive a specific plugin option using the $option key specified.

public static get_option(string $option) : mixed
Parameters
$option : string

The option key

Return values
mixed

The option if set, or the default option

get_option_name()

Get the option name to use in the "name" attributes for form fields on the plugin settings page.

public static get_option_name(string $option_key) : The
Parameters
$option_key : string

The option key to format

Return values
The

formatted option name

get_options()

Retrieve the plugin options.

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

The plugin options array

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>

get_password_protected_terms()

Get an array of password protected terms for the specified taxonomies. If no taxonomies passed, retrieve all password protected terms.

public static get_password_protected_terms([array<string|int, mixed> $taxonomies = [] ]) : array<string|int, mixed>
Parameters
$taxonomies : array<string|int, mixed> = []

An array of taxonomy names (optional)

Return values
array<string|int, mixed>

An array of password protected terms (WP_Term objects)

get_protectable_taxonomies()

Retrieve a list of all protectable taxonomies from the list of currently registered taxonomies.

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

A list of taxonomy names which can be protected by the plugin

get_term_passwords()

Get the list of passwords for the specified term.

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

The term ID for the term.

$single : bool = false

Whether to return a single value.

Return values
array<string|int, mixed>

The passwords array. Will be an empty array if there are no passwords.

get_term_visibility()

Retrieve the Term_Visibility instance for the specified term.

public static get_term_visibility(WP_Term $term) : bool|Term_Visibility
Parameters
$term : WP_Term

The term to retrieve the visibility for

Return values
bool|Term_Visibility

get_term_visibility_cache()

public static get_term_visibility_cache() : mixed
Return values
mixed

get_terms()

Wrapper function to get_terms() to handle parameter change in WP 4.5.

public static get_terms([string $args = [] ]) : array<string|int, mixed>
Parameters
$args : string = []

The $args to pass to get_terms()

Tags
global

string $wp_version

Return values
array<string|int, mixed>

An array of WP_Term objects or an empty array if none found

get_the_term_visibility()

Retrive a list of Term_Visibility objects for the specified post.

public static get_the_term_visibility([int|WP_Post $post = null ][, string $taxonomy = false ]) : array<string|int, mixed>

If no post is specified, the current post object is used.

Parameters
$post : int|WP_Post = null

The post ID or post object

$taxonomy : string = false

The taxonomy to retrive visibilites for, or false to retrieve all applicable taxonomies

Return values
array<string|int, mixed>

An array of Term_Visibility objects

get_unlocked_term()

Returns the currently unlocked category or term (if any) as an array in the following format:

public static get_unlocked_term() : bool|array<string|int, mixed>

array( 'term_id' => 12 'taxonomy' => 'category' )

Return values
bool|array<string|int, mixed>

The taxonomy array or false if no terms are currently unlocked.

get_visibility()

Get the visibility for the specified term.

public static get_visibility(int $term_id) : string
Parameters
$term_id : int

The term ID for the term.

Return values
string

The visibility - one of 'public', 'password' or 'private', 'protected'.

help_tip()

Print an help tooltip.

public static help_tip(string $tip[, bool $allow_html = false ]) : string
Parameters
$tip : string

help tooltip.

$allow_html : bool = false
Return values
string

is_hidden_post()

Is this a hidden post (i.e. private or password protected)? Defaults to the current post if not specified.

public static is_hidden_post([int|WP_Post $post = null ]) : bool
Parameters
$post : int|WP_Post = null

Post ID or WP_Post object

Return values
bool

is_protectable_category()

Are we viewing a category/taxonomy archive page (for any post type) which can be protected by the plugin?

public static is_protectable_category() : bool

Returns the same as is_category() || is_tax() but with an extra check for WooCommerce product categories. If WooCommerce Protected Categories is installed, product categories are excluded from this check.

Return values
bool

is_protectable_single_post()

Are we viewing a single post (for any post type) which can be protected by the plugin?

public static is_protectable_single_post() : bool

Returns the same as is_singular() but with an extra check for WooCommerce products. If WooCommerce Protected Categories is installed, products are excluded from this check.

Return values
bool

is_protected()

Determines whether the supplied category or categories are protected.

public static is_protected(array<string|int, mixed>|Term_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 'ppc_category_protection_priority_order' filter.

Parameters
$categories : array<string|int, mixed>|Term_Visibility

The category or array of Term_Visibility objects to check.

Return values
bool|string

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

is_protection_empty()

If the term visibility is set to protected but the protection has no value

public static is_protection_empty(int $term_id) : bool
Parameters
$term_id : int
Return values
bool

if the protection level is set for this term

is_unlocked_post()

Determine if the given post is unlocked or has no protection.

public static is_unlocked_post([int|WP_Post $post = null ]) : bool
Parameters
$post : int|WP_Post = null
Return values
bool

merge_form_values()

Merge category login form values with shortcode

public static merge_form_values(mixed $shortcode_values) : array<string|int, mixed>
Parameters
$shortcode_values : mixed
Tags
since
2.1.22
Return values
array<string|int, mixed>

replace_tags()

public static replace_tags(mixed $text) : mixed
Parameters
$text : 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.

save_category_login_page()

Programmatically insert the category login shortcode into the selected central login page.

public static save_category_login_page(string $value, string $old_value) : void

When an old value is found, remove the shortcode from the previous page.

Parameters
$value : string

new page id

$old_value : string

old page id

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

to_term_visibilities()

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

update_option()

Programmatically update an option value.

public static update_option([string $key = '' ][, mixed $value = false ][, bool $bypass_cap = false ]) : bool
Parameters
$key : string = ''
$value : mixed = false
$bypass_cap : bool = false
Return values
bool

update_options()

Update the plugin options.

public static update_options(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

The complete list of updated options.

Return values
mixed

update_term_visibility_cache()

public static update_term_visibility_cache(mixed $term_visibilities) : mixed
Parameters
$term_visibilities : 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

sanitize_tooltip()

Sanitize the html content of a tooltip.

private static sanitize_tooltip(string $var) : string
Parameters
$var : string

toolip content

Return values
string

Search results