-
Notifications
You must be signed in to change notification settings - Fork 0
/
acp-column-custom_author.php
executable file
·102 lines (76 loc) · 2.59 KB
/
acp-column-custom_author.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* --------------------------------------------
* This column is for the PRO version only.
* This adds editing and sorting to the column.
* --------------------------------------------
*/
class ACP_Column_custom_author extends AC_Column_custom_author
implements ACP_Column_EditingInterface, ACP_Column_SortingInterface {
public function editing() {
return new ACP_Editing_Model_custom_author( $this );
}
public function sorting() {
return new ACP_Sorting_Model_custom_author( $this );
}
}
/**
* Editing class. Adds editing functionality to the column.
*/
class ACP_Editing_Model_custom_author extends ACP_Editing_Model {
/**
* Editing view settings
*
* @return array Editable settings
*/
public function get_view_settings() {
// available types: text, textarea, media, float, togglable, select, select2_dropdown and select2_tags
$settings = array(
'type' => 'text',
);
// (Optional) Only applies to type: togglable, select, select2_dropdown and select2_tags
// $settings['options'] = array( 'value_1', 'value_2', 'etc.' );
// (Optional) If a selector is provided, editable will be delegated to the specified targets
// $settings['js']['selector'] = 'a.my-class';
// (Optional) Only applies to the type 'select2_dropdown'. Populates the available select2 dropdown values through ajax.
// Ajax callback used is 'get_editable_ajax_options()'.
// $settings['ajax_populate'] = true;
return $settings;
}
/**
* Saves the value after using inline-edit
*
* @param int $id Object ID
* @param mixed $value Value to be saved
*/
public function save( $id, $value ) {
// Store the value that has been entered with inline-edit
// For example: update_post_meta( $id, '_my_custom_field_example', $value );
}
}
/**
* Sorting class. Adds sorting functionality to the column.
*/
class ACP_Sorting_Model_custom_author extends ACP_Sorting_Model {
/**
* (Optional) Put all the sorting logic here. You can remove this function if you want to sort by raw value only.
*
* @return array
*/
public function get_sorting_vars() {
$values = array();
// Loops through all the available post/user/comment id's
foreach ( $this->strategy->get_results() as $id ) {
// Start editing here.
// Put all the column logic here to retrieve the value you need
// For example: $value = get_post_meta( $id, '_my_custom_field_example', true );
$value = $this->column->get_raw_value( $id );
// Stop editing.
$values[ $id ] = $value;
}
// Sorts the array and return all id's to the main query
return array(
'ids' => $this->sort( $values ),
);
}
}