BP_Core_Members_Switching::action_admin_notices()

Displays the ‘Switched to {user}’ and ‘Switch back to {user}’ messages in the admin area.

Description

Source

File: bp-members/classes/class-bp-core-members-switching.php

	public function action_admin_notices() {
		$user     = wp_get_current_user();
		$old_user = self::get_old_user();

		if ( $old_user ) {
			?>
			<div id="bp_member_switching" class="updated notice is-dismissible">
				<p><span class="dashicons dashicons-admin-users" style="color:#56c234" aria-hidden="true"></span>
					<?php
					$message       = '';
					$just_switched = isset( $_GET['user_switched'] );
					if ( $just_switched ) {
						$message = esc_html( sprintf(
						/* Translators: 1: user display name; 2: username; */
							__( 'Switched to %1$s (%2$s).', 'buddyboss' ),
							$user->display_name,
							$user->user_login
						) );
					}
					$switch_back_url = add_query_arg( array(
						'redirect_to' => urlencode( self::current_url() ),
					), self::switch_back_url( $old_user ) );

					$message .= sprintf(
						' <a href="%s">%s</a>.',
						esc_url( $switch_back_url ),
						esc_html( sprintf(
						/* Translators: 1: user display name; 2: username; */
							__( 'Switch back to %1$s (%2$s)', 'buddyboss' ),
							$old_user->display_name,
							$old_user->user_login
						) )
					);

					/**
					 * Filters the contents of the message that's displayed to switched users in the admin area.
					 *
					 * @since BuddyBoss 1.0.0
					 *
					 * @param string $message The message displayed to the switched user.
					 * @param WP_User $user The current user object.
					 * @param WP_User $old_user The old user object.
					 * @param string $switch_back_url The switch back URL.
					 * @param bool $just_switched Whether the user made the switch on this page request.
					 */
					$message = apply_filters( 'bp_member_switching_switched_message', $message, $user, $old_user, $switch_back_url, $just_switched );
					echo $message; // WPCS: XSS ok.
					?>
				</p>
			</div>
			<?php
		} elseif ( isset( $_GET['user_switched'] ) ) {
			?>
			<div id="bp_member_switching" class="updated notice is-dismissible">
				<p>
					<?php
					if ( isset( $_GET['switched_back'] ) ) {
						echo esc_html( sprintf(
						/* Translators: 1: user display name; 2: username; */
							__( 'Switched back to %1$s (%2$s).', 'buddyboss' ),
							$user->display_name,
							$user->user_login
						) );
					} else {
						echo esc_html( sprintf(
						/* Translators: 1: user display name; 2: username; */
							__( 'Switched to %1$s (%2$s).', 'buddyboss' ),
							$user->display_name,
							$user->user_login
						) );
					}
					?>
				</p>
			</div>
			<?php
		}
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.