WordPress plugin to email commentators of posts

The need to email came up when I wanted to notify commentators of my previous announcement posts regarding my plugin - Facebook Like Thumbnail, about its new version which is a rewrite and has lot of goodness in it. I looked it up, and I found a plugin by Yoast, which just adds all the commentators in Bcc and let you email using your mail client. I definitely wanted a better solution where they are emailed separately along with their actual comment so as to remind them that they left a comment on my site earlier and this email is in regard to the same topic.

I build a free plugin, which is now hosted on WordPress.org repo - Email Posts Commentators, and the way it works is, you can select multiple posts to be processed together. Specify your own email as Bcc and even lets you exclude email addresses from the comments of the selected posts. You write down your message along with email subject and an email goes out to them. Take a look at the screenshot to see how its admin screen looks like and how does the email itself look like.

Admin screen

Admin screen

Email that goes out

Email that goes out

If you run into issues, using the plugin, please report them here - https://github.com/ashfame/email-posts-commentators/issues

Updated Facebook Like Thumbnail WordPress plugin (v0.3.1) released

I just pushed out the latest version of my plugin Facebook Like Thumbnail, v0.3.1 to be precise, on WordPress.org plugins repo. It should show up in your WordPress admin shortly if you are using it and if not, then here is yet another reason to try the plugin out if random or unwanted images show up for your WordPress site when links are liked or shared on Facebook.

The new version is a complete rewrite and is really good at figuring out the context specific image to use for different types of pages. It also deals with situations where earlier version would run into compatibility issues with other plugins. And last but not least, this version is developer friendly in case you want to short-circuit the logic, you are able to do so now. All power to you.

Hit me up if you have any questions. And one real good of piece of advice that I can't mention too much is - Facebook maintains a cache of images selected for every URL (usually 24hours), so your new images won't show up right away, but eventually they will. Facebook has a really nice tool to debug your URLs outside of their cache to test the image being selected for display - https://developers.facebook.com/tools/debug

If you are looking for premium support - get in touch with me via my contact form.

Get WordPress images from a different site

Developers usually work on their local installs before pushing any changes to the live or production server and that's how a developer's workflow should be.

In order to setup a local or dev install on which a developer can work or test, they need to pull down the codebase and database dump to exactly mirror the site but they also need to download the media folder to make sure all images show up fine, which can have a bit of its own issues.

Codebase is usually under version control, so that's easy to pull and push changes. Database dump is a single file to download. But media folder can be very large sometimes and not possible to download every time you want to sync up with the files on live site. A super easy solution, that I use, is to setup a redirection rule in your local webserver to redirect all media requests to the live site and then you don't need to sync your media files at all.

Here is a single line, that can be added in your WordPress .htaccess file (if you are using apache, for nginx or any other webserver, idea stays the same, syntax will vary ofcourse):

RedirectMatch 302 ^/wp-content/uploads/(.*)$ http://mylivesite.com/wp-content/uploads/$1

Voila! Now you have all images showing up from live site directly 🙂

P.S. - This doesn't work if you are offline for obvious reasons.

Use WooCommerce product image as its category image

WooCommerce is capable of showing category as well as products on its shop page and this is configurable from settings available in admin side but I can totally imagine running into the situation that categories don't have their images uploaded and they will end up showing placeholder / default image. A quick solution would be to pull a product image from that category and use that image in place of thumbnail, highly dependent on what sort of products you are selling on your store, but in case you fit the bill, here's how to do so:

Install this as a plugin, you can download it. Activate the plugin and any product category will now pull image from a product under that category and show it. In case an image is uploaded for the product category or one already exists, that takes a higher priority and is used instead of trying to get one out of a product.

How to use WooCommerce email design in custom emails

Let's say you have already styled your WooCommerce email and want to use the same email design for a custom email, how will you go about that? Turns out its pretty easy. For the sake of simplicity , I am assuming you have the needed data in variables, change them accordingly as per your code.

For instance, right now, your email function looks something like this:

$email = 'ashfame@example.com';
$subject = 'Custom stuff email';
$email_content = ''; // whatever it is
wp_mail( $email, $subject, $email_content );
view raw before.php hosted with ❤ by GitHub

Now, do the following and it will pull the email design in use with WooCommerce emails even if you haven't styled it.

$email = 'ashfame@example.com';
$subject = 'Custom stuff email';
$email_heading = 'Custom Heading';
$email_content = ''; // whatever it is
do_action( 'woocommerce_email_header', $email_heading );
echo $email_content; // or simply have HTML markup outside PHP tags here
$email_content = ob_get_clean();
wp_mail( $email, $subject, $email_content );
view raw after.php hosted with ❤ by GitHub

The magic happens by calling in header and footer markup of WooCommerce emails along with the actual content, buffer the output it and pass that on to mail function.

SSH password less key authentication 101

Check whether you already have a key pair generated. Inside .ssh directory of your home, if you see files name id_rsa and id_rsa.pub then you can use them.

If you don't have them, generate a new one.

How to generate a SSH key pair?

ssh-keygen -t rsa

To be able to use password less authentication, you need to put the public key on server.

Do that either by adding the contents of public key file in ~/.ssh/authorized_keys on server or use ssh-copy-id user@serverhost which will do that for you.

Now just attempt to login by user@serverhost.com and you will be able to do so.

Its totally safe to use public key because without your private key that's no good to anyone.

How it works?

Server sends you a challenge string which you encrypt using your private key and send the encrypted challenge string back. Now only your public key can decrypt it to what it originally was, thus confirming its actually you and let you login. Simple enough.

Setting up your VPS

Its very easy to setup a VPS considering the tools now we have on our exposure. This post is more of a self note to myself, so pardon me for not explaining things.

To quickly setup latest NginX, MySQL, PHP (with APC and Suhosin) & exim, just use this script https://github.com/vladgh/VladGh.com-LEMP

These instructions will get things up and running a secure server.

Buy a VPS which will get you root access to your server.

Create a new user with sudo powers which will be actually used to do everything on a regular basis since using root is not recommended.

adduser ashfame
usermod -a -G sudo ashfame

Setup iptables (firewall)

From your new account, setup your key based login, disable root login & password login so that only key based logins are allowed.

sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
UsePAM no

Links which explain the above things in detail: