46 | | /** |
47 | | * Checks if a user note is added and saves it to user's meta data. |
48 | | * |
49 | | * @param string $action Requested action. |
50 | | */ |
51 | | public function add_user_note( $action = '' ) { |
52 | | if ( 'wporg_bbp_add_user_note' !== $action || ! current_user_can( 'moderate' ) ) { |
53 | | return; |
54 | | } |
55 | | |
56 | | $user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0; |
57 | | $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; |
58 | | |
59 | | $note_id = isset( $_POST['note_id'] ) ? (int) $_POST['note_id'] : 0; |
60 | | $note_text = isset( $_POST['note_text'] ) ? wp_kses( $_POST['note_text'], array( 'a' => array( 'href' => true ) ) ) : ''; |
61 | | |
62 | | if ( ! $user_id || ! $note_text ) { |
63 | | return; |
64 | | } |
65 | | |
66 | | // Make sure our nonces are in order. |
67 | | if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-add-user-note_%d', $user_id ) ) ) { |
68 | | return; |
69 | | } |
70 | | |
| 48 | public function save_user_note( $user_id, $note_text, $post_id = 0, $note_id = 0 ) { |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Checks if a user note is added and saves it to user's meta data. |
| 98 | * |
| 99 | * @param string $action Requested action. |
| 100 | */ |
| 101 | public function add_user_note( $action = '' ) { |
| 102 | if ( 'wporg_bbp_add_user_note' !== $action || ! current_user_can( 'moderate' ) ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | $user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0; |
| 107 | $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; |
| 108 | |
| 109 | $note_id = isset( $_POST['note_id'] ) ? (int) $_POST['note_id'] : 0; |
| 110 | $note_text = isset( $_POST['note_text'] ) ? wp_kses( $_POST['note_text'], array( 'a' => array( 'href' => true ) ) ) : ''; |
| 111 | |
| 112 | if ( ! $user_id || ! $note_text ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | // Make sure our nonces are in order. |
| 117 | if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-add-user-note_%d', $user_id ) ) ) { |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | $this->save_user_note( $user_id, $note_text, $post_id, $note_id ); |
| 418 | public function edit_user_display_note_form() { |
| 419 | if ( bbp_get_displayed_user_id() === get_current_user_id() ) { |
| 420 | return; |
| 421 | } |
| 422 | ?> |
| 423 | <fieldset class="bbp-form"> |
| 424 | <div> |
| 425 | <label for="wporg-bbp-user-note-text"><?php esc_html_e( 'Add user note:', 'wporg-forums' ); ?></label> |
| 426 | <textarea name="note_text" id="wporg-bbp-user-note-text" cols="40" rows="5"></textarea> |
| 427 | </div> |
| 428 | </fieldset> |
| 429 | <?php |
| 430 | } |
| 431 | |
| 432 | public function edit_user_add_user_note( $user_id ) { |
| 433 | if ( ! current_user_can( 'moderate' ) ) { |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | if ( ! isset( $_POST['note_text'] ) || empty( $_POST['note_text'] ) ) { |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | $this->save_user_note( $user_id, wp_kses( $_POST['note_text'], array( 'a' => array( 'href' => true ) ) ) ); |
| 442 | } |
| 443 | |