-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathQuickEdit.php
95 lines (74 loc) · 2.21 KB
/
QuickEdit.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
<?php
namespace AC\Screen;
use AC\ListScreenRepository\Storage;
use AC\Registerable;
use AC\ScreenController;
use AC\Table\LayoutPreference;
use AC\Table\PrimaryColumnFactory;
use AC\Type\ListScreenId;
class QuickEdit implements Registerable
{
/**
* @var Storage
*/
private $storage;
/**
* @var LayoutPreference
*/
private $preference;
private $primary_column_factory;
public function __construct(
Storage $storage,
LayoutPreference $preference,
PrimaryColumnFactory $primary_column_factory
) {
$this->storage = $storage;
$this->preference = $preference;
$this->primary_column_factory = $primary_column_factory;
}
public function register(): void
{
add_action('admin_init', [$this, 'init_columns_on_quick_edit']);
}
/**
* Get list screen when doing Quick Edit, a native WordPress ajax call
*/
public function init_columns_on_quick_edit()
{
if ( ! wp_doing_ajax()) {
return;
}
switch (filter_input(INPUT_POST, 'action')) {
// Quick edit post
case 'inline-save' :
$type = filter_input(INPUT_POST, 'post_type');
break;
// Adding term & Quick edit term
case 'add-tag' :
case 'inline-save-tax' :
$type = 'wp-taxonomy_' . filter_input(INPUT_POST, 'taxonomy');
break;
// Quick edit comment & Inline reply on comment
case 'edit-comment' :
case 'replyto-comment' :
$type = 'wp-comments';
break;
default:
return;
}
$id = $this->preference->get($type);
if ( ! ListScreenId::is_valid_id($id)) {
return;
}
$list_screen = $this->storage->find(new ListScreenId($id));
if ( ! $list_screen || ! $list_screen->is_user_allowed(wp_get_current_user())) {
return;
}
if ( ! $list_screen ) {
return;
}
add_filter( 'list_table_primary_column', [ $this->primary_column_factory->create( $list_screen ), 'set_primary_column' ], 20 );
$screen_controller = new ScreenController( $list_screen );
$screen_controller->register();
}
}