- Mysql Events
- Sending mail over SMTP in php
- Worpress Multisite Network
- User Roles in wordpress
MySQl Events:
I had shifted the dbless mail verification to database finally, but now how to automatically expire the records after few minutes. This is where I learned about mysql events.
MySQL Events are tasks that run according to a schedule, we can create events to be scheduled to run every 5 minutes or at a specific time.
DELIMITER //
create EVENT delete_verification_tokens
ON SCHEDULE EVERY 1 MINUTE
DO
BEGIN
DELETE FROM verification
WHERE addedAt < NOW() - INTERVAL 2 MINUTE;
END;
//
DELIMITER ;
this will delete rows from verification table that are 2 minutes older.
You can read more about MySQL events from here
Sending mails over SMTP in php
I wanted to test my application if it really works or not, I was using mailhog to capture the mails sent and read them from there.
the default mail() function in php does not support SMTP authentication so we are going to use an external library for this:
phpMailer:
- install it using
composer require phpmailer/phpmailer
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
require 'SubscribersDatabase.php';
require 'EmailController.php';
$database = new SubscribersDatabase();
$emails = $database->getAllEmails();
if (!$emails) {
die();
}
$emailController = new EmailController();
foreach ($emails as $email) {
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'host';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('pratik@githubtimeline.local', 'Admin');
echo $email;
$mail->addAddress($email);
$subject = "Github Timeline Updates";
$message = $emailController->getUpdateMail();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html";
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
}
To get a free 300mails/day SMTP acoount you can signup on to Brevo
WordPress Multisite
We can create multuple files using same wordpress installation, this feature is called wordpress multisite. We can manage separate websites from same dashboard.
Multisite allows us to manage plugins and themese differently for different sites added, we can also add site admins for different sites and delegate the site management to them
User Roles in WordPress
- Below roles can be applied to users:
- Subscriber
- Contributor
- Author
- Editor
- Administrator
- Subscriber
- can read posts
- can access their profile
- Contributor
- can edit posts and delete posts
- Author
- Create new posts, publish them, edit posts, delete posts
- can upload files
- Editor
- publish new pages and posts
- edit and delete pages and posts
- manage categories
- upload files
- Administrator
- manage plugins and themes
- manage users
- manage files
- manage posts and pages
- delete site
- When we are using multisite super admin role is there, super admin can:
- manage sites
- manage network
Overall wordpress is a really powerfull tool that we can use to create our own sites having little to no knowledge about coding websites. The marketplace has plenty of themes and plugins that we can choose from, if we don’t like them we can create our own using block editor.
Leave a Reply