Making WordPress.org


Ignore:
Timestamp:
10/31/2022 03:47:05 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Create a user notes entry every time a user is flagged or unflagged.

This also adds a generic User_Notes function that updates the previous user-note if made within 5 minutes, as used by the forum role changer, so that the flagged/unflagged note is added to any recent descriptive reason.

Fixes #6554.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r12146 r12161  
    136136        add_filter( 'pre_oembed_result', array( $this, 'pre_oembed_result_dont_embed_wordpress_org_anchors' ), 20, 2 );
    137137
     138        // Add a user note when flagging/unflagging a user.
     139        add_filter( 'wporg_bbp_flag_user', array( $this, 'log_user_flag_changes' ) );
     140        add_filter( 'wporg_bbp_unflag_user', array( $this, 'log_user_flag_changes' ) );
     141
    138142        // Break users sessions / passwords when they get blocked, on the main forums only.
    139143        if ( 'wordpress.org' === get_blog_details()->domain ) {
     
    14501454        if ( $note_text ) {
    14511455            // Add a user note about this action.
    1452             $notes   = Plugin::get_instance()->user_notes->get_user_notes( $user->ID );
    1453             $note_id = 0;
    1454 
    1455             // Check to see if the last note added was from the current user in the last few minutes, and if so, append to it.
    1456             if ( $notes->count ) {
    1457                 $last_note_id = array_key_last( $notes->raw );
    1458                 $last_note    = $notes->raw[ $last_note_id ];
    1459                 if (
    1460                     // Note from the current user
    1461                     $last_note->moderator === wp_get_current_user()->user_nicename &&
    1462                     // ..and created within 5 minutes.
    1463                     absint( time() - strtotime( $last_note->date ) ) <= 5 * MINUTE_IN_SECONDS
    1464                 ) {
    1465                     $note_id = $last_note_id;
    1466 
    1467                     // Prefix the existing message.
    1468                     $note_text = trim( $last_note->text . "\n\n" . $note_text );
    1469                 }
    1470             }
    1471 
    1472             // Add a user note about this action.
    1473             Plugin::get_instance()->user_notes->add_user_note(
     1456            Plugin::get_instance()->user_notes->add_user_note_or_update_previous(
    14741457                $user->ID,
    1475                 $note_text,
    1476                 null,
    1477                 $note_id
     1458                $note_text
    14781459            );
    14791460        }
    14801461
    14811462    }
     1463
     1464    /**
     1465     * Add a user note when a user is flagged / unflagged.
     1466     */
     1467    function log_user_flag_changes( $user_id ) {
     1468        $flag_action = ( 'wporg_bbp_flag_user' === current_filter () ) ? 'flaged' : 'unflagged';
     1469
     1470        $note_text = "User {$flag_action}.";
     1471
     1472        Plugin::get_instance()->user_notes->add_user_note_or_update_previous(
     1473            $user_id,
     1474            $note_text
     1475        );
     1476    }
    14821477}
Note: See TracChangeset for help on using the changeset viewer.