PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.13
Admin Columns v7.0.13
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / RequestHandler / Ajax / ListScreenSettings.php
codepress-admin-columns / classes / RequestHandler / Ajax Last commit date
AdminGeneralOptionsGet.php 3 months ago AdminGeneralOptionsPersist.php 3 months ago CustomFieldKeys.php 3 months ago EditorMenuFavorites.php 3 months ago EditorMenuStatus.php 3 months ago ExtendedValue.php 3 months ago IntegrationToggle.php 3 months ago Integrations.php 3 months ago ListScreenAddColumn.php 3 months ago ListScreenDelete.php 3 months ago ListScreenOriginalColumns.php 3 months ago ListScreenSave.php 3 months ago ListScreenSelectColumn.php 3 months ago ListScreenSettings.php 3 months ago NetworkPostStati.php 3 months ago NumberFormat.php 3 months ago RestoreSettingsRequest.php 3 months ago ScreenOptions.php 3 months ago
ListScreenSettings.php
127 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\RequestHandler\Ajax;
6
7 use AC;
8 use AC\Admin\Preference;
9 use AC\Capabilities;
10 use AC\Form\NonceFactory;
11 use AC\ListScreen;
12 use AC\ListScreenRepository\Storage;
13 use AC\Request;
14 use AC\RequestAjaxHandler;
15 use AC\Type\TableId;
16 use InvalidArgumentException;
17
18 class ListScreenSettings implements RequestAjaxHandler
19 {
20
21 protected Storage $storage;
22
23 protected AC\TableScreenFactory\Aggregate $table_factory;
24
25 protected Preference\EditorPreference $editor_preference;
26
27 protected AC\Response\JsonListScreenSettingsFactory $response_factory;
28
29 private AC\Type\ListScreenIdGenerator $list_screen_id_generator;
30
31 public function __construct(
32 Storage $storage,
33 AC\TableScreenFactory\Aggregate $table_factory,
34 Preference\EditorPreference $preference,
35 AC\Response\JsonListScreenSettingsFactory $response_factory,
36 AC\Type\ListScreenIdGenerator $list_screen_id_generator
37 ) {
38 $this->storage = $storage;
39 $this->table_factory = $table_factory;
40 $this->editor_preference = $preference;
41 $this->response_factory = $response_factory;
42 $this->list_screen_id_generator = $list_screen_id_generator;
43 }
44
45 protected function validate(): void
46 {
47 $response = new AC\Response\Json();
48
49 if ( ! current_user_can(Capabilities::MANAGE)) {
50 $response->error();
51 }
52
53 if ( ! NonceFactory::create_ajax()->verify(new Request())) {
54 $response->error();
55 }
56 }
57
58 protected function set_editor_preference(ListScreen $list_screen): void
59 {
60 $this->editor_preference->save(
61 $list_screen->get_table_screen()->get_id(),
62 $list_screen->get_id()
63 );
64 }
65
66 protected function is_template(ListScreen $list_screen): bool
67 {
68 return false;
69 }
70
71 protected function add_middleware(Request $request, AC\TableScreen $table_screen): void
72 {
73 $request->add_middleware(
74 new Request\Middleware\ListScreenAdmin(
75 $this->storage,
76 $table_screen,
77 $this->editor_preference,
78 )
79 );
80 }
81
82 public function handle(): void
83 {
84 $this->validate();
85
86 $request = new Request();
87
88 $table_id = new TableId((string)$request->get('list_key'));
89
90 if ( ! $this->table_factory->can_create($table_id)) {
91 throw new InvalidArgumentException('Invalid table screen.');
92 }
93
94 $table_screen = $this->table_factory->create($table_id);
95
96 $this->add_middleware($request, $table_screen);
97
98 $list_screen = $request->get('list_screen');
99
100 // List Screen and context properties
101 $is_template = false;
102 $is_stored = false;
103 $title = $table_screen->get_labels()->get_singular();
104
105 if ($list_screen instanceof ListScreen) {
106 $this->set_editor_preference($list_screen);
107
108 if ( ! trim($list_screen->get_title())) {
109 $list_screen->set_title($title);
110 }
111
112 $is_template = $this->is_template($list_screen);
113 $is_stored = true;
114 } else {
115 $list_screen = new ListScreen(
116 $this->list_screen_id_generator->generate(),
117 $title,
118 $table_screen
119 );
120 }
121
122 $this->response_factory
123 ->create($list_screen, $is_stored, $is_template)
124 ->success();
125 }
126
127 }