Skip to content

Commit

Permalink
Merge pull request #271 from codepress/release/4.0.3
Browse files Browse the repository at this point in the history
Release/4.0.3
  • Loading branch information
DGStefan authored Mar 11, 2020
2 parents 341424d + a5aeddf commit c5b952e
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 152 deletions.
43 changes: 20 additions & 23 deletions classes/Admin/Request/Column/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,44 @@ public function request( Request $request ) {
wp_send_json_error( [ 'message' => __( 'You need at least one column', 'codepress-admin-columns' ) ] );
}

$list_id = $formdata['list_screen_id'];
$type = $formdata['list_screen'];

if ( ! $this->list_screen_repository->exists( $list_id ) ) {
$list_id = uniqid();
if ( ! $formdata['list_screen_id'] ) {
wp_send_json_error( [ 'message' => 'Invalid list Id' ] );
}

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

$column_data = [];
if ( ! $list_screen ) {
wp_send_json_error( [ 'message' => 'List screen not found' ] );
}

foreach ( $formdata['columns'] as $column_name => $settings ) {
$columns = [];

foreach ( $this->maybe_encode_urls( $formdata['columns'] ) as $column_name => $settings ) {
if ( 0 === strpos( $column_name, '_new_column_' ) ) {
$column_data[ uniqid() ] = $settings;
$columns[ uniqid() ] = $settings;
} else {
$column_data[ $column_name ] = $settings;
$columns[ $column_name ] = $settings;
}
}

$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $type );

if ( ! $list_screen ) {
wp_send_json_error( [ 'message' => 'Failed: List screen not found.' ] );
}

$list_screen->set_title( ! empty( $formdata['title'] ) ? $formdata['title'] : $list_screen->get_label() )
->set_settings( $column_data )
->set_layout_id( $list_id )
->set_settings( $columns )
->set_layout_id( $formdata['list_screen_id'] )
->set_preferences( ! empty( $formdata['settings'] ) ? $formdata['settings'] : [] );

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

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

$view_link = ac_helper()->html->link( $list_screen->get_screen_link(), sprintf( __( 'View %s screen', 'codepress-admin-columns' ), $list_screen->get_label() ) );

wp_send_json_success(
sprintf(
__( 'Settings for %s updated successfully.', 'codepress-admin-columns' ),
"<strong>" . esc_html( $list_screen->get_title() ) . "</strong>"
) . ' ' . $view_link
'%s %s',
sprintf(
__( 'Settings for %s updated successfully.', 'codepress-admin-columns' ),
sprintf( '<strong>%s</strong>', esc_html( $list_screen->get_title() ) )
),
ac_helper()->html->link( $list_screen->get_screen_link(), sprintf( __( 'View %s screen', 'codepress-admin-columns' ), $list_screen->get_label() ) )
)
);
}

Expand Down
23 changes: 19 additions & 4 deletions classes/Controller/ListScreenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function get_list_screen() {
if ( $list_id && $this->repository->exists( $list_id ) ) {
$list_screen = $this->repository->find( $list_id );

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

Expand All @@ -87,7 +87,7 @@ public function get_list_screen() {
}

// Initialize new
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
return $this->create_list_screen( $list_key );
}

// Last visited ID
Expand Down Expand Up @@ -117,7 +117,7 @@ public function get_list_screen() {
}

// Initialize new
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
return $this->create_list_screen( $list_key );
}

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

// Initialize new
return ListScreenTypes::instance()->get_list_screen_by_key( $list_key );
return $this->create_list_screen( $list_key );
}

/**
* @param string $key
*
* @return ListScreen|null
*/
private function create_list_screen( $key ) {
$list_screen = ListScreenTypes::instance()->get_list_screen_by_key( $key );

if ( ! $list_screen ) {
return null;
}

return $list_screen->set_layout_id( uniqid() );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions codepress-admin-columns.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Admin Columns
Version: 4.0.2
Version: 4.0.3
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.
Author: AdminColumns.com
Author URI: https://www.admincolumns.com
Expand Down Expand Up @@ -36,7 +36,7 @@
}

define( 'AC_FILE', __FILE__ );
define( 'AC_VERSION', '4.0.2' );
define( 'AC_VERSION', '4.0.3' );

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

Expand Down
Binary file modified languages/codepress-admin-columns-es_ES.mo
Binary file not shown.
Loading

0 comments on commit c5b952e

Please sign in to comment.