0251 | whmcs line notify แจ้งเตือน invoice

เอาไปใส่ใน folder includes/hooks/linenotify.php (อย่าลืมเปิด tag php)

<?php
add_hook('EmailPreSend', 1, function($vars) {
 
    if (empty($vars['mergefields']) || empty($vars['mergefields']['client_custom_field_linenotifytoken'])) return;
    if ($vars['messagename'] == 'Invoice Created') {
        $message = "THZHost.com: มีใบแจ้งชำระเงินใหม่\n\n";
        foreach ($vars['mergefields']['invoice_items'] as $item) {
            $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n";
        }
        $message .= "\nยอดค้างชำระ: ".$vars['mergefields']['invoice_balance']->__toString()."\nกำหนดชำระ: ".$vars['mergefields']['invoice_date_due']."\nhttps://www.thzhost.com/viewinvoice.php?id=".$vars['mergefields']['invoice_id'];
        line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message);
 
    }
    elseif ($vars['messagename'] == 'Invoice Payment Reminder')
    {
        $message = "THZHost.com: ยอดชำระคงค้างใกล้ถึงกำหนดชำระ\n\n";
        foreach ($vars['mergefields']['invoice_items'] as $item) {
            $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n";
        }
        $message .= "\nยอดค้างชำระ: ".$vars['mergefields']['invoice_balance']->__toString()."\nกำหนดชำระ: ".$vars['mergefields']['invoice_date_due']."\nhttps://www.thzhost.com/viewinvoice.php?id=".$vars['mergefields']['invoice_id'];
        line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message);
    }
    elseif ($vars['messagename'] == 'Invoice Payment Confirmation')
    {
        $message = "THZHost.com: ยืนยันการชำระเงิน\n\n";
        foreach ($vars['mergefields']['invoice_items'] as $item) {
            $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n";
        }
        $message .= "\nยอดรวม: ".$vars['mergefields']['invoice_total']->__toString()."\nขอบคุณที่ชำระค่าบริการ";
        line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message);
    }
});
 
function line_notify_message($line_token, $message)
{
    file_put_contents('/tmp/linenotify', print_r($message, true));
    $line_api = 'https://notify-api.line.me/api/notify';
 
    $queryData = array('message' => $message);
    $queryData = http_build_query($queryData,'','&');
    $headerOptions = array(
        'http'=>array(
            'method'=>'POST',
            'timeout' => 5,
            'header'=> "Content-Type: application/x-www-form-urlencoded\r\n"
                ."Authorization: Bearer ".$line_token."\r\n"
                ."Content-Length: ".strlen($queryData)."\r\n",
            'content' => $queryData
        )
    );
    $context = stream_context_create($headerOptions);
    $result = file_get_contents($line_api, FALSE, $context);
    $res = json_decode($result);
    return $res;
}

Tags:

0250 | Scan + upgrade wp-super-cache ทั้งเครื่อง

สำหรับ shared hosting หรือ server ที่มี wordpress หลายๆ instance

ติดตั้ง wp-cli

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &amp;&amp; \
chmod +x wp-cli.phar &amp;&amp; \
sudo mv wp-cli.phar /usr/local/bin/

wp-cli upgrade wp-super-cache

ใช้คำสั่ง locate หาเว็บที่มี wp-super-cache แล้วใช้ wp-cli สั่ง upgrade เฉพาะ plugin wp-super-cache สำหรับเว็บที่ไม่ได้ใช้ wp-super-cache 1.7.2 (แก้ version php /คำสั่งด้วยนะคัรบ)

for i in $(locate /wp-content/plugins/wp-super-cache/wp-cache.php); do 
 
rootpath=$(echo $i | sed 's#/wp-content/plugins/wp-super-cache/wp-cache.php##g')
echo $rootpath
cd $rootpath
grep 'Version: 1.7.2' ./wp-content/plugins/wp-super-cache/wp-cache.php || \
sudo -u $(stat -c %U .) -- php7.3 $(which wp-cli.phar) plugin update wp-super-cache
 
done