| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\Framework\Support; |
| 4 |
|
| 5 |
use RuntimeException; |
| 6 |
|
| 7 |
class Util |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Returns a comma-separated string or array of functions that |
| 11 |
* have been called to get to the current point in code. |
| 12 |
* |
| 13 |
* @param string $ignoreClass |
| 14 |
* @param integer $skipFrames |
| 15 |
* @param boolean $pretty |
| 16 |
* @return string|array |
| 17 |
* @see https://developer.wordpress.org/reference/functions/wp_debug_backtrace_summary/ |
| 18 |
*/ |
| 19 |
public static function debugBacktraceSummary( |
| 20 |
$ignoreClass = null, |
| 21 |
$skipFrames = 0, |
| 22 |
$pretty = true |
| 23 |
) { |
| 24 |
return wp_debug_backtrace_summary( |
| 25 |
$ignoreClass, $skipFrames, $pretty |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @param string|array $value |
| 31 |
* @return mixed |
| 32 |
* @see https://developer.wordpress.org/reference/functions/wp_slash |
| 33 |
*/ |
| 34 |
public static function addslashes($value) |
| 35 |
{ |
| 36 |
return wp_slash($value); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Convert an absolute file path to URL. |
| 41 |
* |
| 42 |
* @param string $filePath |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
public static function pathToUrl($filePath = '', $checkFile = false) |
| 46 |
{ |
| 47 |
if ($checkFile && !file_exists($filePath)) { |
| 48 |
throw new RuntimeException("File does not exist: {$filePath}"); |
| 49 |
} |
| 50 |
|
| 51 |
$url = str_replace( |
| 52 |
wp_normalize_path(untrailingslashit(ABSPATH)), |
| 53 |
site_url(), |
| 54 |
wp_normalize_path($filePath) |
| 55 |
); |
| 56 |
|
| 57 |
return esc_url_raw($url); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get the user locale. |
| 62 |
* |
| 63 |
* @param int|null $userId |
| 64 |
* @return \FluentCommunity\Framework\Support\Locale |
| 65 |
*/ |
| 66 |
public static function getLocale($userId = null) |
| 67 |
{ |
| 68 |
return Locale::init($userId); |
| 69 |
} |
| 70 |
} |
| 71 |
|