diff --git a/modules/dashboard/widgets/dashboard-notepad.php b/modules/dashboard/widgets/dashboard-notepad.php index b61ced0f0..fa789b60f 100644 --- a/modules/dashboard/widgets/dashboard-notepad.php +++ b/modules/dashboard/widgets/dashboard-notepad.php @@ -18,7 +18,7 @@ public function init() { register_post_type( self::notepad_post_type, array( 'rewrite' => false, 'label' => __( 'Dashboard Note', 'edit-flow' ) - ) + ) ); $this->edit_cap = apply_filters( 'ef_dashboard_notepad_edit_cap', $this->edit_cap ); @@ -34,31 +34,29 @@ public function init() { public function handle_notepad_update() { global $pagenow; - if ( 'index.php' != $pagenow - || ( empty( $_POST['action'] ) || 'dashboard-notepad' != $_POST['action'] ) ) + if ( 'index.php' !== $pagenow || empty( $_POST['action'] ) || 'dashboard-notepad' !== $_POST['action'] ) { return; + } check_admin_referer( 'dashboard-notepad' ); - if ( ! current_user_can( $this->edit_cap ) ) + if ( ! current_user_can( $this->edit_cap ) ) { wp_die( EditFlow()->dashboard->messages['invalid-permissions'] ); + } - $current_id = (int) $_POST['notepad-id']; - $current_notepad = get_post( $current_id ); - $new_note = array( - 'post_content' => wp_filter_nohtml_kses( $_POST['note'] ), - 'post_type' => self::notepad_post_type, - 'post_status' => 'draft', - 'post_author' => get_current_user_id(), - ); - if ( $current_notepad - && self::notepad_post_type == $current_notepad->post_type - && ! isset ( $_POST['create-note'] ) ) { - $new_note['ID'] = $current_id; - wp_update_post( $new_note ); - } else { - wp_insert_post( $new_note ); + $note_data = array( + 'post_content' => isset( $_POST['note'] ) ? wp_filter_nohtml_kses( $_POST['note'] ) : '', + 'post_type' => self::notepad_post_type, + 'post_status' => 'draft', + 'post_author' => get_current_user_id(), + ); + + $existing_notepad = isset( $_POST['notepad-id'] ) ? get_post( absint( $_POST['notepad-id'] ) ) : null; + if ( isset( $existing_notepad->post_type ) && self::notepad_post_type === $existing_notepad->post_type ) { + $note_data['ID'] = $existing_notepad->ID; } + + wp_insert_post( $note_data ); } /**