-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathadd-table-list-column.php
50 lines (44 loc) · 1.44 KB
/
add-table-list-column.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
<?php
/*
* Add custom column to the new List Table
*/
class MyCustomColumn extends \Give\Framework\ListTable\ModelColumn {
public static function getId(): string {
return 'my-custom-column';
}
public function getLabel(): string {
return __('My Custom Column', 'textdomain');
}
/*
* This method must return a string that may contains HTML
*/
public function getCellValue($model, $locale = '') {
return sprintf(
'%s %d',
__('Donation ID:', 'textdomain'),
$model->id
);
}
}
function givewp_register_list_table_columns($list_table) {
/*
* Notes:
* ->addColumnBefore('status', new MyCustomColumn()) will add the custom column before a specific one
* ->addColumn(new MyCustomColumn()) will just add the custom column after all others
* ->addColumnAfter('id'' new MyCustomColun()) will add the custom after a specific one
*
* setColumnVisibility method can be ommited in case the custom column doesn't need to be visible at load
*/
$list_table
->addColumnBefore('status', new MyCustomColumn())
->setColumnVisibility(MyCustomColumn::getId(), true);
return $list_table;
}
/*
* Available hooks:
* givewp_donation_forms_list_table
* givewp_donations_list_table
* givewp_donors_list_table
* givewp_subscriptions_list_table
*/
add_filter('givewp_donations_list_table', 'givewp_register_list_table_columns');