forked from codepress/admin-columns-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acp-quick_add-saved.php
51 lines (41 loc) · 1.26 KB
/
acp-quick_add-saved.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
<?php
/**
* The acp/quick_add/saved action fires after a new item is created using Quick Add.
*/
/**
* @param int $id
* @param AC\ListScreen $list_screen
*
* @return void
*/
function acp_quick_add_saved( $id, AC\ListScreen $list_screen ) {
// Place your code here
}
add_action( 'acp/quick_add/saved', 'acp_quick_add_saved' );
/**
* Add the filtered term to the newly created post (with the use of quick add)
*/
add_action( 'acp/quick_add/saved', function ( $post_id, AC\ListScreen $list_screen ) {
$event_post_type = 'my_post_type';
$event_taxonomy = 'my_taxaonomy';
if ( $event_post_type !== $list_screen->get_key() ) {
return;
}
// Filter request variables
$request = new AC\Request();
$rules = $request->get_query()->get( 'ac-rules' );
if ( ! $rules ) {
return;
}
// Contains the applied smart filters and associated column
$rules = json_decode( $rules )->rules;
foreach ( $rules as $rule ) {
// Get the associated column
$column = $list_screen->get_column_by_name( $rule->id );
// Check if the rule (with the use of the associated column) is a taxonomy
if ( $column && $event_taxonomy === $column->get_taxonomy() ) {
// Write filtered term to post
wp_set_post_terms( $post_id, (int) $rule->value, $event_taxonomy, true );
}
}
}, 10, 2 );