44
55use AC \Admin \GeneralSectionFactory ;
66use AC \Admin \Page ;
7- use AC \Admin \PromoCollection ;
87use AC \Admin \Section \ListScreenMenu ;
98use AC \Admin \Section \Restore ;
10- use AC \Check ;
9+ use AC \Controller \ AjaxColumnValue ;
1110use AC \Controller \AjaxRequestCustomFieldKeys ;
1211use AC \Controller \AjaxRequestNewColumn ;
1312use AC \Controller \ListScreenRequest ;
1413use AC \Controller \ListScreenRestoreColumns ;
14+ use AC \Controller \RedirectAddonStatus ;
1515use AC \Deprecated ;
1616use AC \ListScreenRepository ;
1717use AC \ListScreenRepository \FilterStrategy ;
@@ -58,6 +58,8 @@ private function __construct() {
5858 $ this ->list_screen_repository = new ListScreenRepository \Aggregate ();
5959 $ this ->list_screen_repository ->register_repository ( new ListScreenRepository \DataBase ( ListScreenTypes::instance () ) );
6060
61+ $ this ->register_admin ();
62+
6163 $ services = [
6264 new Ajax \NumberFormat ( new Request () ),
6365 new Deprecated \Hooks ,
@@ -72,7 +74,11 @@ private function __construct() {
7274 new Capabilities \Manage (),
7375 new AjaxRequestNewColumn ( $ this ->list_screen_repository ),
7476 new AjaxRequestCustomFieldKeys (),
77+ new AjaxColumnValue ( $ this ->list_screen_repository ),
7578 new ListScreenRestoreColumns ( $ this ->list_screen_repository ),
79+ new RedirectAddonStatus ( $ this ->admin ->get_url ( Page \Addons::NAME ) ),
80+ new PluginActionLinks ( $ this ->get_basename (), $ this ->admin ->get_url ( Page \Columns::NAME ) ),
81+ new NoticeChecks (),
7682 ];
7783
7884 foreach ( $ services as $ service ) {
@@ -81,23 +87,12 @@ private function __construct() {
8187 }
8288 }
8389
84- $ this ->register_admin ();
8590 $ this ->localize ();
8691
92+ add_action ( 'init ' , [ $ this , 'register_list_screens ' ], 1000 ); // run after all post types are registered
8793 add_action ( 'init ' , [ $ this , 'install ' ], 1000 );
88- add_action ( 'init ' , [ $ this , 'notice_checks ' ] );
8994 add_action ( 'init ' , [ $ this , 'register_global_scripts ' ] );
90-
91- add_filter ( 'plugin_action_links ' , [ $ this , 'add_settings_link ' ], 1 , 2 );
92- add_filter ( 'plugin_action_links ' , [ $ this , 'add_pro_link ' ], 10 , 2 );
93-
9495 add_action ( 'ac/screen ' , [ $ this , 'init_table_on_screen ' ] );
95- add_action ( 'wp_ajax_ac_get_column_value ' , [ $ this , 'table_ajax_value ' ] );
96-
97- add_filter ( 'wp_redirect ' , [ $ this , 'redirect_after_status_change ' ] );
98-
99- // run after all post types are registered
100- add_action ( 'init ' , [ $ this , 'register_list_screens ' ], 1000 );
10196 }
10297
10398 /**
@@ -132,21 +127,19 @@ public function init_table_on_screen( Screen $screen ) {
132127 $ list_id = $ this ->preferences ()->get ( $ key );
133128 }
134129
130+ $ list_screen = null ;
135131 $ permission_checker = ( new PermissionChecker ( wp_get_current_user () ) );
136132
137133 if ( $ list_id ) {
138- $ _list_screen = $ this ->list_screen_repository ->find ( $ list_id );
139-
140- if ( $ _list_screen && $ permission_checker ->is_valid ( $ _list_screen ) ) {
141- $ list_screen = $ _list_screen ;
142- } else {
134+ $ requested_list_screen = $ this ->list_screen_repository ->find ( $ list_id );
143135
144- // List screen not found.
145- $ list_screen = $ this -> get_first_list_screen ( $ key , $ permission_checker ) ;
136+ if ( $ requested_list_screen && $ permission_checker -> is_valid ( $ requested_list_screen ) ) {
137+ $ list_screen = $ requested_list_screen ;
146138 }
147- } else {
139+ }
148140
149- // First visit.
141+ // First visit or not found
142+ if ( ! $ list_screen ) {
150143 $ list_screen = $ this ->get_first_list_screen ( $ key , $ permission_checker );
151144 }
152145
@@ -161,7 +154,8 @@ public function init_table_on_screen( Screen $screen ) {
161154 }
162155
163156 /**
164- * @param string $key
157+ * @param string $key
158+ * @param PermissionChecker $permission_checker
165159 *
166160 * @return ListScreen|null
167161 */
@@ -181,63 +175,6 @@ private function get_first_list_screen( $key, PermissionChecker $permission_chec
181175 return ListScreenTypes::instance ()->get_list_screen_by_key ( $ key );
182176 }
183177
184- /**
185- * Get column value by ajax.
186- */
187- public function table_ajax_value () {
188- check_ajax_referer ( 'ac-ajax ' );
189-
190- // Get ID of entry to edit
191- $ id = intval ( filter_input ( INPUT_POST , 'pk ' ) );
192-
193- if ( ! $ id ) {
194- wp_die ( __ ( 'Invalid item ID. ' , 'codepress-admin-columns ' ), null , 400 );
195- }
196-
197- $ list_screen = $ this ->list_screen_repository ->find ( filter_input ( INPUT_POST , 'layout ' ) );
198-
199- if ( ! $ list_screen ) {
200- wp_die ( __ ( 'Invalid list screen. ' , 'codepress-admin-columns ' ), null , 400 );
201- }
202-
203- $ column = $ list_screen ->get_column_by_name ( filter_input ( INPUT_POST , 'column ' ) );
204-
205- if ( ! $ column ) {
206- wp_die ( __ ( 'Invalid column. ' , 'codepress-admin-columns ' ), null , 400 );
207- }
208-
209- if ( ! $ column instanceof Column \AjaxValue ) {
210- wp_die ( __ ( 'Invalid method. ' , 'codepress-admin-columns ' ), null , 400 );
211- }
212-
213- // Trigger ajax callback
214- echo $ column ->get_ajax_value ( $ id );
215- exit ;
216- }
217-
218- /**
219- * Init checks
220- */
221- public function notice_checks () {
222- $ checks = [
223- new Check \Review (),
224- ];
225-
226- if ( ! ac_is_pro_active () ) {
227- foreach ( new PromoCollection () as $ promo ) {
228- $ checks [] = new Check \Promotion ( $ promo );
229- }
230- }
231-
232- foreach ( new Integrations () as $ integration ) {
233- $ checks [] = new Check \AddonAvailable ( $ integration );
234- }
235-
236- foreach ( $ checks as $ check ) {
237- $ check ->register ();
238- }
239- }
240-
241178 /**
242179 * @return string
243180 */
@@ -259,41 +196,6 @@ public function get_version() {
259196 return AC_VERSION ;
260197 }
261198
262- /**
263- * Add a settings link to the Admin Columns entry in the plugin overview screen
264- *
265- * @param array $links
266- * @param string $file
267- *
268- * @return array
269- * @see filter:plugin_action_links
270- * @since 1.0
271- */
272- public function add_settings_link ( $ links , $ file ) {
273- if ( $ file === $ this ->get_basename () ) {
274- array_unshift ( $ links , sprintf ( '<a href="%s">%s</a> ' , $ this ->admin ->get_url ( 'columns ' ), __ ( 'Settings ' , 'codepress-admin-columns ' ) ) );
275- }
276-
277- return $ links ;
278- }
279-
280- /**
281- * @param array $links
282- * @param string $file
283- *
284- * @return array
285- */
286- public function add_pro_link ( $ links , $ file ) {
287- if ( $ file === $ this ->get_basename () && ! ac_is_pro_active () ) {
288- $ links [] = sprintf ( '<a href="%s" target="_blank">%s</a> ' ,
289- esc_url ( ac_get_site_utm_url ( 'admin-columns-pro ' , 'upgrade ' ) ),
290- sprintf ( '<span style="font-weight: bold;">%s</span> ' , __ ( 'Go Pro ' , 'codepress-admin-columns ' ) )
291- );
292- }
293-
294- return $ links ;
295- }
296-
297199 /**
298200 * @since 2.5
299201 */
@@ -389,9 +291,9 @@ public function get_post_types() {
389291 * Load text-domain
390292 */
391293 public function localize () {
392- $ path = pathinfo ( $ this ->get_dir () );
294+ $ relative_dir = str_replace ( WP_PLUGIN_DIR , '' , $ this ->get_dir () );
393295
394- load_plugin_textdomain ( 'codepress-admin-columns ' , false , $ path [ ' basename ' ] . '/ languages/ ' );
296+ load_plugin_textdomain ( 'codepress-admin-columns ' , false , $ relative_dir . 'languages/ ' );
395297 }
396298
397299 /**
@@ -416,42 +318,6 @@ private function register_admin() {
416318 ->register ();
417319 }
418320
419- /**
420- * Redirect the user to the Admin Columns add-ons page after activation/deactivation of an add-on from the add-ons page
421- *
422- * @param $location
423- *
424- * @return string
425- * @since 2.2
426- */
427- public function redirect_after_status_change ( $ location ) {
428- global $ pagenow ;
429-
430- if ( 'plugins.php ' !== $ pagenow || ! filter_input ( INPUT_GET , 'ac-redirect ' ) || filter_input ( INPUT_GET , 'error ' ) ) {
431- return $ location ;
432- }
433-
434- $ status = filter_input ( INPUT_GET , 'action ' );
435-
436- if ( ! $ status ) {
437- return $ location ;
438- }
439-
440- $ integration = IntegrationFactory::create ( filter_input ( INPUT_GET , 'plugin ' ) );
441-
442- if ( ! $ integration ) {
443- return $ location ;
444- }
445-
446- $ location = add_query_arg ( [
447- 'status ' => $ status ,
448- 'plugin ' => $ integration ->get_slug (),
449- '_ac_nonce ' => wp_create_nonce ( 'ac-plugin-status-change ' ),
450- ], $ this ->admin ()->get_url ( 'addons ' ) );
451-
452- return $ location ;
453- }
454-
455321 /**
456322 * @param $file
457323 *
0 commit comments