| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Tag Groups |
| 5 |
* |
| 6 |
* @author Christoph Amthor |
| 7 |
* @copyright 2018 Christoph Amthor (@ Chatty Mango, chattymango.com) |
| 8 |
* @license GPL-3.0+ |
| 9 |
*/ |
| 10 |
|
| 11 |
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, Squiz.Scope.MethodScope.Missing, PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
| 12 |
if (! class_exists('TagGroups_Utilities')) { |
| 13 |
/** |
| 14 |
* |
| 15 |
*/ |
| 16 |
class TagGroups_Utilities |
| 17 |
{ |
| 18 |
/** |
| 19 |
* Returns the first element of an array without changing the original array |
| 20 |
* |
| 21 |
* @param array $array |
| 22 |
* @return mixed |
| 23 |
*/ |
| 24 |
public static function get_first_element($array = array()) |
| 25 |
{ |
| 26 |
|
| 27 |
if (! is_array($array)) { |
| 28 |
TagGroups_Error::log('[Tag Groups] Parameter supplied to get_first_element() must be an array.'); |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
return reset($array); |
| 33 |
} |
| 34 |
|
| 35 |
public static function is_free_plan() |
| 36 |
{ |
| 37 |
|
| 38 |
return !self::is_premium_plan(); |
| 39 |
} |
| 40 |
|
| 41 |
public static function is_premium_plan() |
| 42 |
{ |
| 43 |
|
| 44 |
return defined('TAG_GROUPS_LOADED_BY_PRO') && TAG_GROUPS_LOADED_BY_PRO |
| 45 |
|| defined('TAG_GROUPS_PRO_FILE') |
| 46 |
|| defined('TAG_GROUPS_PRO_VERSION'); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Turns a string into a valid JS function name, preserving as much as possible uniqueness |
| 51 |
* |
| 52 |
* @since 1.26.1 |
| 53 |
* |
| 54 |
* @param string $raw |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
static function create_js_fn_name($raw) |
| 58 |
{ |
| 59 |
|
| 60 |
return str_replace('-', '', sanitize_html_class($raw)); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* Execute wp_die() or die(), depending whether we are running tests |
| 66 |
* That way we prevent that other plugins add own output after AJAX responses |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
static function die() |
| 71 |
{ |
| 72 |
|
| 73 |
if (defined('CM_UNIT_TESTING')) { |
| 74 |
wp_die(); |
| 75 |
} else { |
| 76 |
die(); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
} |
| 83 |
|