AdminColumnsPro.php
8.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
namespace ACP;
use AC;
use AC\Admin\AdminNetwork;
use AC\Admin\AdminScripts;
use AC\Admin\NetworkRequestHandler;
use AC\Admin\Page\Columns;
use AC\Admin\PageRequestHandler;
use AC\Admin\WpMenuFactory;
use AC\Capabilities;
use AC\Integration\Filter\IsInstalled;
use AC\IntegrationRepository;
use AC\ListScreenTypes;
use AC\Plugin\InstallCollection;
use AC\PluginInformation;
use AC\Request;
use AC\Storage\ListScreenOrder;
use AC\Type\Url;
use ACP\Admin;
use ACP\Admin\MenuFactory;
use ACP\Admin\PageFactory;
use ACP\Bookmark;
use ACP\Bookmark\SegmentRepository;
use ACP\Migrate;
use ACP\Plugin;
use ACP\Plugin\NetworkUpdate;
use ACP\Plugin\Updater;
use ACP\RequestHandler;
use ACP\Search;
use ACP\Settings;
use ACP\Settings\ListScreen\HideOnScreen;
use ACP\Sorting\ModelFactory;
use ACP\Sorting\NativeSortableFactory;
use ACP\Storage\ListScreen\DecoderFactory;
use ACP\Storage\ListScreen\Encoder;
use ACP\Storage\ListScreen\LegacyCollectionDecoder;
use ACP\Storage\ListScreen\LegacyCollectionDecoderAggregate;
use ACP\ThirdParty;
/**
* The Admin Columns Pro plugin class
*/
final class AdminColumnsPro extends AC\Plugin {
/**
* @var API
*/
private $api;
/**
* @var self
*/
private static $instance;
/**
* @return AdminColumnsPro
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
protected function __construct() {
parent::__construct( ACP_FILE, 'acp_version' );
$this->api = new API();
$this->api
->set_url( Url\Site::URL )
->set_proxy( 'https://api.admincolumns.com' )
->set_request_meta( [
'php_version' => PHP_VERSION,
'acp_version' => $this->get_version()->get_value(),
] );
add_filter( 'ac/show_banner', '__return_false' );
$site_url = new Type\SiteUrl( $this->is_network_active() ? network_site_url() : site_url(), $this->is_network_active() );
$license_key_repository = new LicenseKeyRepository( $this->is_network_active() );
$license_repository = new LicenseRepository( $this->is_network_active() );
$storage = AC()->get_storage();
$list_screen_types = ListScreenTypes::instance();
$list_screen_encoder = new Encoder( $this->get_version() );
$list_screen_decoder_factory = new DecoderFactory( $list_screen_types );
$legacy_collection_decoder = new LegacyCollectionDecoderAggregate( [
new LegacyCollectionDecoder\Version332( $list_screen_types ),
new LegacyCollectionDecoder\Version384( $list_screen_types ),
new LegacyCollectionDecoder\Version400( $list_screen_types ),
] );
$location = $this->get_location();
$location_core = AC()->get_location();
$admin_url = admin_url( 'options-general.php' );
AC\Admin\RequestHandler::add_handler(
new PageRequestHandler(
new PageFactory( $storage, $location_core, $location, $site_url, new PluginInformation( $this->get_basename() ), new MenuFactory( $admin_url, new IntegrationRepository(), $license_key_repository, $license_repository ), $license_key_repository, $license_repository ),
Columns::NAME
)
);
$plugins = $this->get_installed_plugins();
$segment_repository = new SegmentRepository();
$request = new Request();
$services = [
new Admin\Settings( $storage, $location, $segment_repository ),
new QuickAdd\Addon( $storage, $location, $request ),
new Sorting\Addon( $storage, $location, new NativeSortableFactory(), new ModelFactory(), $segment_repository ),
new Editing\Addon( $storage, $location, $request ),
new Export\Addon( $location ),
new Bookmark\Addon( $storage, $request, $segment_repository ),
new Search\Addon( $storage, $location, $segment_repository ),
new Filtering\Addon( $storage, $location, $request ),
new ThirdParty\ACF\Addon(),
new ThirdParty\bbPress\Addon(),
new ThirdParty\Polylang\Addon(),
new ThirdParty\WooCommerce\Addon(),
new ThirdParty\YoastSeo\Addon(),
new Table\Switcher( $storage ),
new Table\HorizontalScrolling( $storage, $location ),
new Table\StickyTableRow( $storage ),
new Table\HideSearch(),
new Table\HideSubMenu( new HideOnScreen\SubMenu\CommentStatus() ),
new Table\HideSubMenu( new HideOnScreen\SubMenu\PostStatus() ),
new Table\HideSubMenu( new HideOnScreen\SubMenu\Roles() ),
new Table\HideBulkActions(),
new Table\HideFilters(),
new ListScreens(),
new Localize( $this->get_dir() ),
new NativeTaxonomies(),
new IconPicker(),
new TermQueryInformation(),
new Migrate\Export\Request( $storage, new Migrate\Export\ResponseFactory( $list_screen_encoder ) ),
new Migrate\Import\Request( $storage, $list_screen_decoder_factory, $legacy_collection_decoder ),
new RequestHandler\Ajax\ListScreenUsers(),
new RequestHandler\Ajax\ListScreenOrder( new ListScreenOrder() ),
new RequestHandler\Ajax\Feedback( $this->get_version() ),
new RequestHandler\Ajax\SubscriptionUpdate( $license_key_repository, $license_repository, $this->api, $site_url, $location, $this->is_network_active() ),
new RequestHandler\Ajax\AddonInstaller( $this->api, $license_repository, $license_key_repository, $site_url ),
new RequestHandler\ListScreenCreate( $storage, $request, new ListScreenOrder() ),
new RequestParser( $this->api, $license_repository, $license_key_repository, $site_url, $plugins ),
new Updates( $this->api, $license_key_repository, $site_url, $plugins ),
new PluginActionLinks( $this->get_basename() ),
new Check\Activation( $this->get_basename(), $license_repository, $license_key_repository ),
new Check\Expired( $license_repository, $license_key_repository, $this->get_basename(), $site_url ),
new Check\Renewal( $license_repository, $license_key_repository, $this->get_basename(), $site_url ),
new Check\RecommendedAddons( new IntegrationRepository() ),
new Admin\Scripts( $location ),
];
$services[] = new Service\Storage(
$storage,
new ListScreenRepository\FileFactory( $list_screen_encoder, $list_screen_decoder_factory ),
new AC\EncodedListScreenDataFactory(),
$legacy_collection_decoder
);
if ( $this->get_version()->is_beta() ) {
$services[] = new Check\Beta( new Admin\Feedback( $location ) );
}
$network_url = network_admin_url( 'settings.php' );
NetworkRequestHandler::add_handler(
new PageRequestHandler(
new Admin\NetworkPageFactory( $storage, $location_core, $location, $site_url, new MenuFactory( $network_url, new IntegrationRepository(), $license_key_repository, $license_repository ) ),
Columns::NAME
)
);
if ( $this->is_network_active() ) {
$services[] = new AdminNetwork( new NetworkRequestHandler(), new WpMenuFactory(), new AdminScripts( $location_core ) );
}
array_map( [ $this, 'register_service' ], $services );
$installer = new InstallCollection();
$installer->add_install( new Plugin\Install\BookmarkTable() );
$this->set_installer( $installer );
add_action( 'init', [ $this, 'install' ], 1000 );
add_action( 'init', [ $this, 'install_network' ], 1000 );
add_action( 'ac/table_scripts', [ $this, 'table_scripts' ] );
add_filter( 'ac/view/templates', [ $this, 'templates' ] );
}
private function register_service( AC\Registrable $service ) {
$service->register();
}
/**
* @return Plugins
*/
private function get_installed_plugins() {
$plugins = [
new PluginInformation( $this->get_basename() ),
];
$addons = ( new IntegrationRepository() )->find_all( [
IntegrationRepository::ARG_FILTER => [ new IsInstalled() ],
] );
foreach ( $addons as $addon ) {
$plugins[] = new PluginInformation( $addon->get_basename() );
}
return new Plugins( $plugins );
}
public function install_network() {
if ( ! current_user_can( Capabilities::MANAGE ) || ! is_network_admin() ) {
return;
}
$updater = new Updater\Network( $this->get_version() );
$updater->add_update( new NetworkUpdate\V5000( $updater->get_stored_version() ) )
->parse_updates();
}
/**
* @return API
*/
public function get_api() {
return $this->api;
}
/**
* @return void
*/
public function table_scripts() {
$assets = [
new AC\Asset\Style( 'acp-table', $this->get_location()->with_suffix( 'assets/core/css/table.css' ) ),
new AC\Asset\Script( 'acp-table', $this->get_location()->with_suffix( 'assets/core/js/table.js' ) ),
];
foreach ( $assets as $asset ) {
$asset->enqueue();
}
}
/**
* @param array $templates
*
* @return array
*/
public function templates( $templates ) {
$templates[] = $this->get_dir() . 'templates';
return $templates;
}
/**
* @since 4.0
*/
public function network_admin() {
_deprecated_function( __METHOD__, '5.5.2' );
}
/**
* @since 4.0
* @deprecated 4.5
*/
public function editing() {
_deprecated_function( __METHOD__, '4.5' );
}
/**
* @deprecated 4.5
* @since 4.0
*/
public function filtering() {
_deprecated_function( __METHOD__, '4.5' );
}
/**¬
* @since 4.0
* @deprecated 4.5
*/
public function sorting() {
_deprecated_function( __METHOD__, '4.5' );
}
/**
* @since 4.0
* @deprecated 5.0.0
*/
public function layouts() {
_deprecated_function( __METHOD__, '5.0.0' );
}
}