Util

Utility functions for Barn2 plugins.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

version
1.5.3

Table of Contents

BARN2_URL  = 'https://barn2.com'
EDD_STORE_URL  = 'https://barn2.com'
KNOWLEDGE_BASE_URL  = 'https://barn2.com'
barn2_kses_post()  : string
Similar to wp_kses_post but with added support for <img> srcset and sizes attributes.
barn2_link()  : string
Formats a HTML link to a path on the Barn2 site.
barn2_url()  : mixed
create_page()  : int
Create a page and store the ID in an option. (adapted from WooCommerce)
format_barn2_link_open()  : mixed
format_link()  : mixed
format_link_open()  : mixed
format_store_link()  : mixed
format_store_link_open()  : mixed
format_store_url()  : mixed
Format a Barn2 store URL.
get_add_to_cart_url()  : mixed
get_script_dependencies()  : array<string|int, mixed>
Retrieves an array of internal WP dependencies for bundled JS files.
get_script_suffix()  : string
Get the script suffix used when registering/queuing JS and CSS, based on SCRIPT_DEBUG.
is_acf_active()  : bool
Returns true if Advanced Custom Fields or Advanced Custom Fields Pro is active.
is_admin()  : bool
Returns true if the current request is a WP admin request.
is_barn2_plugin_active()  : bool
Returns true if the plugin instance returned by $function is an active Barn2 plugin.
is_edd_active()  : bool
Returns true if EDD is active.
is_fast_cart_active()  : bool
Returns true if WooCommerce Fast Cart is active and has a valid license.
is_front_end()  : bool
Returns true if the current request is a front-end request, e.g. viewing a page or post.
is_product_addons_active()  : bool
Returns true if WooCommerce Product Addons is active.
is_product_table_active()  : bool
Returns true if WooCommerce Product Table is active and has a valid license.
is_protected_categories_active()  : bool
Returns true if WooCommerce Protected Categories is active and has a valid license.
is_quick_view_pro_active()  : bool
Returns true if WooCommerce Quick View Pro is active and has a valid license.
is_restaurant_ordering_active()  : bool
Returns true if WooCommerce Restaurant Ordering is active and has a valid license.
is_woocommerce_active()  : bool
Returns true if WooCommerce is active.
register_services()  : mixed
Register the Services in the given array.
store_url()  : mixed
Format a Barn2 store URL.

Constants

BARN2_URL

public mixed BARN2_URL = 'https://barn2.com'

EDD_STORE_URL

public mixed EDD_STORE_URL = 'https://barn2.com'

KNOWLEDGE_BASE_URL

public mixed KNOWLEDGE_BASE_URL = 'https://barn2.com'

Methods

barn2_kses_post()

Similar to wp_kses_post but with added support for <img> srcset and sizes attributes.

public static barn2_kses_post(string $string) : string
Parameters
$string : string

The string to sanitize.

Tags
see
https://core.trac.wordpress.org/ticket/29807
Return values
string

The sanitized string.

Formats a HTML link to a path on the Barn2 site.

public static barn2_link(string $relative_path[, string $link_text = '' ][, bool $new_tab = false ]) : string
Parameters
$relative_path : string

The path relative to https://barn2.com.

$link_text : string = ''

The link text.

$new_tab : bool = false

Whether to open the link in a new tab.

Return values
string

The hyperlink.

barn2_url()

public static barn2_url(mixed $relative_path) : mixed
Parameters
$relative_path : mixed
Return values
mixed

create_page()

Create a page and store the ID in an option. (adapted from WooCommerce)

public static create_page(mixed $slug[, string $option = '' ][, string $page_title = '' ][, string $page_content = '' ], int $post_parent) : int
Parameters
$slug : mixed

Slug for the new page.

$option : string = ''

Option name to store the page's ID.

$page_title : string = ''

(default: '') Title for the new page.

$page_content : string = ''

(default: '') Content for the new page.

$post_parent : int

(default: 0) Parent for the new page.

Return values
int

page ID.

public static format_barn2_link_open(mixed $relative_path[, mixed $new_tab = false ]) : mixed
Parameters
$relative_path : mixed
$new_tab : mixed = false
Return values
mixed
public static format_link(mixed $url, mixed $link_text[, mixed $new_tab = false ]) : mixed
Parameters
$url : mixed
$link_text : mixed
$new_tab : mixed = false
Return values
mixed
public static format_link_open(mixed $url[, mixed $new_tab = false ]) : mixed
Parameters
$url : mixed
$new_tab : mixed = false
Return values
mixed
public static format_store_link(mixed $relative_path, mixed $link_text[, mixed $new_tab = true ]) : mixed
Parameters
$relative_path : mixed
$link_text : mixed
$new_tab : mixed = true
Return values
mixed
public static format_store_link_open(mixed $relative_path[, mixed $new_tab = true ]) : mixed
Parameters
$relative_path : mixed
$new_tab : mixed = true
Return values
mixed

format_store_url()

Format a Barn2 store URL.

public static format_store_url(string $relative_path) : mixed
Parameters
$relative_path : string

The relative path

Tags
deprecated
1.5

Renamed store_url

Return values
mixed

get_add_to_cart_url()

public static get_add_to_cart_url(mixed $download_id, mixed $price_id[, mixed $discount_code = '' ]) : mixed
Parameters
$download_id : mixed
$price_id : mixed
$discount_code : mixed = ''
Return values
mixed

get_script_dependencies()

Retrieves an array of internal WP dependencies for bundled JS files.

public static get_script_dependencies(Plugin $plugin, string $filename) : array<string|int, mixed>
Parameters
$plugin : Plugin
$filename : string
Return values
array<string|int, mixed>

get_script_suffix()

Get the script suffix used when registering/queuing JS and CSS, based on SCRIPT_DEBUG.

public static get_script_suffix() : string
Return values
string

Returns '' or '.min'

is_acf_active()

Returns true if Advanced Custom Fields or Advanced Custom Fields Pro is active.

public static is_acf_active() : bool
Return values
bool

true if active

is_admin()

Returns true if the current request is a WP admin request.

public static is_admin() : bool
Return values
bool

true if the current page is in WP admin

is_barn2_plugin_active()

Returns true if the plugin instance returned by $function is an active Barn2 plugin.

public static is_barn2_plugin_active(string $function) : bool
Parameters
$function : string

The function that returns the plugin instance

Tags
since
1.5.3
Return values
bool

true if active

is_edd_active()

Returns true if EDD is active.

public static is_edd_active() : bool
Return values
bool

true if active

is_fast_cart_active()

Returns true if WooCommerce Fast Cart is active and has a valid license.

public static is_fast_cart_active() : bool
Tags
deprecated
1.5.3

Use is_barn2_plugin_active( '\Barn2\Plugin\WC_Fast_Cart\wfc' ) instead

Return values
bool

true if active

is_front_end()

Returns true if the current request is a front-end request, e.g. viewing a page or post.

public static is_front_end() : bool
Return values
bool

true if the current page is front-end

is_product_addons_active()

Returns true if WooCommerce Product Addons is active.

public static is_product_addons_active() : bool
Return values
bool

true if active

is_product_table_active()

Returns true if WooCommerce Product Table is active and has a valid license.

public static is_product_table_active() : bool
Tags
deprecated
1.5.3

Use is_barn2_plugin_active( '\Barn2\Plugin\WC_Product_Table\wpt' ) instead

Return values
bool

true if active

is_protected_categories_active()

Returns true if WooCommerce Protected Categories is active and has a valid license.

public static is_protected_categories_active() : bool
Tags
deprecated
1.5.3

Use is_barn2_plugin_active( '\Barn2\Plugin\WC_Protected_Categories\wpc' ) instead

Return values
bool

true if active

is_quick_view_pro_active()

Returns true if WooCommerce Quick View Pro is active and has a valid license.

public static is_quick_view_pro_active() : bool
Tags
deprecated
1.5.3

Use is_barn2_plugin_active( '\Barn2\Plugin\WC_Quick_View_Pro\wqv' ) instead

Return values
bool

true if active

is_restaurant_ordering_active()

Returns true if WooCommerce Restaurant Ordering is active and has a valid license.

public static is_restaurant_ordering_active() : bool
Tags
deprecated
1.5.3

Use is_barn2_plugin_active( '\Barn2\Plugin\WC_Restaurant_Ordering\wro' ) instead

Return values
bool

true if active

is_woocommerce_active()

Returns true if WooCommerce is active.

public static is_woocommerce_active() : bool
Return values
bool

true if active

register_services()

Register the Services in the given array.

public static register_services(array<string|int, mixed> $services) : mixed
Parameters
$services : array<string|int, mixed>

The services to register

Return values
mixed

store_url()

Format a Barn2 store URL.

public static store_url(string $relative_path) : mixed
Parameters
$relative_path : string

The relative path

Return values
mixed

Search results