Changeset 12161 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php
- Timestamp:
- 10/31/2022 03:47:05 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php
r11527 r12161 147 147 148 148 /** 149 * Saves a note to a users meta data. Suffixes to previous user note if by same moderator within a timeframe. 150 * 151 * @param int $user_id The user ID. 152 * @param string $note_text The note text to add. 153 * @param int $post_id The support thread this text is related to. Optional. 154 * @param int $timeframe The timeframe used to determine if the previous note should be updated. Optional. Default 5 minutes. 155 */ 156 public function add_user_note_or_update_previous( $user_id, $note_text, $post_id = 0, $timeframe = 300 ) { 157 // Default to adding a new note.. 158 $note_id = 0; 159 160 // Add a user note about this action. 161 $existing_notes = $this->get_user_notes( $user_id ); 162 163 // Check to see if the last note added was from the current user in the last few minutes, and if so, append to it. 164 if ( $existing_notes->count ) { 165 $last_note_id = array_key_last( $existing_notes->raw ); 166 $last_note = $existing_notes->raw[ $last_note_id ]; 167 if ( 168 // Note from the current user 169 $last_note->moderator === wp_get_current_user()->user_nicename && 170 // ..and created within $timeframe seconds 171 absint( time() - strtotime( $last_note->date ) ) <= $timeframe 172 ) { 173 $note_id = $last_note_id; 174 175 // Prefix the existing message. 176 $note_text = trim( $last_note->text . "\n\n" . $note_text ); 177 } 178 } 179 180 return $this->add_user_note( $user_id, $note_text, $post_id, $note_id ); 181 } 182 183 /** 149 184 * Deletes a previously added note from user's meta data. 150 185 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)