Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support User Switching Plugin #87

Open
ouun opened this issue Feb 3, 2025 · 0 comments
Open

Support User Switching Plugin #87

ouun opened this issue Feb 3, 2025 · 0 comments

Comments

@ouun
Copy link
Contributor

ouun commented Feb 3, 2025

Needed a shortcut here, which I solved with:

/**
 * Add "Switch to User" button to User Profile screen
 */
add_action('wp_user_profiles_status_metabox_after', function ($user) {
    if (! function_exists('switch_to_user') || ! $user || ! current_user_can('switch_to_user', $user->ID)) {
        return;
    }

    $url = add_query_arg([
        'redirect_to' => rawurlencode(user_switching::current_url()),
    ], user_switching::switch_to_url($user));

    ?>
	<div class="submitbox">
		<div id="major-publishing-actions">
			<div id="publishing-action">
				<a href="<?php echo esc_url($url); ?>"><?php esc_html_e('Switch&nbsp;To', 'user-switching') ?></a>
			</div>
			<div class="clear"></div>
		</div>
	</div>
	<?php
});

It adds a "Switch to this user" link below the save button.

Image

Is this something that could land in the plugin? If yes, happy to add a PR if you let me know where it fits best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant