Changeset 12749 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
- Timestamp:
- 07/20/2023 04:01:22 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r12171 r12749 136 136 add_filter( 'pre_oembed_result', array( $this, 'pre_oembed_result_dont_embed_wordpress_org_anchors' ), 20, 2 ); 137 137 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 142 138 // Break users sessions / passwords when they get blocked, on the main forums only. 143 139 if ( 'wordpress.org' === get_blog_details()->domain ) { 144 add_ action( 'bbp_set_user_role', array( $this, 'user_blocked_password_handler' ), 10, 3 );140 add_filter( 'bbp_set_user_role', array( $this, 'user_blocked_password_handler' ), 10, 3 ); 145 141 } 146 142 } … … 1360 1356 * 1361 1357 * Note: This method is called even when the users role is not changed. 1358 * 1359 * See Audit_Log class for where the note is set/updated. 1362 1360 */ 1363 1361 public function user_blocked_password_handler( $new_role, $user_id, \WP_User $user ) { … … 1366 1364 // ~~~ is a reset password on WordPress.org. Let's ignore those. 1367 1365 if ( '~~~' === $user->user_pass ) { 1368 return ;1366 return $new_role; 1369 1367 } 1370 1368 … … 1374 1372 $blocked_role = bbp_get_blocked_role(); 1375 1373 $password_broken = ( 0 === strpos( $user->user_pass, $blocked_prefix ) ); 1376 $note_text = false;1377 1374 1378 1375 // WP_User::has_role() does not exist, and WP_User::has_cap( 'bbp_blocked' ) will be truthful for super admins. 1379 1376 $user_has_blocked_role = ! empty( $user->roles ) && in_array( $blocked_role, $user->roles, true ); 1380 1381 // Define what has blocked the user.1382 if ( ! ms_is_switched() ) {1383 $where_from = preg_replace( '!^https?://!i', '', home_url( is_admin() ? '/wp-admin' : '' ) );1384 } else {1385 // When we're switched, we can't determine the source of the switch, so we use a bit of URL parsing magic.1386 $where_from = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];1387 if ( str_contains( $where_from, '?' ) ) {1388 list( $where_from, ) = explode( '?', $where_from );1389 }1390 // Trim actual filename off, just the major path component.1391 $where_from = preg_replace( '!/[^/?]+\.[a-z]{3}$!i', '', $where_from );1392 }1393 1377 1394 1378 if ( … … 1413 1397 $manager = \WP_Session_Tokens::get_instance( $user->ID ); 1414 1398 $manager->destroy_all(); 1415 1416 // Add a user note about this action.1417 $note_text = sprintf(1418 $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.',1419 get_role( $new_role )->name,1420 $where_from1421 );1422 1423 // Used in wporg-login to add context.1424 $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user );1425 1399 } else if ( 1426 1400 $password_broken && … … 1440 1414 1441 1415 clean_user_cache( $user ); 1442 1443 // Add a user note about this action. 1444 $note_text = sprintf( 1445 $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.', 1446 get_role( $new_role )->name, 1447 $where_from 1448 ); 1449 1450 // Unused, here for consistency with above. 1451 $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user ); 1452 } 1453 1454 if ( $note_text ) { 1455 // Add a user note about this action. 1456 Plugin::get_instance()->user_notes->add_user_note_or_update_previous( 1457 $user->ID, 1458 $note_text 1459 ); 1460 } 1461 1462 } 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 () ) ? 'flagged' : '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 } 1416 } 1417 1418 // It's a filter, return the value. 1419 return $new_role; 1420 } 1421 1477 1422 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)