วิธีใช้ login ของ wordpress กับ script ที่เราเขียนเอง

by Paul

The script below checks if user already logged in, if not, it will redirect to Wordpress Login page then send the user back after they enter the correct username & password.

มีคนถามเรื่องนี้มา ตัวเราก็อยากรู้เองเหมือนกัน เลยไปค้น ๆ ดูแล้วมั่วเอา ได้ สคริปท์แบบนี้

<?php

require_once(‘wp-load.php’);
if (!is_user_logged_in())
{
auth_redirect();
}

?>

เป็นการหา cookie ของ wordpress ถ้าไม่เจอจะส่งไปที่หน้า login หลังจากนั้นค่อยส่งกลับมาหน้าเดิม