Skip to content

Commit c5b952e

Browse files
authored
Merge pull request #271 from codepress/release/4.0.3
Release/4.0.3
2 parents 341424d + a5aeddf commit c5b952e

File tree

6 files changed

+169
-152
lines changed

6 files changed

+169
-152
lines changed

classes/Admin/Request/Column/Save.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,44 @@ public function request( Request $request ) {
2525
wp_send_json_error( [ 'message' => __( 'You need at least one column', 'codepress-admin-columns' ) ] );
2626
}
2727

28-
$list_id = $formdata['list_screen_id'];
29-
$type = $formdata['list_screen'];
30-
31-
if ( ! $this->list_screen_repository->exists( $list_id ) ) {
32-
$list_id = uniqid();
28+
if ( ! $formdata['list_screen_id'] ) {
29+
wp_send_json_error( [ 'message' => 'Invalid list Id' ] );
3330
}
3431

35-
$formdata['columns'] = $this->maybe_encode_urls( $formdata['columns'] );
32+
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $formdata['list_screen'] );
3633

37-
$column_data = [];
34+
if ( ! $list_screen ) {
35+
wp_send_json_error( [ 'message' => 'List screen not found' ] );
36+
}
3837

39-
foreach ( $formdata['columns'] as $column_name => $settings ) {
38+
$columns = [];
39+
40+
foreach ( $this->maybe_encode_urls( $formdata['columns'] ) as $column_name => $settings ) {
4041
if ( 0 === strpos( $column_name, '_new_column_' ) ) {
41-
$column_data[ uniqid() ] = $settings;
42+
$columns[ uniqid() ] = $settings;
4243
} else {
43-
$column_data[ $column_name ] = $settings;
44+
$columns[ $column_name ] = $settings;
4445
}
4546
}
4647

47-
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $type );
48-
49-
if ( ! $list_screen ) {
50-
wp_send_json_error( [ 'message' => 'Failed: List screen not found.' ] );
51-
}
52-
5348
$list_screen->set_title( ! empty( $formdata['title'] ) ? $formdata['title'] : $list_screen->get_label() )
54-
->set_settings( $column_data )
55-
->set_layout_id( $list_id )
49+
->set_settings( $columns )
50+
->set_layout_id( $formdata['list_screen_id'] )
5651
->set_preferences( ! empty( $formdata['settings'] ) ? $formdata['settings'] : [] );
5752

5853
$this->list_screen_repository->save( $list_screen );
5954

6055
do_action( 'ac/columns_stored', $list_screen );
6156

62-
$view_link = ac_helper()->html->link( $list_screen->get_screen_link(), sprintf( __( 'View %s screen', 'codepress-admin-columns' ), $list_screen->get_label() ) );
63-
6457
wp_send_json_success(
6558
sprintf(
66-
__( 'Settings for %s updated successfully.', 'codepress-admin-columns' ),
67-
"<strong>" . esc_html( $list_screen->get_title() ) . "</strong>"
68-
) . ' ' . $view_link
59+
'%s %s',
60+
sprintf(
61+
__( 'Settings for %s updated successfully.', 'codepress-admin-columns' ),
62+
sprintf( '<strong>%s</strong>', esc_html( $list_screen->get_title() ) )
63+
),
64+
ac_helper()->html->link( $list_screen->get_screen_link(), sprintf( __( 'View %s screen', 'codepress-admin-columns' ), $list_screen->get_label() ) )
65+
)
6966
);
7067
}
7168

classes/Controller/ListScreenRequest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function get_list_screen() {
6464
if ( $list_id && $this->repository->exists( $list_id ) ) {
6565
$list_screen = $this->repository->find( $list_id );
6666

67-
if ( $this->exists_list_screen( $list_screen->get_key() ) ) {
67+
if ( $list_screen && $this->exists_list_screen( $list_screen->get_key() ) ) {
6868
$this->preference->set( 'list_id', $list_screen->get_layout_id() );
6969
$this->preference->set( 'list_key', $list_screen->get_key() );
7070

@@ -87,7 +87,7 @@ public function get_list_screen() {
8787
}
8888

8989
// Initialize new
90-
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
90+
return $this->create_list_screen( $list_key );
9191
}
9292

9393
// Last visited ID
@@ -117,7 +117,7 @@ public function get_list_screen() {
117117
}
118118

119119
// Initialize new
120-
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
120+
return $this->create_list_screen( $list_key );
121121
}
122122

123123
// First visit to settings page
@@ -134,7 +134,22 @@ public function get_list_screen() {
134134
}
135135

136136
// Initialize new
137-
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
137+
return $this->create_list_screen( $list_key );
138+
}
139+
140+
/**
141+
* @param string $key
142+
*
143+
* @return ListScreen|null
144+
*/
145+
private function create_list_screen( $key ) {
146+
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $key );
147+
148+
if ( ! $list_screen ) {
149+
return null;
150+
}
151+
152+
return $list_screen->set_layout_id( uniqid() );
138153
}
139154

140155
/**

codepress-admin-columns.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/*
33
Plugin Name: Admin Columns
4-
Version: 4.0.2
4+
Version: 4.0.3
55
Description: Customize columns on the administration screens for post(types), pages, media, comments, links and users with an easy to use drag-and-drop interface.
66
Author: AdminColumns.com
77
Author URI: https://www.admincolumns.com
@@ -36,7 +36,7 @@
3636
}
3737

3838
define( 'AC_FILE', __FILE__ );
39-
define( 'AC_VERSION', '4.0.2' );
39+
define( 'AC_VERSION', '4.0.3' );
4040

4141
require_once __DIR__ . '/classes/Dependencies.php';
4242

5.69 KB
Binary file not shown.

0 commit comments

Comments
 (0)