Making WordPress.org


Ignore:
Timestamp:
03/02/2022 07:51:58 AM (3 years ago)
Author:
dd32
Message:

Support: User Blocking: When blocking a user, add where they've been blocked from, and context if possible.

Fixes #5764.

File:
1 edited

Legend:

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

    r11350 r11623  
    13361336        $user_has_blocked_role = ! empty( $user->roles ) && in_array( $blocked_role, $user->roles, true );
    13371337
     1338        // Define what has blocked the user.
     1339        if ( ! ms_is_switched() ) {
     1340            $where_from = preg_replace( '!^https?://!i', '', home_url( is_admin() ? '/wp-admin' : '' ) );
     1341        } else {
     1342            // When we're switched, we can't determine the source of the switch, so we use a bit of URL parsing magic.
     1343            $where_from = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     1344            if ( str_contains( $where_from, '?' ) ) {
     1345                list( $where_from, ) = explode( '?', $where_from );
     1346            }
     1347            // Trim actual filename off, just the major path component.
     1348            $where_from = preg_replace( '!/[^/?]+\.[a-z]{3}$!i', '', $where_from  );
     1349        }
     1350
    13381351        if (
    13391352            ( $blocked_role === $new_role || $user_has_blocked_role ) &&
     
    13601373            // Add a user note about this action.
    13611374            $note_text = sprintf(
    1362                 'Forum role changed to %s.',
    1363                 get_role( $new_role )->name
     1375                $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.',
     1376                get_role( $new_role )->name,
     1377                $where_from
    13641378            );
     1379
     1380            // Used in wporg-login to add context.
     1381            $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user );
    13651382        } else if (
    13661383            $password_broken &&
     
    13831400            // Add a user note about this action.
    13841401            $note_text = sprintf(
    1385                 'Forum role changed to %s.',
    1386                 get_role( $new_role )->name
     1402                $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.',
     1403                get_role( $new_role )->name,
     1404                $where_from
    13871405            );
     1406
     1407            // Unused, here for consistency with above.
     1408            $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user );
    13881409        }
    13891410
Note: See TracChangeset for help on using the changeset viewer.