Plugin Directory

source: codepress-admin-columns/trunk/api.php @ 2293580

Last change on this file since 2293580 was 2293580, checked in by tschutter, 5 years ago

trunk

File size: 4.3 KB
Line 
1<?php
2
3use AC\Admin;
4use AC\EncodedListScreenDataFactory;
5use AC\Helper;
6use AC\ListScreen;
7use AC\ListScreenCollection;
8use AC\Type\ListScreenId;
9
10/**
11 * @return AC\AdminColumns
12 * @since 3.0
13 */
14function AC() {
15        return AC\AdminColumns::instance();
16}
17
18/**
19 * We check the defined const because it is available before AC::__construct() runs.
20 * @return bool
21 */
22function ac_is_pro_active() {
23        return defined( 'ACP_FILE' );
24}
25
26/**
27 * Get the url where the Admin Columns website is hosted
28 *
29 * @param string $path
30 *
31 * @return string
32 */
33function ac_get_site_url( $path = '' ) {
34        $url = 'https://www.admincolumns.com';
35
36        if ( ! empty( $path ) ) {
37                $url .= '/' . trim( $path, '/' ) . '/';
38        }
39
40        return $url;
41}
42
43/**
44 * Url with utm tags
45 *
46 * @param string $path
47 * @param string $utm_medium
48 * @param string $utm_content
49 * @param bool   $utm_campaign
50 *
51 * @return string
52 */
53function ac_get_site_utm_url( $path, $utm_medium, $utm_content = null, $utm_campaign = false ) {
54        $url = ac_get_site_url( $path );
55
56        if ( ! $utm_campaign ) {
57                $utm_campaign = 'plugin-installation';
58        }
59
60        $args = [
61                // Referrer: plugin
62                'utm_source'   => 'plugin-installation',
63
64                // Specific promotions or sales
65                'utm_campaign' => $utm_campaign,
66
67                // Marketing medium: banner, documentation or email
68                'utm_medium'   => $utm_medium,
69
70                // Used for differentiation of medium
71                'utm_content'  => $utm_content,
72        ];
73
74        $args = array_map( 'sanitize_key', array_filter( $args ) );
75
76        return add_query_arg( $args, $url );
77}
78
79/**
80 * @return string
81 */
82function ac_get_twitter_handle() {
83        return 'admincolumns';
84}
85
86/**
87 * Simple helper methods for AC/Column objects
88 * @since 3.0
89 */
90function ac_helper() {
91        return new AC\Helper();
92}
93
94/**
95 * @param array|string $list_screen_keys
96 * @param array        $column_data
97 *
98 * @deprecated 4.0.0
99 * @since      2.2
100 */
101function ac_register_columns( $list_screen_keys, $column_data ) {
102        foreach ( (array) $list_screen_keys as $key ) {
103                ac_load_columns( [ $key => $column_data ] );
104        }
105}
106
107/**
108 * Manually set the columns for a list screen
109 * This overrides the database settings and thus renders the settings screen for this list screen useless
110 * If you like to register a column of your own please have a look at our documentation.
111 * We also have a free start-kit available, which contains all the necessary files.
112 * Documentation: https://www.admincolumns.com/documentation/guides/creating-new-column-type/
113 * Starter-kit: https://.com/codepress/ac-column-template/
114 *
115 * @param array $data
116 *
117 * @deprecated 4.1
118 * @since      4.0.0
119 */
120function ac_load_columns( array $data ) {
121        $factory = new EncodedListScreenDataFactory();
122        $factory->create()->add( $data );
123}
124
125/**
126 * @param string|null $slug
127 *
128 * @return string
129 */
130function ac_get_admin_url( $slug ) {
131        return add_query_arg(
132                [
133                        Admin::QUERY_ARG_PAGE => Admin::NAME,
134                        Admin::QUERY_ARG_TAB  => $slug,
135                ],
136                admin_url( 'options-general.php' )
137        );
138}
139
140/**
141 * @param string|null $slug
142 *
143 * @return string
144 */
145function ac_get_admin_network_url( $slug = null ) {
146        return add_query_arg(
147                [
148                        Admin::QUERY_ARG_PAGE => Admin::NAME,
149                        Admin::QUERY_ARG_TAB  => $slug,
150                ],
151                network_admin_url( 'settings.php' )
152        );
153}
154
155/**
156 * Convert site_url() to [cpac_site_url] and back for easy migration
157 *
158 * @param string $label
159 * @param string $action
160 *
161 * @return string
162 */
163function ac_convert_site_url( $label, $action = 'encode' ) {
164        $input = [ site_url(), '[cpac_site_url]' ];
165
166        if ( 'decode' === $action ) {
167                $input = array_reverse( $input );
168        }
169
170        return stripslashes( str_replace( $input[0], $input[1], trim( $label ) ) );
171}
172
173/**
174 * @param string $id Layout ID e.g. ac5de58e04a75b0
175 *
176 * @return ListScreen|null
177 * @since 4.0.0
178 */
179function ac_get_list_screen( $id ) {
180        return AC()->get_storage()->find( new ListScreenId( $id ) );
181}
182
183/**
184 * @param string $key e.g. post, page, wp-users, wp-media, wp-comments
185 *
186 * @return ListScreenCollection
187 * @since 4.0.0
188 */
189function ac_get_list_screens( $key ) {
190        return AC()->get_storage()->find_all( [ 'key' => $key ] );
191}
192
193/**
194 * @param                   $format
195 * @param null              $timestamp
196 * @param DateTimeZone|null $timezone
197 *
198 * @return false|string
199 */
200function ac_format_date( $format, $timestamp = null, DateTimeZone $timezone = null ) {
201        return ( new Helper\Date() )->format_date( $format, $timestamp, $timezone );
202}
Note: See TracBrowser for help on using the repository browser.