Making WordPress.org


Ignore:
Timestamp:
01/19/2021 04:40:47 AM (6 years ago)
Author:
dd32
Message:

Support Forums: When automatically adding a "Forum role changed to.." user note, append it to the last note added if it's from the current user in the last 5 minutes.

This allows for a note added while blocking/unblocking a user to contain both the moderator note and the action performed.

See #4192.
Fixes #4691.

File:
1 edited

Legend:

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

    r10580 r10595  
    13011301                $blocked_role    = bbp_get_blocked_role();
    13021302                $password_broken = ( 0 === strpos( $user->user_pass, $blocked_prefix ) );
     1303                $note_text       = false;
    13031304
    13041305                if ( $blocked_role === $new_role && ! $password_broken ) {
     
    13221323
    13231324                        // 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                                 )
     1325                        $note_text = sprintf(
     1326                                'Forum role changed to %s.',
     1327                                get_role( $new_role )->name
    13301328                        );
    13311329                } else if (
     
    13481346
    13491347                        // Add a user note about this action.
     1348                        $note_text = sprintf(
     1349                                'Forum role changed to %s.',
     1350                                get_role( $new_role )->name
     1351                        );
     1352                }
     1353
     1354                if ( $note_text ) {
     1355                        // Add a user note about this action.
     1356                        $notes   = Plugin::get_instance()->user_notes->get_user_notes( $user->ID );
     1357                        $note_id = 0;
     1358
     1359                        // Check to see if the last note added was from the current user in the last few minutes, and if so, append to it.
     1360                        if ( $notes->count ) {
     1361                                $last_note_id = array_key_last( $notes->raw );
     1362                                $last_note    = $notes->raw[ $last_note_id ];
     1363                                if (
     1364                                        // Note from the current user
     1365                                        $last_note->moderator === wp_get_current_user()->user_nicename &&
     1366                                        // ..and created within 5 minutes.
     1367                                        absint( time() - strtotime( $last_note->date ) ) <= 5 * MINUTE_IN_SECONDS
     1368                                ) {
     1369                                        $note_id = $last_note_id;
     1370
     1371                                        // Prefix the existing message.
     1372                                        $note_text = trim( $last_note->text . "\n\n" . $note_text );
     1373                                }
     1374                        }
     1375
     1376                        // Add a user note about this action.
    13501377                        Plugin::get_instance()->user_notes->add_user_note(
    13511378                                $user->ID,
    1352                                 sprintf(
    1353                                         'Forum role changed to %s.',
    1354                                         get_role( $new_role )->name
    1355                                 )
     1379                                $note_text,
     1380                                null,
     1381                                $note_id
    13561382                        );
    13571383                }
Note: See TracChangeset for help on using the changeset viewer.