Lance Cleveland

Getting Foundation, Sass, and phpStorm To Play Together

In an effort to improve the overall user experience in Store Locator Plus, my business locator plugin for WordPress, I have been playing with pre-defined interface frameworks.   I’ve been working with Vue recently and like their pre-defined templates.  However, the MySLP version of Store Locator Plus has been built using Foundation and React.    I decided it would be a good idea to stay with Foundation to help style my interfaces in the WordPress SLP product.

I already have phpStorm setup for my WordPress development and use Sass to compile my own CSS libraries.   I wanted to add Foundation to the mix, but it turned out to take longer than I anticipated.  With any luck my cheat-sheet here may save you some time.
Read More

Using Custom Vagrant Sites For WordPress Development

As with many things in life, I recently learned that I’ve been doing things the hard way when it comes to WordPress development and Vagrant.

I got on the Varying-Vagrant-Vagrants bandwagon years ago.   It made it easy to write my Store Locator Plus code and test it on several different WordPress installations.    Along the way I learned how to provision my test boxes and share code between them.   When VVV 2 came out earlier this year I decided to upgrade.  It did make things easy, but in the early days of limited documentation I followed a few sparse examples and “figure out my own way”.   Of course that turned out to be the hard way of doing things.    I’m going to share with you the shortcuts I learned today to hopefully save you some time.

Read More

What To Consider When Buying MacBook Pro Retina Power Adapters

The new MacBook Pro Retina is now shipping with the soon-to-be ubiquitous USB Type-C ports.   There are 4 of them on my new 15″ MacBook Pro.    The cool thing about these new ports is they are bi-directional and symmetrical. That means the cable is identical on both ends and there is no upside-down.   That is a HUGE step up from all previous iterations of cables and connectors.

In addition the new USB Type-C cables and ports can support video, audio, data, and power.   That means the ports can be used to connect headphones, monitors, and power to your devices.   For smaller devices like phones that means one port can be used to power your device while at home and the same port is your headphone jack when out roaming around the city.

However there are some key things to be aware of especially when you are talking about the USB Type-C ports and charging devices, especially when looking for a new MacBook power adapter.   As many people are learning, not all charging devices and cables are created equal.   As happens with any new tech peripheral, China has rushed into the USB Type-C market with dozens of low-quality accessories that are not up to the job.   Best case, your device doesn’t charge.  Worst case, your device is fried and you start a fire.
Read More

MacBook Pro System Freezes

Despite having spilled a half-quart of apple juice straight into the innards of my Mid 2014 MacBook Pro Retina, the uptime has been astounding. The only notable time that the system has been offline was during a keyboard replacement just over a year ago. Turns out apple juice, no matter how well you think you’ve cleaned it out of the guts of the MacBook, tends to stick around. Literally. A little less than a year after the mishap one of the keys was stuck as always being pressed. Turns out that makes it hard to boot the system. $1200 (yikes! MacBook repairs from an Apple Authorized Repair Center are costly!) and a few days later and evertyhing was back to new.

Until this week. 14 months later my MacBook Pro system freezes with almost no warning. Last week it was getting sluggish after some software updates and I assumed that was it. This week it would stop responding to keyboard input, then a few moments later the trackpad would stop responding. Evenutally the “Spinning Beachball” or “Spinning Pizza Of Death” (SPOD) comes up and I can no longer close apps or get to the Apple system menu to do a clean restart. My only option was to hold down the power button and do a hard restart. That is not good for the system or my productivity.

The problem has quickly gotten worse. I’ve been learning a few things along the way while I struggle through the problem and try to find a solution that costs less than a new MacBook Pro. My “crib notes” are here for both my future self and to possibly help anyone that stumbles across this article.
Read More

WordPress Hooks and Filters Order Of Precedence

When building plugins and themes I often need to reference the WordPress order of precedence of hooks.   This helps ensure various components are loaded only when needed and at the right time.   The base list I reference is the old Codex Plugin API/Action Reference page.   Its sister resource, the Codex Plugin API/Filter Reference is also useful.

The only problem I have with those resources is when I need to determine what will fire on the front-end, backend (admin only) , AJAX, and Cron.    This is my cheat sheet to help sort out the first two (front-end v. admin processing).

WordPress Action Hooks

Stage 1 : Loading

Front EndAdmin Pages
widgets_init *widgets_init *
wp_default_scripts wp_default_scripts
wp_default_styles wp_default_styles
admin_bar_init admin_bar_init
add_admin_bar_menus add_admin_bar_menus
wp_loaded wp_loaded


widgets_init is fired by hooking the init action.  It fires at priority 1.

Stage 2 : Processing

After wp_loaded is called, this is where the front end and admin processes diverge.

Front EndAdmin Pages
parse_request auth_redirect
send_headers _admin_menu
parse_query  admin_menu
pre_get_posts  admin_init
posts_selection current_screen
wp  wp
wp_enqueue_scripts admin_enqueue_scripts
wp_print_scripts  wp_print_scripts
get_search_form admin_notices
loop_start restrict_manage_posts
the_post the_post
get_template_part_content  pre_user_query
get_footer   in_admin_footer
wp_footer  admin_footer
admin_bar_menu  admin_bar_menu
wp_before_admin_bar_render wp_before_admin_bar_render
wp_after_admin_bar_render wp_after_admin_bar_render
shutdown shutdown


Starting Up A Plugin

I use PHP autoloading to eliminate require and include statements throughout the code.   It requires a consistent directory structure and file naming convention.  If you follow PHP best practices this should not be an issue.  I also recommend naming your PHP files after the class they contain and keeping every class in its own file.

Here is an example from my latest side project that sets up the autoloader and loads up the bulk of the plugin code when the WordPress plugins_loaded hook is fired.   It also exits the plugin early if a WordPress heartbeat comes in since this plugin, like 99% of those out there, has no need to listen to the heartbeat and load up all the overhead.


Loading Code As Needed

Rather than load up a pile of code into memory when a plugin loads, I prefer to break down my code into classes that are only loaded as needed.   No need to load up all that admin settings page overhead if we are only rendering a shortcode for a user on the front-end.

I use plugins_loaded to fire up my main plugin class and let the construction of that class manage the logic of when to load up the other modules.


Front End Only Processing

The main plugin loads a class that runs several methods during construction, adding hooks to admin_menu to load up the admin class when on the back end, testing for Cron or AJAX calls, and checking is_admin() and loaded the front end if NOT running an admin page.

Admin Only Processing

The admin_menu Hook

I often use the admin_menu hook to load up classes that are only needed on admin pages.   My typical structure is to have a controlling MyClass_Admin object which loads via admin_menu and within that add intelligence to the loading by relegating any code that does not have to run during the admin_menu hook into further subclasses such as MyClass_Admin_Init which is loaded up via a method attached to the ‘admin_init’ hook.

I use this method if I do not need to load up features earlier in the call stack (Stage 1 Loading) such as tweaking the admin_bar.


The is_admin() Test

This built-in WordPress function can also be used to check if admin pages are being loaded.   I tend to leave this as a sanity check to ensure we are on an admin page within my objects.  This avoids the overhead of calling and is_admin() test on every single page load, though I’ve not yet tested if this is more or less efficient than tying into the admin_menu hook.

I use this method if I need things to happen earlier in the call stack than admin_menu allows such as modifying the admin menu bar.

AJAX Only Processing

I often load this when the main plugin is loaded, which gets invoked via the plugins_loaded hook.    I typically use a method in the class that is loaded to manage the plugin that does a simple AJAX test:

Cron Only Processing

Similar to AJAX, Cron can fire at any time.  It too is managed via plugins_loaded with the main plugin class and has a check for DOING_CRON:



%d bloggers like this: