forked from codepress/admin-columns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
201 lines (175 loc) · 4.22 KB
/
api.php
File metadata and controls
201 lines (175 loc) · 4.22 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
<?php
use AC\Admin;
use AC\EncodedListScreenDataFactory;
use AC\Helper;
use AC\ListScreen;
use AC\ListScreenCollection;
use AC\Type\ListScreenId;
/**
* @return AC\AdminColumns
* @since 3.0
*/
function AC() {
return AC\AdminColumns::instance();
}
/**
* @return bool True when Admin Columns Pro plugin is activated.
*/
function ac_is_pro_active() {
return function_exists( 'ACP' );
}
/**
* Get the url where the Admin Columns website is hosted
*
* @param string $path
*
* @return string
*/
function ac_get_site_url( $path = '' ) {
$url = 'https://www.admincolumns.com';
if ( ! empty( $path ) ) {
$url .= '/' . trim( $path, '/' ) . '/';
}
return $url;
}
/**
* Url with utm tags
*
* @param string $path
* @param string $utm_medium
* @param string $utm_content
* @param bool $utm_campaign
*
* @return string
*/
function ac_get_site_utm_url( $path, $utm_medium, $utm_content = null, $utm_campaign = false ) {
$url = ac_get_site_url( $path );
if ( ! $utm_campaign ) {
$utm_campaign = 'plugin-installation';
}
$args = [
// Referrer: plugin
'utm_source' => 'plugin-installation',
// Specific promotions or sales
'utm_campaign' => $utm_campaign,
// Marketing medium: banner, documentation or email
'utm_medium' => $utm_medium,
// Used for differentiation of medium
'utm_content' => $utm_content,
];
$args = array_map( 'sanitize_key', array_filter( $args ) );
return add_query_arg( $args, $url );
}
/**
* @return string
*/
function ac_get_twitter_handle() {
return 'admincolumns';
}
/**
* Simple helper methods for AC/Column objects
* @since 3.0
*/
function ac_helper() {
return new AC\Helper();
}
/**
* @param array|string $list_screen_keys
* @param array $column_data
*
* @deprecated 4.0.0
* @since 2.2
*/
function ac_register_columns( $list_screen_keys, $column_data ) {
foreach ( (array) $list_screen_keys as $key ) {
ac_load_columns( [ $key => $column_data ] );
}
}
/**
* Manually set the columns for a list screen
* This overrides the database settings and thus renders the settings screen for this list screen useless
* If you like to register a column of your own please have a look at our documentation.
* We also have a free start-kit available, which contains all the necessary files.
* Documentation: https://www.admincolumns.com/documentation/guides/creating-new-column-type/
* Starter-kit: https://github.com/codepress/ac-column-template/
*
* @param array $data
*
* @deprecated 4.1
* @since 4.0.0
*/
function ac_load_columns( array $data ) {
$factory = new EncodedListScreenDataFactory();
$factory->create()->add( $data );
}
/**
* @param string|null $slug
*
* @return string
*/
function ac_get_admin_url( $slug ) {
return add_query_arg(
[
Admin::QUERY_ARG_PAGE => Admin::NAME,
Admin::QUERY_ARG_TAB => $slug,
],
admin_url( 'options-general.php' )
);
}
/**
* @param string|null $slug
*
* @return string
*/
function ac_get_admin_network_url( $slug = null ) {
return add_query_arg(
[
Admin::QUERY_ARG_PAGE => Admin::NAME,
Admin::QUERY_ARG_TAB => $slug,
],
network_admin_url( 'settings.php' )
);
}
/**
* Convert site_url() to [cpac_site_url] and back for easy migration
*
* @param string $label
* @param string $action
*
* @return string
*/
function ac_convert_site_url( $label, $action = 'encode' ) {
$input = [ site_url(), '[cpac_site_url]' ];
if ( 'decode' === $action ) {
$input = array_reverse( $input );
}
return stripslashes( str_replace( $input[0], $input[1], trim( $label ) ) );
}
/**
* @param string $id Layout ID e.g. ac5de58e04a75b0
*
* @return ListScreen|null
* @since 4.0.0
*/
function ac_get_list_screen( $id ) {
return AC()->get_storage()->find( new ListScreenId( $id ) );
}
/**
* @param string $key e.g. post, page, wp-users, wp-media, wp-comments
*
* @return ListScreenCollection
* @since 4.0.0
*/
function ac_get_list_screens( $key ) {
return AC()->get_storage()->find_all( [ 'key' => $key ] );
}
/**
* @param $format
* @param null $timestamp
* @param DateTimeZone|null $timezone
*
* @return false|string
*/
function ac_format_date( $format, $timestamp = null, DateTimeZone $timezone = null ) {
return ( new Helper\Date() )->format_date( $format, $timestamp, $timezone );
}