Skip to content

Instantly share code, notes, and snippets.

@holly
Last active March 16, 2025 03:05
Show Gist options
  • Save holly/24a08667f4c6706d63d0b4e4bacf7bf5 to your computer and use it in GitHub Desktop.
Save holly/24a08667f4c6706d63d0b4e4bacf7bf5 to your computer and use it in GitHub Desktop.
wordpress auto login
<?php
define('WP_USE_THEMES', false);
require_once __DIR__ . '/wp-load.php';
$user_id = 1;
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id, true);
wp_redirect(admin_url());
<?php
define('WP_USE_THEMES', false);
require_once __DIR__ . '/wp-load.php';
$user_id = 1; // 管理者ユーザー
$expiration = time() + 3600; // クッキーの有効期限
$token = "111";
// WordPressのキーやハッシュ関数を利用
$expire = $expiration; // For use in setcookie()
$cookie_name = 'wordpress_logged_in_' . md5( site_url() );
$cookie_value = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in');
$cookie_domain = "";
if (COOKIE_DOMAIN === "") {
$cookie_domain = parse_url(site_url(), PHP_URL_HOST);
} else {
$cookie_domain = COOKIE_DOMAIN;
}
wp_set_current_user($user_id);
setcookie( $cookie_name, $cookie_value, $expiration, COOKIEPATH, $cookie_domain, true, true );
$cookie_name = 'wordpress_sec_' . md5( site_url() );
$cookie_value = wp_generate_auth_cookie( $user_id, $expiration, 'secure_auth');
setcookie( $cookie_name, $cookie_value, $expiration, COOKIEPATH, $cookie_domain, true, true );
wp_redirect(admin_url());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment