class-admin.php
4 years ago
class-columns.php
4 years ago
class-counter.php
4 years ago
class-crawler-detect.php
4 years ago
class-cron.php
4 years ago
class-dashboard.php
4 years ago
class-frontend.php
4 years ago
class-functions.php
4 years ago
class-query.php
4 years ago
class-settings-api.php
4 years ago
class-settings.php
4 years ago
class-update.php
4 years ago
class-widgets.php
4 years ago
functions.php
4 years ago
class-functions.php
66 lines
| 1 | <?php |
| 2 | // exit if accessed directly |
| 3 | if ( ! defined( 'ABSPATH' ) ) |
| 4 | exit; |
| 5 | |
| 6 | /** |
| 7 | * Post_Views_Counter_Functions class. |
| 8 | * |
| 9 | * @class Post_Views_Counter_Functions |
| 10 | */ |
| 11 | class Post_Views_Counter_Functions { |
| 12 | |
| 13 | /** |
| 14 | * Class constructor. |
| 15 | * |
| 16 | * @return void |
| 17 | */ |
| 18 | public function __construct() {} |
| 19 | |
| 20 | /** |
| 21 | * Get post types available for counting. |
| 22 | * |
| 23 | * @return array |
| 24 | */ |
| 25 | public function get_post_types() { |
| 26 | $post_types = []; |
| 27 | |
| 28 | // get public post types |
| 29 | foreach ( get_post_types( [ 'public' => true ], 'objects', 'and' ) as $key => $post_type ) { |
| 30 | $post_types[$key] = $post_type->labels->name; |
| 31 | } |
| 32 | |
| 33 | // remove bbPress replies |
| 34 | if ( class_exists( 'bbPress' ) && isset( $post_types['reply'] ) ) |
| 35 | unset( $post_types['reply'] ); |
| 36 | |
| 37 | // filter post types |
| 38 | $post_types = apply_filters( 'pvc_available_post_types', $post_types ); |
| 39 | |
| 40 | // sort post types alphabetically |
| 41 | asort( $post_types, SORT_STRING ); |
| 42 | |
| 43 | return $post_types; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get all user roles. |
| 48 | * |
| 49 | * @global object $wp_roles |
| 50 | * @return array |
| 51 | */ |
| 52 | public function get_user_roles() { |
| 53 | global $wp_roles; |
| 54 | |
| 55 | $roles = []; |
| 56 | |
| 57 | foreach ( apply_filters( 'editable_roles', $wp_roles->roles ) as $role => $details ) { |
| 58 | $roles[$role] = translate_user_role( $details['name'] ); |
| 59 | } |
| 60 | |
| 61 | // sort user roles alphabetically |
| 62 | asort( $roles, SORT_STRING ); |
| 63 | |
| 64 | return $roles; |
| 65 | } |
| 66 | } |