generated from Pierre-Lannoy/wp-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
73 lines (69 loc) · 1.65 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Global functions.
*
* @package Functions
* @author Pierre Lannoy <https://pierre.lannoy.fr/>.
* @since 3.4.1
*/
if ( ! function_exists('decalog_get_psr_log_version') ) {
/**
* Get the needed version of PSR-3.
*
* @return int The PSR-3 needed version.
* @since 4.0.0
*/
function decalog_get_psr_log_version() {
$required = 1;
if ( ! defined( 'DECALOG_PSR_LOG_VERSION') ) {
define( 'DECALOG_PSR_LOG_VERSION', 'V1' );
}
switch ( strtolower( DECALOG_PSR_LOG_VERSION ) ) {
case 'v3':
$required = 3;
break;
case 'auto':
if ( class_exists( '\Psr\Log\NullLogger') ) {
$reflection = new \ReflectionMethod(\Psr\Log\NullLogger::class, 'log');
foreach ( $reflection->getParameters() as $param ) {
if ( 'message' === $param->getName() ) {
if ( str_contains($param->getType() ?? '', '|') ) {
$required = 3;
}
}
}
}
}
return $required;
}
}
/**
* Verify if a timestamp is a TRUE unix timestamp or based on monotonic clock.
* If it's based on monotonic clock, fix it.
*
* Patch done for supporting APCu > 5.1.21
* @see https://stackoverflow.com/questions/74227993/php-apcu-monotonic-ttl-clock-change-please-confirm-my-understanding-of-timesta
*
* @since 3.4.1
*
* @param integer $value A timestamp.
* @return integer A true unix timestamp.
*/
function apcm_unix_ts( $value ) {
if ( $value > 946681201 ) {
return $value;
}
$time = time();
if ( ! function_exists( 'hrtime' ) ) {
return $time;
}
$hr = hrtime();
if ( ! is_array( $hr ) ) {
return $time;
}
$hrtime = (int) $hr[0];
if ( $hrtime < $value ) {
return $time;
}
return $time - $hrtime + $value;
}