codepress-admin-columns
Last commit date
assets
2 years ago
classes
2 years ago
languages
2 years ago
settings
2 years ago
templates
2 years ago
vendor
2 years ago
api.php
2 years ago
codepress-admin-columns.php
2 years ago
readme.txt
1 year ago
api.php
191 lines
| 1 | <?php |
| 2 | |
| 3 | use AC\Container; |
| 4 | use AC\Helper; |
| 5 | use AC\ListScreen; |
| 6 | use AC\ListScreenCollection; |
| 7 | use AC\Type\ListScreenId; |
| 8 | use AC\Type\Url; |
| 9 | |
| 10 | function ac_get_url(string $relative_file_path): string |
| 11 | { |
| 12 | return Container::get_location()->with_suffix($relative_file_path)->get_url(); |
| 13 | } |
| 14 | |
| 15 | if ( ! function_exists('AC')) { |
| 16 | function AC(): AC\AdminColumns |
| 17 | { |
| 18 | static $ac = null; |
| 19 | |
| 20 | if ($ac === null) { |
| 21 | $ac = new AC\AdminColumns(); |
| 22 | } |
| 23 | |
| 24 | return $ac; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | if ( ! function_exists('ac_helper')) { |
| 29 | function ac_helper(): AC\Helper |
| 30 | { |
| 31 | return new AC\Helper(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @since 4.0.0 |
| 37 | */ |
| 38 | if ( ! function_exists('ac_get_list_screen')) { |
| 39 | function ac_get_list_screen(string $id): ?ListScreen |
| 40 | { |
| 41 | return Container::get_storage()->find(new ListScreenId($id)); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Usage: Load after or within the 'wp_loaded' action hook. |
| 47 | * @since 4.0.0 |
| 48 | */ |
| 49 | if ( ! function_exists('ac_get_list_screens')) { |
| 50 | function ac_get_list_screens(string $key): ListScreenCollection |
| 51 | { |
| 52 | return Container::get_storage()->find_all_by_key($key); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Usage: Load after or within the 'wp_loaded' action hook. |
| 58 | */ |
| 59 | if ( ! function_exists('ac_get_column')) { |
| 60 | function ac_get_column(string $column_name, string $list_screen_id): ?\AC\Column |
| 61 | { |
| 62 | try { |
| 63 | $list_id = new ListScreenId($list_screen_id); |
| 64 | } catch (Exception $e) { |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | $list_screen = Container::get_storage()->find($list_id); |
| 69 | |
| 70 | if ( ! $list_screen) { |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | $column = $list_screen->get_column_by_name($column_name); |
| 75 | |
| 76 | return $column ?: null; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Usage: Load after or within the 'wp_loaded' action hook. |
| 82 | * @return AC\Column[] |
| 83 | * @since 4.2 |
| 84 | */ |
| 85 | if ( ! function_exists('ac_get_columns')) { |
| 86 | function ac_get_columns(string $list_screen_id): array |
| 87 | { |
| 88 | try { |
| 89 | $list_id = new ListScreenId($list_screen_id); |
| 90 | } catch (Exception $e) { |
| 91 | return []; |
| 92 | } |
| 93 | |
| 94 | $list_screen = Container::get_storage()->find($list_id); |
| 95 | |
| 96 | if ( ! $list_screen) { |
| 97 | return []; |
| 98 | } |
| 99 | |
| 100 | return $list_screen->get_columns(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if ( ! function_exists('ac_format_date')) { |
| 105 | function ac_format_date(string $format, int $timestamp = null, DateTimeZone $timezone = null): ?string |
| 106 | { |
| 107 | return (new Helper\Date())->format_date($format, $timestamp, $timezone) ?: null; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | function ac_get_admin_url(string $slug = null): string |
| 112 | { |
| 113 | _deprecated_function(__METHOD__, '4.5', 'Url\Editor'); |
| 114 | |
| 115 | return (new Url\Editor($slug))->get_url(); |
| 116 | } |
| 117 | |
| 118 | function ac_get_admin_network_url(string $slug = null): string |
| 119 | { |
| 120 | _deprecated_function(__METHOD__, '4.5', 'Url\EditorNetwork'); |
| 121 | |
| 122 | return (new Url\EditorNetwork($slug))->get_url(); |
| 123 | } |
| 124 | |
| 125 | function ac_register_columns(): void |
| 126 | { |
| 127 | _deprecated_function(__METHOD__, '4.0'); |
| 128 | } |
| 129 | |
| 130 | function ac_get_site_utm_url( |
| 131 | string $path, |
| 132 | string $utm_medium, |
| 133 | string $utm_content = null, |
| 134 | string $utm_campaign = null |
| 135 | ): string { |
| 136 | _deprecated_function(__METHOD__, '6.0', 'AC\Type\UrlUtmTags()'); |
| 137 | |
| 138 | return (new Url\UtmTags(new Url\Site($path), $utm_medium, $utm_content, $utm_campaign))->get_url(); |
| 139 | } |
| 140 | |
| 141 | function ac_get_site_documentation_url(string $path = null): string |
| 142 | { |
| 143 | _deprecated_function(__METHOD__, '6.0', 'AC\Type\Url\Documentation()'); |
| 144 | |
| 145 | return (new Url\Documentation($path))->get_url(); |
| 146 | } |
| 147 | |
| 148 | function ac_get_site_url(string $path = null): string |
| 149 | { |
| 150 | _deprecated_function(__METHOD__, '6.0', 'AC\Type\Url\Site()'); |
| 151 | |
| 152 | return (new Url\Site($path))->get_url(); |
| 153 | } |
| 154 | |
| 155 | if ( ! function_exists('ac_load_columns')) { |
| 156 | function ac_load_columns(): void |
| 157 | { |
| 158 | _deprecated_function(__METHOD__, '4.1'); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | function ac_is_pro_active(): bool |
| 163 | { |
| 164 | _deprecated_function(__METHOD__, '6.0'); |
| 165 | |
| 166 | return defined('ACP_FILE'); |
| 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 |