Views
in package
Display page and post views on admin pages.
Tags
Table of Contents
Constants
- COUNT_KEY = 'pnet_views_count'
- Meta key for view counts.
Properties
- $instances : array<string|int, object>
- The array of instances of this class and sub-classes.
Methods
- add_views_column() : array<string|int, string>
- Adds views column to the admin page.
- get_instance() : object
- Creates and/or returns the instance of this class.
- populate_views_column() : void
- Returns post view for the column on the admin page.
- sortable_views_column() : array<string|int, string>
- Make view column sortable.
- sortable_views_column_orderby() : void
- Modify query to include views sortable column.
- views_count() : int
- Returns view counter for a post.
- __construct() : void
- Initialise the class.
Constants
COUNT_KEY
Meta key for view counts.
protected
string
COUNT_KEY
= 'pnet_views_count'
Tags
Properties
$instances
The array of instances of this class and sub-classes.
protected
static array<string|int, object>
$instances
= array()
Tags
Methods
add_views_column()
Adds views column to the admin page.
public
add_views_column(array<string|int, string> $columns) : array<string|int, string>
Parameters
- $columns : array<string|int, string>
-
Array of column name => label pairs.
Tags
Return values
array<string|int, string> —The modified columns array.
get_instance()
Creates and/or returns the instance of this class.
public
static get_instance() : object
Tags
Return values
object —The instance of this class.
populate_views_column()
Returns post view for the column on the admin page.
public
populate_views_column(string $column_name, int $post_id) : void
Parameters
- $column_name : string
-
Name of the custom column.
- $post_id : int
-
ID of the current post.
Tags
sortable_views_column()
Make view column sortable.
public
sortable_views_column(array<string|int, string> $columns) : array<string|int, string>
Parameters
- $columns : array<string|int, string>
-
Array of column name => label pairs.
Tags
Return values
array<string|int, string> —The modified columns array.
sortable_views_column_orderby()
Modify query to include views sortable column.
public
sortable_views_column_orderby(object $query) : void
Parameters
- $query : object
-
Query object, passed by reference.
Tags
views_count()
Returns view counter for a post.
public
views_count(int $post_id) : int
Parameters
- $post_id : int
-
ID of post or page.
Tags
Return values
int —Count of page views, or false if no post id.
__construct()
Initialise the class.
protected
__construct() : void