| 1 |
<?php |
| 2 |
/** |
| 3 |
* Helper functions for NodeInfo. |
| 4 |
* |
| 5 |
* @package Nodeinfo |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Nodeinfo; |
| 9 |
|
| 10 |
/** |
| 11 |
* Gets the count of active users within a duration. |
| 12 |
* |
| 13 |
* @param string $duration The duration to check (e.g., '1 month ago'). |
| 14 |
* @return int The number of active users. |
| 15 |
*/ |
| 16 |
function get_active_users( $duration = '1 month ago' ) { |
| 17 |
$posts = \get_posts( |
| 18 |
array( |
| 19 |
'post_type' => 'post', |
| 20 |
'post_status' => 'publish', |
| 21 |
'orderby' => 'post_count', |
| 22 |
'order' => 'DESC', |
| 23 |
'posts_per_page' => 4, |
| 24 |
'date_query' => array( |
| 25 |
array( |
| 26 |
'after' => $duration, |
| 27 |
), |
| 28 |
), |
| 29 |
) |
| 30 |
); |
| 31 |
|
| 32 |
if ( ! $posts ) { |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
return \count( |
| 37 |
\array_unique( |
| 38 |
\wp_list_pluck( |
| 39 |
$posts, |
| 40 |
'post_author' |
| 41 |
) |
| 42 |
) |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Gets the masked WordPress version (major.minor only). |
| 48 |
* |
| 49 |
* @return string The masked version. |
| 50 |
*/ |
| 51 |
function get_masked_version() { |
| 52 |
$version = \get_bloginfo( 'version' ); |
| 53 |
// Strip RC/beta suffixes. |
| 54 |
$version = \preg_replace( '/-.*$/', '', $version ); |
| 55 |
$version = \explode( '.', $version ); |
| 56 |
$version = \array_slice( $version, 0, 2 ); |
| 57 |
|
| 58 |
return \implode( '.', $version ); |
| 59 |
} |
| 60 |
|