Filter Since 1.5.5 uncanny-learndash-toolkit

user_switching_in_footer

Allows the 'Switch back to {user}' link in the WordPress footer to be disabled. Filters whether to show the 'Switch back to {user}' link in the WordPress footer.

add_filter( 'user_switching_in_footer', $callback, 10, 1 );

Description

Filters whether the "Switch back to {user}" link is displayed in the WordPress footer. Developers can set this filter to `false` to disable its appearance. This hook fires during the `wp_footer` action, allowing conditional control over this user-switching element.


Usage

add_filter( 'user_switching_in_footer', 'your_function_name', 10, 1 );

Parameters

$show_in_footer (bool)
Whether to show the 'Switch back to {user}' link in footer.

Return Value

The filtered value.


Examples

// Example: Disable the 'Switch back to {user}' link in the footer for administrators.
add_filter( 'user_switching_in_footer', 'my_disable_footer_switch_back_for_admins', 10, 1 );

function my_disable_footer_switch_back_for_admins( $show_in_footer ) {
    // Check if the current user has the 'manage_options' capability, which is typically for administrators.
    if ( current_user_can( 'manage_options' ) ) {
        // If the user is an administrator, return false to hide the link in the footer.
        return false;
    }

    // For all other users, return the original value, allowing the link to be displayed if it was intended.
    return $show_in_footer;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/user-switching.php:695

public function action_wp_footer() {
		if ( is_admin_bar_showing() || did_action( 'wp_meta' ) ) {
			return;
		}

		/**
		 * Allows the 'Switch back to {user}' link in the WordPress footer to be disabled.
		 *
		 * @since 1.5.5
		 *
		 * @param bool $show_in_footer Whether to show the 'Switch back to {user}' link in footer.
		 */
		if ( ! apply_filters( 'user_switching_in_footer', true ) ) {
			return;
		}

		$old_user = self::get_old_user();

		if ( $old_user instanceof WP_User ) {
			$url = add_query_arg(
				array(
					'redirect_to' => urlencode( self::current_url() ),
				),
				self::switch_back_url( $old_user )
			);
			printf(
				'<p id="user_switching_switch_on" style="position:fixed;bottom:40px;padding:0;margin:0;left:10px;font-size:13px;z-index:99999;"><a href="%s">%s</a></p>',
				esc_url( $url ),
				esc_html( self::switch_back_message( $old_user ) )
			);
		}
	}

Scroll to Top