PluginProbe
Posts Table with Search & Sort / 1.3.4
Posts Table with Search & Sort v1.3.4
1.4.13 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 40 releases
posts-data-table / lib / Util.php

Util.php in Posts Table with Search & Sort 1.3.4, at lib/Util.php

153 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Barn2\PTS_Lib;
3
4 /**
5 * Utility functions for Barn2 plugins.
6 *
7 * @package Barn2\barn2-lib
8 * @author Barn2 Plugins <support@barn2.co.uk>
9 * @license GPL-3.0
10 * @copyright Barn2 Media Ltd
11 * @version 1.4.8
12 */
13 class Util {
14
15 const EDD_STORE_URL = 'https://barn2.co.uk';
16 const KNOWLEDGE_BASE_URL = 'https://barn2.co.uk';
17
18 /**
19 * Formats a HTML link to a path on the Barn2 site.
20 *
21 * @param string $relative_path The path relative to https://barn2.co.uk.
22 * @param string $link_text The link text.
23 * @param boolean $new_tab Whether to open the link in a new tab.
24 * @return string The hyperlink.
25 */
26 public static function barn2_link( $relative_path, $link_text = '', $new_tab = false ) {
27 if ( empty( $link_text ) ) {
28 $link_text = __( 'Read more', 'posts-data-table' );
29 }
30 return self::format_link( self::barn2_url( $relative_path ), esc_html( $link_text ), $new_tab );
31 }
32
33 public static function barn2_url( $relative_path ) {
34 return esc_url( 'https://barn2.co.uk/' . ltrim( $relative_path, '/' ) );
35 }
36
37 public static function format_link( $url, $link_text, $new_tab = false ) {
38 return sprintf( '%1$s%2$s</a>', self::format_link_open( $url, $new_tab ), $link_text );
39 }
40
41 public static function format_link_open( $url, $new_tab = false ) {
42 $target = $new_tab ? ' target="_blank"' : '';
43 return sprintf( '<a href="%1$s"%2$s>', esc_url( $url ), $target );
44 }
45
46 public static function format_store_url( $path = '' ) {
47 return self::EDD_STORE_URL . '/' . ltrim( $path, ' /' );
48 }
49
50 public static function format_store_link( $path, $link_text, $new_tab = true ) {
51 return self::format_link( self::format_store_url( $path ), $link_text, $new_tab );
52 }
53
54 public static function format_store_link_open( $path, $new_tab = true ) {
55 return self::format_link_open( self::format_store_url( $path ), $new_tab );
56 }
57
58 public static function get_add_to_cart_url( $download_id, $price_id = 0, $discount_code = '' ) {
59 $args = array(
60 'edd_action' => 'add_to_cart',
61 'download_id' => (int) $download_id
62 );
63 if ( $price_id ) {
64 $args['edd_options[price_id]'] = (int) $price_id;
65 }
66 if ( $discount_code ) {
67 $args['discount'] = $discount_code;
68 }
69
70 return self::format_store_url( '?' . http_build_query( $args ) );
71 }
72
73 public static function is_admin() {
74 return is_admin();
75 }
76
77 public static function is_front_end() {
78 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
79 }
80
81 public static function is_woocommerce_active() {
82 return class_exists( '\WooCommerce' );
83 }
84
85 public static function is_product_addons_active() {
86 return class_exists( '\WC_Product_Addons' );
87 }
88
89 public static function is_edd_active() {
90 return class_exists( '\Easy_Digital_Downloads' );
91 }
92
93 public static function is_acf_active() {
94 return class_exists( '\ACF' );
95 }
96
97 public static function is_protected_categories_active() {
98 if ( function_exists( '\Barn2\Plugin\WC_Protected_Categories\wpc' ) ) {
99 return \Barn2\Plugin\WC_Protected_Categories\wpc()->has_valid_license();
100 } else {
101 if ( class_exists( '\WC_Protected_Categories_Plugin' ) ) {
102 if ( method_exists( \WC_Protected_Categories_Plugin::instance(), 'has_valid_license' ) ) {
103 return \WC_Protected_Categories_Plugin::instance()->has_valid_license();
104 }
105 return true;
106 }
107 }
108 return false;
109 }
110
111 public static function is_product_table_active() {
112 if ( function_exists( '\Barn2\Plugin\WC_Product_Table\wpt' ) ) {
113 return \Barn2\Plugin\WC_Product_Table\wpt()->has_valid_license();
114 } elseif ( class_exists( '\WC_Product_Table_Plugin' ) ) {
115 if ( method_exists( \WC_Product_Table_Plugin::instance(), 'has_valid_license' ) ) {
116 return \WC_Product_Table_Plugin::instance()->has_valid_license();
117 }
118 return true;
119 }
120 return false;
121 }
122
123 public static function is_quick_view_pro_active() {
124 if ( function_exists( '\Barn2\Plugin\WC_Quick_View_Pro\wqv' ) ) {
125 return \Barn2\Plugin\WC_Quick_View_Pro\wqv()->has_valid_license();
126 } else {
127 if ( class_exists( '\Barn2\Plugin\WC_Quick_View_Pro\Quick_View_Plugin' ) ) {
128 return \Barn2\Plugin\WC_Quick_View_Pro\Quick_View_Plugin::instance()->has_valid_license();
129 }
130 return false;
131 }
132 }
133
134 public static function get_script_suffix() {
135 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
136 }
137
138 public static function register_services( $services ) {
139 array_map( function( $service ) {
140 if ( ( $service instanceof Conditional ) && ! $service->is_required() ) {
141 return;
142 }
143 if ( $service instanceof Registerable ) {
144 $service->register();
145 }
146 if ( $service instanceof Schedulable ) {
147 $service->schedule();
148 }
149 }, $services );
150 }
151
152 }
153