forked from codepress/admin-columns-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacp-editing-value.php
42 lines (35 loc) · 1.09 KB
/
acp-editing-value.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
<?php
/**
* This hook allows you to alter the value that is retrieved for editing before it is displayed in the editable.
*/
/**
* @param mixed $value
* @param int $id
* @param AC\Column $column
*
* @return mixed
*/
function acp_editing_value_example_usage( $value, $id, AC\Column $column ) {
return $value;
}
add_filter( 'acp/editing/value', 'acp_editing_value_example_usage', 10, 3 );
// Or anonymous function
add_filter( 'acp/editing/view', function ( $value, $id, AC\Column $column ) {
return $value;
}, 10, 3 );
/**
* Example to get a nested value from an associative array. You need to parse it back when saving the value with the hook `acp/editing/save_value`
*
* @param mixed $value
* @param int $id
* @param AC\Column $column
*
* @return mixed
*/
function acp_editing_value_get_nested_value( $value, $id, AC\Column $column ) {
if ( $column instanceof AC\Column\Customfield && 'my_custom_field_key' === $column->get_meta_key() ) {
$value = $value['sub_key'];
}
return $value;
}
add_filter( 'acp/editing/value', 'acp_editing_value_get_nested_value', 10, 3 );