functions.php in NodeInfo(2) 2.2.0, at includes/functions.php
| 1 | <?php |
| 2 | function nodeinfo_get_active_users( $duration = '1 month ago' ) { |
| 3 | // get all distinct authors that have published a post in the last 30 days |
| 4 | $posts = get_posts( |
| 5 | array( |
| 6 | 'post_type' => 'post', |
| 7 | 'post_status' => 'publish', |
| 8 | 'orderby' => 'post_count', |
| 9 | 'order' => 'DESC', |
| 10 | 'posts_per_page' => 4, |
| 11 | 'date_query' => array( |
| 12 | array( |
| 13 | 'after' => $duration, |
| 14 | ), |
| 15 | ), |
| 16 | ) |
| 17 | ); |
| 18 | |
| 19 | if ( ! $posts ) { |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | // get all distinct ID from $posts |
| 24 | return count( |
| 25 | array_unique( |
| 26 | wp_list_pluck( |
| 27 | $posts, |
| 28 | 'post_author' |
| 29 | ) |
| 30 | ) |
| 31 | ); |
| 32 | } |
| 33 |