Helper.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Backend view helper |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Backend_View_Helper { |
| 17 | |
| 18 | /** |
| 19 | * Prepare phrase or label |
| 20 | * |
| 21 | * @param string $phrase |
| 22 | * @param mixed $... |
| 23 | * |
| 24 | * @return string |
| 25 | * |
| 26 | * @access protected |
| 27 | */ |
| 28 | public static function preparePhrase($phrase) { |
| 29 | //prepare search patterns |
| 30 | $num = func_num_args(); |
| 31 | $search = ($num > 1 ? array_fill(0, ($num - 1) * 2, null) : array()); |
| 32 | |
| 33 | array_walk($search, 'AAM_Backend_View_Helper::prepareWalk'); |
| 34 | |
| 35 | $replace = array(); |
| 36 | foreach (array_slice(func_get_args(), 1) as $key) { |
| 37 | array_push($replace, "<{$key}>", "</{$key}>"); |
| 38 | } |
| 39 | |
| 40 | //localize the phase first |
| 41 | return preg_replace($search, $replace, __($phrase, AAM_KEY), 1); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * |
| 46 | * @param string $value |
| 47 | * @param type $index |
| 48 | */ |
| 49 | public static function prepareWalk(&$value, $index) { |
| 50 | $value = '/\\' . ($index % 2 ? ']' : '[') . '/'; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get default Access Policy |
| 55 | * |
| 56 | * @global string $wp_version |
| 57 | * |
| 58 | * @return string |
| 59 | * |
| 60 | * @access public |
| 61 | * @static |
| 62 | * @since v5.7.3 |
| 63 | */ |
| 64 | public static function getDefaultPolicy() { |
| 65 | global $wp_version; |
| 66 | |
| 67 | $aamVersion = AAM_Core_API::version(); |
| 68 | |
| 69 | return <<<EOT |
| 70 | { |
| 71 | "Version": "1.0.0", |
| 72 | "Dependency": { |
| 73 | "wordpress": ">=$wp_version", |
| 74 | "advanced-access-manager": ">=$aamVersion" |
| 75 | }, |
| 76 | "Statement": [ |
| 77 | { |
| 78 | "Effect": "deny", |
| 79 | "Resource": [], |
| 80 | "Action": [] |
| 81 | } |
| 82 | ] |
| 83 | } |
| 84 | EOT; |
| 85 | } |
| 86 | |
| 87 | } |