-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathapi.php
More file actions
256 lines (190 loc) · 5.97 KB
/
api.php
File metadata and controls
256 lines (190 loc) · 5.97 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
use AC\Column;
use AC\Exception\HookTimingException;
use AC\ListScreen;
use AC\ListScreenCollection;
use AC\ListScreenRepository\Storage;
use AC\Plugin\Version;
use AC\Registry;
use AC\Type\ColumnId;
use AC\Type\ListScreenId;
use AC\Type\TableId;
use AC\Type\Url;
/**
* For usage @see https://docs.admincolumns.com/article/57-code-snippets
* List of available template functions:
* @method ac_get_list_screens()
* @method ac_get_list_screen()
* @method ac_get_column()
* @method ac_get_columns()
* @method AC()
*/
if ( ! function_exists('ac_get_list_screen')) {
/**
* Return the list table configuration, such as its ID, columns, and settings.
* For usage @see https://docs.admincolumns.com/article/57-code-snippets
*/
function ac_get_list_screen(string $id): ?ListScreen
{
if ( ! did_action('wp_loaded')) {
throw HookTimingException::called_too_early('wp_loaded');
}
$storage = Registry::get(Storage::class);
if ( ! $storage instanceof Storage) {
return null;
}
return $storage->find(new ListScreenId($id));
}
}
if ( ! function_exists('ac_get_list_screens')) {
/**
* Returns a collection of all list table configurations for a specific table.
* For usage @see https://docs.admincolumns.com/article/57-code-snippets
*/
function ac_get_list_screens(string $table_id): ListScreenCollection
{
if ( ! did_action('wp_loaded')) {
throw HookTimingException::called_too_early('wp_loaded');
}
$storage = Registry::get(Storage::class);
if ( ! $storage instanceof Storage) {
return new ListScreenCollection();
}
try {
return $storage->find_all_by_table_id(new TableId($table_id));
} catch (Throwable $e) {
return new ListScreenCollection();
}
}
}
if ( ! function_exists('ac_get_column')) {
/**
* Returns a single column by its name and list screen ID.
* For usage @see https://docs.admincolumns.com/article/57-code-snippets
*/
function ac_get_column(string $column_name, string $list_screen_id): ?Column
{
if ( ! did_action('wp_loaded')) {
throw HookTimingException::called_too_early('wp_loaded');
}
$storage = Registry::get(Storage::class);
if ( ! $storage instanceof Storage) {
return null;
}
try {
$list_screen = $storage->find(new ListScreenId($list_screen_id));
} catch (Throwable $e) {
return null;
}
if ( ! $list_screen) {
return null;
}
return $list_screen->get_column(new ColumnId($column_name));
}
}
if ( ! function_exists('ac_get_columns')) {
/**
* Returns all columns for a specific list table.
* For usage @see https://docs.admincolumns.com/article/57-code-snippets
* @return Column[]
*/
function ac_get_columns(string $list_screen_id): array
{
if ( ! did_action('wp_loaded')) {
throw HookTimingException::called_too_early('wp_loaded');
}
$storage = Registry::get(Storage::class);
if ( ! $storage instanceof Storage) {
return [];
}
try {
$list_screen = $storage->find(new ListScreenId($list_screen_id));
} catch (Throwable $e) {
return [];
}
if ( ! $list_screen) {
return [];
}
return iterator_to_array($list_screen->get_columns());
}
}
if ( ! function_exists('AC')) {
/**
* returns thw AC\AdminColumn object. Contains the plugin version and directory path.
*/
function AC(): AC\AdminColumns
{
static $ac = null;
if ($ac === null) {
$ac = new AC\AdminColumns(AC_FILE, new Version(AC_VERSION));
}
return $ac;
}
}
if ( ! function_exists('ac_is_pro_active')) {
function ac_is_pro_active(): bool
{
return defined('ACP_VERSION');
}
}
function ac_get_admin_url(?string $slug = null): string
{
_deprecated_function(__METHOD__, '4.5', 'Url\Editor');
return (new Url\Editor($slug))->get_url();
}
function ac_get_admin_network_url(?string $slug = null): string
{
_deprecated_function(__METHOD__, '4.5', 'Url\EditorNetwork');
return (new Url\EditorNetwork($slug))->get_url();
}
function ac_register_columns(): void
{
_deprecated_function(__METHOD__, '4.0');
}
function ac_get_site_utm_url(
string $path,
string $utm_medium,
?string $utm_content = null,
?string $utm_campaign = null
): string {
_deprecated_function(__METHOD__, '6.0', 'AC\Type\UrlUtmTags()');
return (new Url\UtmTags(new Url\Site($path), $utm_medium, $utm_content, $utm_campaign))->get_url();
}
function ac_get_site_documentation_url(?string $path = null): string
{
_deprecated_function(__METHOD__, '6.0', 'AC\Type\Url\Documentation()');
return (new Url\Documentation($path))->get_url();
}
function ac_get_site_url(?string $path = null): string
{
_deprecated_function(__METHOD__, '6.0', 'AC\Type\Url\Site()');
return (new Url\Site($path))->get_url();
}
function ac_get_url(string $relative_file_path): string
{
_deprecated_function(__FUNCTION__, '7.0.10');
return '';
}
if ( ! function_exists('ac_load_columns')) {
function ac_load_columns(): void
{
_deprecated_function(__METHOD__, '4.1');
}
}
if ( ! function_exists('ac_helper')) {
/**
* @deprecated 7.0.10 Use Helper\X::create() instead.
*/
function ac_helper(): AC\Helper
{
_deprecated_function(__FUNCTION__, '7.0.10', 'Helper\X::create()');
return new AC\Helper();
}
}
if ( ! function_exists('ac_format_date')) {
function ac_format_date(string $format, ?int $timestamp = null, ?DateTimeZone $timezone = null): ?string
{
_deprecated_function(__METHOD__, '7.0.10', 'wp_date()');
return wp_date($format, $timestamp, $timezone ?? new DateTimeZone('UTC')) ?: null;
}
}