Please wait while my tweets load

Quando Omni Flunkus Moritati

Category: Programming

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

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 หลังจากนั้นค่อยส่งกลับมาหน้าเดิม

Check and cut the strings by length in PHP

function striptext($message, $position)
{
if (strlen($message) > $position) // Check if string length is exceeded
{
$post = substr($message,$position,1);
if ($post !=” “) // If last character is not space
{
while($post !=” “) // Check next character one by one
{
$i=1;
$position=$position+$i;
$post = substr($message,$position,1);
}
}
$post = substr($message,0,$position);
$text = $post . ‘…’; // Add dots
} else {
$text = $message . ‘…’; // Or do nothing
}
return($text);
}
Usage: [...]