Changeset 10580
- Timestamp:
- 01/14/2021 06:30:11 AM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r10578 r10580 1285 1285 /** 1286 1286 * Catch a user being blocked / unblocked and set their password appropriately. 1287 * 1288 * Note: This method is called even when the users role is not changed. 1287 1289 */ 1288 1290 public function user_blocked_password_handler( $new_role, $user_id, \WP_User $user ) { … … 1319 1321 $manager->destroy_all(); 1320 1322 1323 // Add a user note about this action. 1324 Plugin::get_instance()->user_notes->add_user_note( 1325 $user->ID, 1326 sprintf( 1327 'Forum role changed to %s.', 1328 get_role( $new_role )->name 1329 ) 1330 ); 1321 1331 } else if ( 1322 1332 $password_broken && … … 1336 1346 1337 1347 clean_user_cache( $user ); 1338 } 1348 1349 // Add a user note about this action. 1350 Plugin::get_instance()->user_notes->add_user_note( 1351 $user->ID, 1352 sprintf( 1353 'Forum role changed to %s.', 1354 get_role( $new_role )->name 1355 ) 1356 ); 1357 } 1358 1339 1359 } 1340 1360 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php
r10492 r10580 22 22 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 23 23 24 add_action( 'bbp_post_request', array( $this, 'add_user_note ' ) );25 add_action( 'bbp_get_request', array( $this, 'delete_user_note ' ) );24 add_action( 'bbp_post_request', array( $this, 'add_user_note_request' ) ); 25 add_action( 'bbp_get_request', array( $this, 'delete_user_note_request' ) ); 26 26 27 27 add_action( 'bbp_theme_after_topic_author_details', array( $this, 'display_user_notes_toggle_link' ) ); … … 49 49 * @param string $action Requested action. 50 50 */ 51 public function add_user_note ( $action = '' ) {51 public function add_user_note_request( $action = '' ) { 52 52 if ( 'wporg_bbp_add_user_note' !== $action || ! current_user_can( 'moderate' ) ) { 53 53 return; … … 69 69 } 70 70 71 $this->add_user_note( $user_id, $note_text, $post_id, $note_id ); 72 73 $redirect_url = set_url_scheme( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 74 75 // Redirect to clear form data. 76 bbp_redirect( $redirect_url ); 77 } 78 79 /** 80 * Saves a note to a users meta data. 81 * 82 * @param int $user_id The User ID. 83 * @param string $note_text The note text to add. 84 * @param int $post_id The support thread this text is related to. Optional. 85 * @param int $note_id The note ID to edit. Optional. 86 */ 87 public function add_user_note( $user_id, $note_text, $post_id = 0, $note_id = 0 ) { 71 88 // Make sure the user exists. 72 89 $user = get_userdata( $user_id ); 73 90 if ( ! $user ) { 74 return ;91 return false; 75 92 } 76 93 … … 101 118 $user_notes[ $note_id ]->moderator !== wp_get_current_user()->user_nicename 102 119 ) { 103 return ;120 return false; 104 121 } 105 122 … … 115 132 update_user_meta( $user_id, self::META, $user_notes ); 116 133 117 $redirect_url = set_url_scheme( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 118 119 // Redirect to clear form data. 120 bbp_redirect( $redirect_url ); 134 return true; 121 135 } 122 136 … … 126 140 * @param string $action Requested action. 127 141 */ 128 public function delete_user_note ( $action = '' ) {142 public function delete_user_note_request( $action = '' ) { 129 143 if ( 'wporg_bbp_delete_user_note' !== $action || ! current_user_can( 'keep_gate' ) ) { 130 144 return; … … 143 157 } 144 158 159 $this->delete_user_note( $user_id, $note_id ); 160 161 $redirect_url = remove_query_arg( array( 'action', 'user_id', 'note_id', '_wpnonce' ) ); 162 163 // Redirect to clear URL. 164 bbp_redirect( $redirect_url ); 165 } 166 167 /** 168 * Delete a user note. 169 * 170 * @param int $user_id The user ID. 171 * @param int $note_id The note ID. 172 */ 173 public function delete_user_note( $user_id, $note_id ) { 145 174 // Make sure the user exists. 146 175 $user = get_userdata( $user_id ); 147 176 if ( ! $user ) { 148 return ;177 return false; 149 178 } 150 179 151 180 // Get an array of existing notes. 152 181 $user_notes = get_user_meta( $user_id, self::META, true ); 153 if ( ! $user_notes ) {154 return ;182 if ( ! $user_notes || ! isset( $user_notes[ $note_id ] ) ) { 183 return false; 155 184 } 156 185 … … 164 193 update_user_meta( $user_id, self::META, $user_notes ); 165 194 166 $redirect_url = remove_query_arg( array( 'action', 'user_id', 'note_id', '_wpnonce' ) ); 167 168 // Redirect to clear URL. 169 bbp_redirect( $redirect_url ); 195 return true; 170 196 } 171 197
Note: See TracChangeset
for help on using the changeset viewer.