← Back
Editing: wpck-autologin.php
<?php /** * Plugin Name: WPCK Auto Login * Description: One-click admin login for the WPmanage control panel. * Consumes a single-use token that an authenticated panel operator created * server-side over SSH, logs the matching WordPress user in, and redirects to * wp-admin. Tokens live in a short-lived transient (~2 min) and are deleted the * moment they are used, so a link cannot be replayed. Installed as a MUST-USE * plugin so it is always active and survives backup/restore (wp-restore.sh leaves * mu-plugins/ untouched). * Version: 1.0 * Author: WPmanage */ if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'init', function () { if ( empty( $_GET['wpck_sso'] ) ) { return; } // Tokens are hex only; reject anything else outright. $token = preg_replace( '/[^a-f0-9]/', '', (string) $_GET['wpck_sso'] ); if ( strlen( $token ) < 16 ) { return; } $key = 'wpck_sso_' . $token; $uid = get_transient( $key ); if ( false === $uid || '' === $uid ) { wp_die( 'This one-time login link has expired or was already used. Generate a new one from the control panel.', 'Login link expired', array( 'response' => 403 ) ); } // Single use: burn the token before logging in. delete_transient( $key ); $user = get_user_by( 'id', (int) $uid ); if ( ! $user ) { wp_die( 'The account for this login link no longer exists.', 'Login failed', array( 'response' => 403 ) ); } wp_set_current_user( $user->ID ); wp_set_auth_cookie( $user->ID, false ); do_action( 'wp_login', $user->user_login, $user ); wp_safe_redirect( admin_url() ); exit; }, 0 );
Save File
Cancel