Making WordPress.org


Ignore:
Timestamp:
01/14/2021 06:30:11 AM (6 years ago)
Author:
dd32
Message:

Support Forums: Add a user log entry when a user is blocked or unblocked.

See #4691.
See #2537.

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  
    2222                add_action( 'wp_enqueue_scripts',                   array( $this, 'enqueue_scripts' ) );
    2323
    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' ) );
    2626
    2727                add_action( 'bbp_theme_after_topic_author_details', array( $this, 'display_user_notes_toggle_link' ) );
     
    4949         * @param string $action Requested action.
    5050         */
    51         public function add_user_note( $action = '' ) {
     51        public function add_user_note_request( $action = '' ) {
    5252                if ( 'wporg_bbp_add_user_note' !== $action || ! current_user_can( 'moderate' ) ) {
    5353                        return;
     
    6969                }
    7070
     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 ) {
    7188                // Make sure the user exists.
    7289                $user = get_userdata( $user_id );
    7390                if ( ! $user ) {
    74                         return;
     91                        return false;
    7592                }
    7693
     
    101118                                $user_notes[ $note_id ]->moderator !== wp_get_current_user()->user_nicename
    102119                        ) {
    103                                 return;
     120                                return false;
    104121                        }
    105122
     
    115132                update_user_meta( $user_id, self::META, $user_notes );
    116133
    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;
    121135        }
    122136
     
    126140         * @param string $action Requested action.
    127141         */
    128         public function delete_user_note( $action = '' ) {
     142        public function delete_user_note_request( $action = '' ) {
    129143                if ( 'wporg_bbp_delete_user_note' !== $action || ! current_user_can( 'keep_gate' ) ) {
    130144                        return;
     
    143157                }
    144158
     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 ) {
    145174                // Make sure the user exists.
    146175                $user = get_userdata( $user_id );
    147176                if ( ! $user ) {
    148                         return;
     177                        return false;
    149178                }
    150179
    151180                // Get an array of existing notes.
    152181                $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;
    155184                }
    156185
     
    164193                update_user_meta( $user_id, self::META, $user_notes );
    165194
    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;
    170196        }
    171197
Note: See TracChangeset for help on using the changeset viewer.