Skip to content

Feature request: login automagically if the plugin is installed #1

@vinkla

Description

@vinkla

I would like to propose two ideas for improving the plugin:

1. Enable super admin login on local environments when the plugin is installed.

It would be beneficial to allow users to log in as a super admin in a local environment when the plugin is installed. Here is a code snippet demonstrating this concept:

$id = 1;

if (
    wp_get_environment_type() !== 'local' || // if not local
    is_user_logged_in() || // if user is already logged in
    is_admin() === false || // if not admin
    is_super_admin($id) === false // if user is not super admin
) {
    return;
}

$user = get_user_by('id', $id);
$login = $user->data->user_login;

wp_set_current_user($id, $login);
wp_set_auth_cookie($id, true);
do_action('wp_login', $login, $user);

if (isset($_SERVER['REQUEST_URI'])) {
    wp_safe_redirect($_SERVER['REQUEST_URI']);
    exit;
}

2. Implement a constant for automatic super admin login in local environments.

As an alternative, introducing a constant that enables automatic super admin login in local environments when set to true could be advantageous:

AUTOMATIC_LOGIN=true

One of these enhancements would provide additional flexibility and ease of use for developers working with the plugin in their local environments. Please let me know your thoughts on these suggestions. I prefer the first one 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions