-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New reimbursement request and vendor payments status and notes functi…
…onality (#1051) * add new wcb-needs-followup status for payments * add new wcb-needs-followup status to network payments views * take new wcb-pending-approval status into consideration when doing the overdue vendor payments list * extend the notes field for vendor payments * add new private note metabox to vendor payments and reimbursement requests * limit the new notes for network admins and the request's author --------- Co-authored-by: ren <[email protected]>
- Loading branch information
1 parent
97c1d78
commit e21ab60
Showing
9 changed files
with
289 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ function get_post_statuses() { | |
'draft', | ||
'wcb-incomplete', | ||
'wcb-pending-approval', | ||
'wcb-needs-followup', | ||
'wcb-approved', | ||
'wcb-pending-payment', | ||
'wcb-paid', | ||
|
@@ -162,15 +163,6 @@ function init_meta_boxes() { | |
'high' | ||
); | ||
|
||
add_meta_box( | ||
'wcbrr_notes', | ||
esc_html__( 'Notes', 'wordcamporg' ), | ||
__NAMESPACE__ . '\render_notes_metabox', | ||
POST_TYPE, | ||
'side', | ||
'high' | ||
); | ||
|
||
add_meta_box( | ||
'wcbrr_general_information', | ||
esc_html__( 'General Information', 'wordcamporg' ), | ||
|
@@ -316,19 +308,6 @@ function render_status_metabox( $post ) { | |
require_once dirname( __DIR__ ) . '/views/reimbursement-request/metabox-status.php'; | ||
} | ||
|
||
/** | ||
* Render the Notes metabox | ||
* | ||
* @param WP_Post $post | ||
*/ | ||
function render_notes_metabox( $post ) { | ||
wp_nonce_field( 'notes', 'notes_nonce' ); | ||
|
||
$existing_notes = get_post_meta( $post->ID, '_wcbrr_notes', true ); | ||
|
||
require_once dirname( __DIR__ ) . '/views/reimbursement-request/metabox-notes.php'; | ||
} | ||
|
||
/** | ||
* Render General Information Metabox | ||
* | ||
|
@@ -520,7 +499,6 @@ function save_request( $post_id, $post ) { | |
} | ||
|
||
verify_metabox_nonces(); | ||
validate_and_save_notes( $post, $_POST['wcbrr_new_note'] ); | ||
|
||
/* | ||
* We need to determine if the user is allowed to modify the request -- in terms of this plugin's post_status | ||
|
@@ -673,7 +651,6 @@ function render_log_metabox( $post ) { | |
function verify_metabox_nonces() { | ||
$nonces = array( | ||
'status_nonce', | ||
'notes_nonce', | ||
'general_information_nonce', | ||
'payment_details_nonce', | ||
'expenses_nonce', | ||
|
@@ -743,95 +720,6 @@ function validate_and_save_expenses( $post_id, $expenses ) { | |
update_post_meta( $post_id, '_wcbrr_expenses', $expenses ); | ||
} | ||
|
||
/** | ||
* Validate and save expense data | ||
* | ||
* @param WP_Post $post | ||
* @param string $new_note_message | ||
*/ | ||
function validate_and_save_notes( $post, $new_note_message ) { | ||
|
||
// Save incomplete message. | ||
if ( isset( $_POST['wcp_mark_incomplete_notes'] ) ) { | ||
$safe_value = ''; | ||
if ( $post->post_status == 'wcb-incomplete' ) { | ||
$safe_value = wp_kses( $_POST['wcp_mark_incomplete_notes'], wp_kses_allowed_html( 'strip' ) ); | ||
} | ||
|
||
update_post_meta( $post->ID, '_wcp_incomplete_notes', $safe_value ); | ||
} | ||
|
||
$new_note_message = sanitize_text_field( wp_unslash( $new_note_message ) ); | ||
|
||
if ( empty( $new_note_message ) ) { | ||
return; | ||
} | ||
|
||
$notes = get_post_meta( $post->ID, '_wcbrr_notes', true ); | ||
if ( ! is_array( $notes ) ) { | ||
$notes = array(); | ||
} | ||
|
||
$new_note = array( | ||
'timestamp' => time(), | ||
'author_id' => get_current_user_id(), | ||
'message' => $new_note_message, | ||
); | ||
|
||
$notes[] = $new_note; | ||
|
||
update_post_meta( $post->ID, '_wcbrr_notes', $notes ); | ||
notify_parties_of_new_note( $post, $new_note ); | ||
|
||
\WordCamp_Budgets::log( $post->ID, get_current_user_id(), sprintf( 'Note: %s', $new_note_message ), array( | ||
'action' => 'note-added', | ||
) ); | ||
} | ||
|
||
/** | ||
* Notify WordCamp Central or the request author when new notes are added | ||
* | ||
* @param WP_Post $request | ||
* @param array $note | ||
*/ | ||
function notify_parties_of_new_note( $request, $note ) { | ||
$note_author = get_user_by( 'id', $note['author_id'] ); | ||
|
||
if ( $note_author->has_cap( 'manage_network' ) ) { | ||
$to = \WordCamp_Budgets::get_requester_formatted_email( $request->post_author ); | ||
$subject_prefix = sprintf( '[%s] ', get_wordcamp_name() ); | ||
} else { | ||
$to = '[email protected]'; | ||
$subject_prefix = ''; | ||
} | ||
|
||
if ( ! $to ) { | ||
return; | ||
} | ||
|
||
$subject = sprintf( '%sNew note on `%s`', $subject_prefix, sanitize_text_field( $request->post_title ) ); | ||
$note_author_name = \WordCamp_Budgets::get_requester_name( $note['author_id'] ); | ||
$request_url = admin_url( sprintf( 'post.php?post=%s&action=edit', $request->ID ) ); | ||
$headers = array( 'Reply-To: [email protected]' ); | ||
|
||
$message = sprintf( ' | ||
%s has added the following note on the reimbursement request for %s: | ||
%s | ||
You can view the request and respond to their note at: | ||
%s', | ||
sanitize_text_field( $note_author_name ), | ||
sanitize_text_field( $request->post_title ), | ||
sanitize_text_field( $note['message'] ), | ||
esc_url_raw( $request_url ) | ||
); | ||
$message = str_replace( "\t", '', $message ); | ||
|
||
wp_mail( $to, $subject, $message, $headers ); | ||
} | ||
|
||
/** | ||
* Notify the organizer when the status of their reimbursement changes or when notes are added | ||
* | ||
|
Oops, something went wrong.