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

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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.