Skip to content

Commit 341424d

Browse files
authored
Merge pull request #267 from codepress/release/4.0.2
Release/4.0.2
2 parents 12a0071 + 9abf8e6 commit 341424d

File tree

60 files changed

+41225
-1810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+41225
-1810
lines changed

classes/Admin/Page/Addons.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
class Addons extends Page
1111
implements AC\Registrable {
1212

13+
const NAME = 'addons';
14+
1315
public function __construct() {
14-
parent::__construct( 'addons', __( 'Add-ons', 'codepress-admin-columns' ) );
16+
parent::__construct( self::NAME, __( 'Add-ons', 'codepress-admin-columns' ) );
1517
}
1618

1719
/**

classes/AdminColumns.php

Lines changed: 20 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
use AC\Admin\GeneralSectionFactory;
66
use AC\Admin\Page;
7-
use AC\Admin\PromoCollection;
87
use AC\Admin\Section\ListScreenMenu;
98
use AC\Admin\Section\Restore;
10-
use AC\Check;
9+
use AC\Controller\AjaxColumnValue;
1110
use AC\Controller\AjaxRequestCustomFieldKeys;
1211
use AC\Controller\AjaxRequestNewColumn;
1312
use AC\Controller\ListScreenRequest;
1413
use AC\Controller\ListScreenRestoreColumns;
14+
use AC\Controller\RedirectAddonStatus;
1515
use AC\Deprecated;
1616
use AC\ListScreenRepository;
1717
use 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
*

classes/Autoloader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Autoloader {
1919
protected $prefixes;
2020

2121
protected function __construct() {
22-
$this->prefixes = array();
22+
$this->prefixes = [];
2323

24-
spl_autoload_register( array( $this, 'autoload' ) );
24+
spl_autoload_register( [ $this, 'autoload' ] );
2525
}
2626

2727
public static function instance() {
@@ -127,11 +127,11 @@ public function get_class_names_from_dir( $namespace ) {
127127
$path = realpath( $path );
128128

129129
if ( ! $path ) {
130-
return array();
130+
return [];
131131
}
132132

133133
$iterator = new FilesystemIterator( $path, FilesystemIterator::SKIP_DOTS );
134-
$classes = array();
134+
$classes = [];
135135

136136
/* @var DirectoryIterator $leaf */
137137
foreach ( $iterator as $leaf ) {

classes/Check/AddonAvailable.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct( Integration $integration ) {
2929
* @throws Exception
3030
*/
3131
public function register() {
32-
add_action( 'ac/screen', array( $this, 'display' ) );
32+
add_action( 'ac/screen', [ $this, 'display' ] );
3333

3434
$this->get_ajax_handler()->register();
3535
}
@@ -41,7 +41,7 @@ private function get_ajax_handler() {
4141
$handler = new Ajax\Handler();
4242
$handler
4343
->set_action( 'ac_dismiss_notice_addon_' . $this->integration->get_slug() )
44-
->set_callback( array( $this, 'ajax_dismiss_notice' ) );
44+
->set_callback( [ $this, 'ajax_dismiss_notice' ] );
4545

4646
return $handler;
4747
}
@@ -88,7 +88,6 @@ public function display( Screen $screen ) {
8888
)
8989
);
9090

91-
9291
$notice = new Dismissible( $message, $this->get_ajax_handler() );
9392
$notice->register();
9493
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace AC\Controller;
4+
5+
use AC\Ajax;
6+
use AC\Column\AjaxValue;
7+
use AC\ListScreenRepository\ListScreenRepository;
8+
use AC\Registrable;
9+
10+
class AjaxColumnValue implements Registrable {
11+
12+
/**
13+
* @var ListScreenRepository
14+
*/
15+
private $repository;
16+
17+
public function __construct( ListScreenRepository $repository ) {
18+
$this->repository = $repository;
19+
}
20+
21+
public function register() {
22+
$this->get_ajax_handler()->register();
23+
}
24+
25+
private function get_ajax_handler() {
26+
$handler = new Ajax\Handler();
27+
$handler
28+
->set_action( 'ac_get_column_value' )
29+
->set_callback( [ $this, 'get_value' ] );
30+
31+
return $handler;
32+
}
33+
34+
public function get_value() {
35+
check_ajax_referer( 'ac-ajax' );
36+
37+
// Get ID of entry to edit
38+
$id = intval( filter_input( INPUT_POST, 'pk' ) );
39+
40+
if ( ! $id ) {
41+
wp_die( __( 'Invalid item ID.', 'codepress-admin-columns' ), null, 400 );
42+
}
43+
44+
$list_screen = $this->repository->find( filter_input( INPUT_POST, 'layout' ) );
45+
46+
if ( ! $list_screen ) {
47+
wp_die( __( 'Invalid list screen.', 'codepress-admin-columns' ), null, 400 );
48+
}
49+
50+
$column = $list_screen->get_column_by_name( filter_input( INPUT_POST, 'column' ) );
51+
52+
if ( ! $column ) {
53+
wp_die( __( 'Invalid column.', 'codepress-admin-columns' ), null, 400 );
54+
}
55+
56+
if ( ! $column instanceof AjaxValue ) {
57+
wp_die( __( 'Invalid method.', 'codepress-admin-columns' ), null, 400 );
58+
}
59+
60+
// Trigger ajax callback
61+
echo $column->get_ajax_value( $id );
62+
exit;
63+
}
64+
65+
}

0 commit comments

Comments
 (0)