vi brace matching

For 40 years, brace matching in vi has been part of my workflow, and for the most part, it works great! One of the first things I look for in a new editor is this feature. But sometimes, it breaks down. Consider a PHP line like:

if (stripos($str, '{+') !== false) {

As soon as you do something like that, your brace matching in vim falls apart.

But there’s a fix! The incredible matchit mod for vim by Benji Fisher. Handles THOUSAND LINE if blocks (this is legacy code, my friends) like a knife through butter. Thank you Benji!

Update PHP – or be shamed!

Now that PHP 5.6 is no longer being actively supported, it’s time to move to PHP 7. And if you don’t, then WordPress will shame you by displaying a warning!

Fortunately, WordPress is very easy to update, and there’s really no reason not to be running PHP 7 if this is your main web application. Other applications are more work to upgrade. If you need to upgrade a Zen Cart, for example, please contact me and I’ll help. You can run Zen Cart 1.5.5 under PHP 7.1 with a small number of modifications for most carts.

Zen Cart – MailChimp Integration

My Zen Cart – MailChimp integrations have received the following updates:

  • Fixed bug in API integration:
    The original integration had error checking that was based on the 1.3 API, and lo longer work.  So while the success path logic was all correct, the error handling was wrong.
  • Added instructions for changing Zen Cart newsletter page:
    The original Zen Cart integration only handled signup on the account creation page. Now users may subscribe or unsubscribe on the newsletter page (which is linked to on the My Account page as /index.php?main_page=account_newsletters.
  • Removed double opt in:
    At the request of ecommerce companies, MailChimp has changed the default subscribe behavior so that double opt in is no longer required.  Users who prefer the prior behavior can still change it back by modifying the PHP API (includes/functions/extra_functions/mailchimp.php) to set status based on $options[‘status’] rather than just to subscribed.
  • Moved MailChimp error log to /logs folder:
    In the event of an error, the MailChimp.log file was being written to the /cache folder; it is now written to the /logs folder where it is more likely to be noticed (since most logfiles have been migrated there in Zen Cart 1.5+).

You can see the updates in my ZenCart MailChimp and ZenCart Newsletter Discount contributions, and  my MailChimp Integration for Zen Cart GitHub repository.

Including a file in a PHP class

I was trying to figure out how I could manage the premium logic for my freemium Better Together for OpenCart module.  You can’t just require a block of code in the middle of a PHP Class:

class SomeClass {  
  // NOT ALLOWED! 
  premium_file = "premium.php";
  if (file_exists($premium_file)) {
    require($premium_file);
  }

So I cooked up another method that I documented in this StackOverflow post about how to include code into a PHP class.