Changeset 10580 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php
- Timestamp:
- 01/14/2021 06:30:11 AM (5 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
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.