Skip to content

Commit ae18d74

Browse files
committed
Clean up dashboard-note logic
1 parent 2507889 commit ae18d74

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

modules/dashboard/widgets/dashboard-notepad.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,29 @@ public function init() {
3434
public function handle_notepad_update() {
3535
global $pagenow;
3636

37-
if ( 'index.php' != $pagenow
38-
|| ( empty( $_POST['action'] ) || 'dashboard-notepad' != $_POST['action'] ) )
37+
if ( 'index.php' !== $pagenow || empty( $_POST['action'] ) || 'dashboard-notepad' !== $_POST['action'] ) {
3938
return;
39+
}
4040

4141
check_admin_referer( 'dashboard-notepad' );
4242

43-
if ( ! current_user_can( $this->edit_cap ) )
43+
if ( ! current_user_can( $this->edit_cap ) ) {
4444
wp_die( EditFlow()->dashboard->messages['invalid-permissions'] );
45+
}
4546

46-
$current_id = (int) $_POST['notepad-id'];
47-
$current_notepad = get_post( $current_id );
48-
$new_note = array(
49-
'post_content' => wp_filter_nohtml_kses( $_POST['note'] ),
50-
'post_type' => self::notepad_post_type,
51-
'post_status' => 'draft',
52-
'post_author' => get_current_user_id(),
53-
);
54-
if ( $current_notepad
55-
&& self::notepad_post_type == $current_notepad->post_type
56-
&& ! isset ( $_POST['create-note'] ) ) {
57-
$new_note['ID'] = $current_id;
58-
wp_update_post( $new_note );
59-
} else {
60-
wp_insert_post( $new_note );
47+
$note_data = array(
48+
'post_content' => wp_filter_nohtml_kses( $_POST['note'] ),
49+
'post_type' => self::notepad_post_type,
50+
'post_status' => 'draft',
51+
'post_author' => get_current_user_id(),
52+
);
53+
54+
$existing_notepad = get_post( absint( $_POST['notepad-id'] ) );
55+
if ( isset( $existing_notepad->post_type ) && self::notepad_post_type === $existing_notepad->post_type ) {
56+
$note_data['ID'] = $existing_notepad->ID;
6157
}
58+
59+
wp_insert_post( $note_data );
6260
}
6361

6462
/**

0 commit comments

Comments
 (0)