SiteGround Is Fucking Awesome

Here’s my first affiliate linking post thingy ever.  I want you to sign up for hosting with SiteGround and I want you to do it through my link so I get some referral money: https://www.siteground.com/index.htm?afcode=29a69d074161ca9f9de2a9796e5229a8

Now, let me tell you why I love these guys.

SSL Through Let’s Encryptlets-encrypt-siteground-one-click

I found out while poking around in my admin that I can install a FREE Let’s Encrypt SSL certificate with a click of a button.  Go to cPanel, scroll down to the Security section and hit the Let’s Encrypt icon.  Fuck yea.

WordPress Friendly

SiteGround is setup to work great with WordPress.  It has easy installs and is configured perfectly with all correct file permissions and so on.  I had five sites on my own linode.com server slice and they were constantly getting hacked.  I moved them over even with some shitty hacked up themes & plugins on a couple of them.  Haven’t been hacked a single time.

Support

I had one issue with support that wasn’t very pleasant.  But when I replied with my frustration it was escalated to a higher support person and handled immediately and gracefully.

Easy Upgrades

I have five accounts with SiteGround for various clients and myself.  My primary job’s website had a huge surge in traffic.  Expanding memory temporarily was an easy click, done.

Beyond all these perks, the sites are fast and always up.  I’ve had 0 down time.  I can’t say enough about finally finding a host I’m going to stick with for everything.

BUY SITEGROUND HOSTING THROUGH MY AFFILIATE LINK 🙂

WooCommerce Bulk Past Due Invoice Reminders

Once WooCommerce sends an invoice there’s no real way to send out mass invoice reminders unless you do them one at a time.  I needed something better than that.

Woo Deposits & Follow Up Emails

My company needed a way to have people pay for our more expensive products over four months.  I saw Woo Deposits had a payment plan capability so we bought it, installed it and I setup the plans.   I screwed up though.

It’s not clear unless you carefully read through the whole plugin description/FAQ that it invoices for each payment and does not do recurring charges.  I should have noticed this and made sure but I didn’t.

Well, we realized a couple months after turning on and we had around 50 unpaid invoices.  I installed Follow Up Emails and sadly it doesn’t have a way to invoice pending payments.

Some Code To Send Reminders

So here’s a function  you can run to resend the invoice to anyone who is pending payment.  I have the timestamp set to send 7 days after missed payment.

You won’t want to run this all the time so maybe set to a cron job every 7 days or so.

https://gist.github.com/ChrisFlannagan/ac250f86f2625bfc40d6a95d791fd56d

Add Two Color Linear Gradient Backgrounds To View Elements In NativeScript

Since the css linear-gradient isn’t part of NativeScript core yet I went looking for the ability to do this online.  I found a git conversation over at https://github.com/NativeScript/NativeScript/issues/539 that discussed and shared some code.

The code doesn’t work on iOS as expected.  There were some typos in the code that need to be adjusted and wrong variables.  I’ve made those adjustments and you can copy below a functioning version.

I added it to a .js file in my /app directory called grad-bg.js.  Simply load this .js file into your page’s javascript code with:

var gradients = require("~/grad-bg.js");

Import the function via the require method.  Then in your page loaded function call the function on your view.  Make sure to set the view’s id in your xml file and use that id here as the second parameter:

https://gist.github.com/ChrisFlannagan/9fc4b8e2ef871208abcb7f15018cd6ec

Here’s the full javascript function for linearGradient

https://gist.github.com/ChrisFlannagan/5dd5ca61ac01b15cf60b87dda20beaba

Repo: https://github.com/ChrisFlannagan/nativescript-gradient-background

The WP Crowd: Build Data Driven IOS & Android Apps With WordPress REST API & NativeScript – Part 1

I’ve started a new series over at The WP Crowd about putting WordPress & NativeScript to work together building REST API data driven apps.

Build Data Driven iOS & Android Apps With WordPress REST API & NativeScript – Part 1

Creating Custom Permalink Rewrite For Plugin Function Output to Content

I had a very short window to get this functioning today.  I haven’t toyed with WordPress rewrites API in some time so I had to dive right in and try to figure this out.

The Problem

I needed /plugin-content/ to rewrite to a blank page I could place a form on.  I needed this to be done without having to create a page in the WordPress admin first.  There are ways to create this page automagically when you first activate the plugin. I wanted it to not be tied to a post/page in the database but to simply work.  First I needed to build out a rewrite.  Let’s do this all in the primary plugin class for now.  Let’s imagine our class is called MyPlugin.

Building the Rewrite

First we need to add an action to init, I do this in __construct()

public function __construct() {
   add_action( 'init', array( $this, 'your_website_rewrite' ) );
   add_action( 'template_redirect', array( $this, 'make_your_website_form' ) );
}

You can see that I also hook into ‘template_redirect’ which we will address momentarily.  Here is the your_website_rewrite function:

public function your_website_rewrite() {
   add_rewrite_rule( '^your-website$', 'index.php?your-website=display-form', 'top' );
   add_rewrite_tag('%your-website%', '([^&]+)');

   if ( get_option( 'websites-cpt-flush-rewrites' ) ) {
      flush_rewrite_rules();
      delete_option( 'websites-cpt-flush-rewrites' );
   }
}

The first line creates our write which is ‘your-website’ so when we visit mysite.com/your-website the rewrite will be called.  The second parameter sends us to the site’s homepage index.php and tacks on a query string.  We need to let WordPress know to expect this query variable ‘your-website’ so we use the add_rewrite_tag function.

The way I handle flush_rewrite_rules is inside the activation of the plugin.  I set an option to true that means the rewrites do need to be flushed.  You don’t want to flush these every time the plugin is called as it can be very heavy processing.  So we only do it once after setting the rewrite rules.  They must be flushed this one time though or it won’t work.

Displaying Your Content

I originally set this up to display the content via a shortcode.  This was not the requirement though but since I had the shortcode setup and working I just used it here to display the form I needed.  That said, you can echo whatever you want in this place.  Here’s a quick look at what happens next.  We hook into the ‘template_redirect’ action with our function make_your_website_form():

public function make_your_website_form( $template ) {
   if ( get_query_var( 'your-website' ) == 'display-form' ) {
      get_header();
      echo do_shortcode(  '[WSCPT]' );
      get_footer();
      exit();
   } else {
      return $template;
   }
}

This checks the query string to see if your-website is set.  If our rewrite worked correctly then it should be there when visiting site.com/your-website.

Now inside that check we call get_header() followed by whatever we want to display then wrap it up with get_footer.  It’s important to put the exit(); here though as that is what stops all other content from being loaded.