-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·85 lines (73 loc) · 2.73 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
Plugin Name: Slimstat Analytics - Extended Overview
Description: Add custom columns to the User Overview widget and export file.
Version: 1.0
Author: Slimstat Analytics
Author URI: https://wp-slimstat.com/
*/
class wp_slimstat_extended_overview {
public static $columns = array(
'company' => array(
'order' => '25', // Default columns are defined as Username=20, Full Name=40, Email=60, etc... By setting this value=25, will place this column in between Username and Full Name
'label' => 'Company',
'class' => 'manage-column',
'type' => 'varchar',
'in_csv' => true, // Switch to determine if this column should be added to the CSV file
'in_widget' => true // Switch to determine if this column should be added to User Overview widget
),
'segment' => array(
'order' => '45',
'label' => 'Segment',
'class' => 'manage-column',
'type' => 'varchar',
'in_csv' => true,
'in_widget' => false
)
);
public static function init(){
if ( !class_exists( 'wp_slimstat' ) ) {
return true;
}
// Define extra column names to the CSV export
add_filter( 'slimstat_column_names', array( __CLASS__, 'add_column_names' ) );
// Append columns to the table: this is separate from the filter here above because
// you may want to show a different set of columns in the admin compared to the CSV export
add_filter( 'slimstat_user_overview_table_columns', array( __CLASS__, 'add_table_columns' ), 20, 1 );
// Append custom values to the dataset
add_filter( 'slimstat_user_overview_get_data', array( __CLASS__, 'get_data' ) );
}
public static function add_column_names( $_columns = array() ) {
foreach ( self::$columns as $a_id => $a_column ) {
if ( !empty( $a_column[ 'in_csv' ] ) ) {
$_columns[ $a_id ] = array( $a_column[ 'label' ], $a_column[ 'type' ] );
}
}
return $_columns;
}
public static function add_table_columns( $_columns = array() ) {
foreach ( self::$columns as $a_id => $a_column ) {
if ( !empty( $a_column[ 'in_widget' ] ) ) {
$_columns[ $a_column[ 'order' ] ] = array(
'id' => $a_id,
'label' => $a_column[ 'label' ],
'class' => $a_column[ 'class' ]
);
}
}
return $_columns;
}
public static function get_data( $_rows = array() ) {
foreach ( $_rows as $i => $a_row ) {
// Retrieve the value to append to this user; you can use $_rows[ $i ][ 'username' ] or any other values already available in the data set
$_rows[ $i ][ 'company' ] = $_rows[ $i ][ 'username' ] . "'s company";
$_rows[ $i ][ 'segment' ] = $_rows[ $i ][ 'username' ] . "'s segment";
}
return $_rows;
}
}
// end of class declaration
// Bootstrap
if ( function_exists( 'add_action' ) ) {
add_action( 'plugins_loaded', array( 'wp_slimstat_extended_overview', 'init' ), 10 );
}