| @@ -31,12 +31,16 @@ | ||
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | 33 | function logtivity_dd($dump) |
| 34 | 34 | { |
| 35 | + if (!defined('WP_DEBUG') || !WP_DEBUG) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 35 | 39 | echo '<pre>'; |
| 36 | - var_export($dump); | |
| 40 | + echo esc_html(wp_json_encode($dump, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | |
| 37 | 41 | echo '</pre>'; |
| 38 | - die(); | |
| 42 | + wp_die(); | |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | /** |
| 42 | 46 | * Global function for easy use in themes/plugins for logging custom actions |
| @@ -64,9 +68,16 @@ | ||
| 64 | 68 | * @return string |
| 65 | 69 | */ |
| 66 | 70 | function logtivity_view(string $fileName, array $vars = []): string |
| 67 | 71 | { |
| 68 | - extract($vars); | |
| 72 | + $options = $vars['options'] ?? []; | |
| 73 | + $log = $vars['log'] ?? null; | |
| 74 | + $logs = $vars['logs'] ?? []; | |
| 75 | + $message = $vars['message'] ?? null; | |
| 76 | + $meta = $vars['meta'] ?? null; | |
| 77 | + $hasNextPage = $vars['hasNextPage'] ?? null; | |
| 78 | + $display = $vars['display'] ?? false; | |
| 79 | + $logo = $vars['logo'] ?? true; | |
| 69 | 80 | unset($vars); |
| 70 | 81 | |
| 71 | 82 | ob_start(); |
| 72 | 83 | |
| @@ -137,15 +148,30 @@ | ||
| 137 | 148 | * @return bool |
| 138 | 149 | */ |
| 139 | 150 | function logtivity_is_production(): bool |
| 140 | 151 | { |
| 141 | - return logtivity_get_production_app_url() == logtivity_get_app_url() | |
| 142 | - || logtivity_get_production_api_url() == logtivity_get_api_url(); | |
| 152 | + return logtivity_get_app_url() === logtivity_get_production_app_url() | |
| 153 | + && logtivity_get_api_url() === logtivity_get_production_api_url(); | |
| 143 | 154 | } |
| 144 | 155 | |
| 145 | 156 | /** |
| 157 | + * True when exactly one of the app/api URLs has been overridden away from | |
| 158 | + * production. This is a configuration error: the two endpoints must belong | |
| 159 | + * to the same environment. | |
| 160 | + * | |
| 146 | 161 | * @return bool |
| 147 | 162 | */ |
| 163 | + function logtivity_url_environment_mismatch(): bool | |
| 164 | + { | |
| 165 | + $appIsProduction = logtivity_get_app_url() === logtivity_get_production_app_url(); | |
| 166 | + $apiIsProduction = logtivity_get_api_url() === logtivity_get_production_api_url(); | |
| 167 | + | |
| 168 | + return $appIsProduction !== $apiIsProduction; | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * @return bool | |
| 173 | + */ | |
| 148 | 174 | function logtivity_has_site_url_changed(): bool |
| 149 | 175 | { |
| 150 | 176 | $hash = (new Logtivity_Options())->urlHash(); |
| 151 | 177 | |
| @@ -176,9 +202,10 @@ | ||
| 176 | 202 | */ |
| 177 | 203 | function logtivity_get_capabilities(): array |
| 178 | 204 | { |
| 179 | 205 | $capabilities = []; |
| 180 | - if ($roles = wp_roles()) { | |
| 206 | + $roles = wp_roles(); | |
| 207 | + if ($roles) { | |
| 181 | 208 | foreach ($roles->roles as $role) { |
| 182 | 209 | $capabilities = array_merge($capabilities, $role['capabilities']); |
| 183 | 210 | } |
| 184 | 211 | } |
| @@ -219,9 +246,9 @@ | ||
| 219 | 246 | case 'object': |
| 220 | 247 | $value = get_object_vars($value); |
| 221 | 248 | // fall through to array type |
| 222 | 249 | case 'array': |
| 223 | - return print_r($value, true); | |
| 250 | + return wp_json_encode($value, JSON_UNESCAPED_SLASHES) ?: ''; | |
| 224 | 251 | |
| 225 | 252 | case 'boolean': |
| 226 | 253 | return $value ? 'True' : 'False'; |
| 227 | 254 | |