Fantastic hooks and where to use them.

This post is an introduction to the useDispatch and useSelect hooks in the wp.data api found in the WordPress Gutenberg plugin. Note: the hooks will be available with the next release of the @wordpress/data package (which will happen after Gutenberg 5.9 is released)

So you’ve had a chance to finally figure out the wp.data api. You’ve written a few components using withSelect or withDispatch. You think you’ve got a handle on some of the finer points of higher order components in Gutenberg (and realize that’s essentially what withSelect or withDispatch are!). But now you start seeing things like useDispatch or useSelect pop up in use. What the heck are these? Where did they come from? Is everything you learned useless?

To answer the last question and appease your worries. No. Everything you’ve learned in using withSelect and withDispatch is still awesome. You can keep using them and your Gutenberg blocks and apps will still keep on rocking.

Read more “Fantastic hooks and where to use them.”

Testing Javascript for your Gutenberg Integrated Plugin

(Edit October 10, 2018) Note: This article is now out of date but is kept published for reference purposes. Nearly everything in Gutenberg is published as a package so for the purpose of testing you can include those packages as a devDependency in your package.json file and jest will know to reference those in tests. 

As a part of my work with Event Espresso I’ve been assisting them with moving over to a more modern Javascript build system.  This has been prompted by the upcoming new editor for WordPress codenamed Gutenberg.  I’m not going to spend a whole lot of time talking about Gutenberg since there’s already a ton of information on the internet.  What I want to do in this post is outline a way for plugin developers to test their custom components/blocks built for Gutenberg using the Jest framework.

Writing javascript tests using Jest is pretty straightforward and this isn’t a how-to-post since there’s a lot of that already available (including this readme the Gutenberg team prepared).  Instead I thought it’d be useful to write how I solved a problem with a particular set of tests I was trying to write for some code I had written (especially since I couldn’t find anything useful on the internet myself to help with it).

Read more “Testing Javascript for your Gutenberg Integrated Plugin”

Something every Language/Library debate needs to keep in mind….

There’s some discussion happening right now in the WordPress world about what javascript framework to add to WP core.  These kind of debates happen frequently in the programming world (Google “PHP sucks” for some great examples).  In the course of these types of discussions, support is usually brought up for one point of view or another by pointing to what others have written about it on the internet.  Certainly it is reasonable to glean from what has been written,  but I think it’s also important to recognize there is a silent majority of programmers out there that we’ll never get input from as demonstrated by this simple diagram I did up (horrendous but communicates the point I want to make):

peoplewhoprogrampeoplewhowrite

The intersection of people who write (and you might add write well to that) and those who program (and you might add those who program well to that) is a small portion of the entire picture.  Sure, we don’t discard what is written about, but let’s not give it undue weight either.  Ultimately, there is a silent majority of people building solutions who really don’t care about these discussions or flame wars because they are using what gets the job done.

At the end of the day, use what gets the job done.  Learn it well.  Learn it deeply.  If you’re one of the few who also has the gift/time to write, write about it!

On Vision

This is a post that has been percolating as a draft post for nearly two or three months now.  But as a theme, its something I’ve wrestled with far longer.  Those who know me well, know that at my core, I’m kind of a systems and strategy kind of guy. What makes gets my ticker picking up its pace,  is when I get to work with a big picture idea and help generate/coach the strategies and systems to see that that big picture come alive and grow.  And so, that’s why this post reflects something that strums the passion bone in my body.

I want to spend a little bit of time articulating some things I’ve come to believe about a word that gets used a lot,  but is rarely understood fully.   This post is sparked in part because I think there’s a lot of misunderstanding about what vision is, and what it is not.  Part of that is because its so elusive, and part of it is because it frequently rides the buzzword wave.  So here’s what I think about vision:

Read more “On Vision”

Using circleci.com for automated WordPress plugin testing.

A few months ago, one of the teams I work with went on the hunt for a good continuous integration service for running tests on the code we write.  We jumped on the unit test bandwagon at the beginning of the year and wanted to really amp up the quality of our product by having tests run on every commit.  I was tasked with this job (and anyone who knows me knows I LOVE playing with new things, so it was a task I was looking forward to doing)

Most WordPress users are familiar with travis-ci.org and the internets were full of instructions for getting things plugged in and up with travis.  Unfortunately, our project is inside a private github repo so we couldn’t use the free travis plan to run our tests on and the premium plan was a bit to pricey for our first attempt at this.  So after searching around, I stumbled on circle.  From all appearances, circle looked like it would work very similarly to travis and bonus points were that their plans are much cheaper – so great for getting started with.

Read more “Using circleci.com for automated WordPress plugin testing.”

If I was in charge of a telecommunications company…

Yes, this is one of those “If I was in charge, I’d do this…” posts.  Don’t we all have opinions on how companies should be run?  Just had these thoughts today so decided to write them down.  Canada is known as one of the worst places for mobile phone plans (from a consumer perspective), largely because of the lack of competition.  If by some freak cosmological accident I ended up in charge of a telecommunications company, here’s some things I’d do:

I’m not going to talk about pricing or packages or anything like that, because at the end of the day what matters most for company longevity is customer loyalty and word of mouth marketing (even more so in today’s hyper social world).  The only reasons why I think the existing companies are doing so well in Canada now are because of their entrenched position with infrastructure, and the lack of choice for consumers.  With that said,

1. I’d ensure that our company has some sort of automated process that scans existing customers accounts (ooo privacy, but bear with me) and if there are any current company promotions that are better plans (either in terms of the same as what they have but cheaper, or more features than what they have for same price) than what the customer currently has we automatically switch them to the cheaper plan and notify them.

2. The plans would be simplified (which would need to happen for number 1 to work effectively).

3. Company wide policy that if a customer calls and complains about something not working, and they have ANY difficulty getting the level of service they asked for, we immediately grant them at least a free month’s service.

4. For customers who have been with the company for over three years.  We surprise a certain number of them randomly once a year with free phones and/or upgraded plans for their current phones.

That’s just four things.  Not a lot, and I fully realize there’s a lot more involved with running a company, but four things that I think would help towards gaining long term customers and viral word of mouth marketing.

What would you add?

FireHost and WordPress Multi-site… how well do they play together?

Recently, one of my clients purchased a server with FireHost.com.  We’d been on the search for a new web host for some time now to serve as the infrastructure supporting upcoming web applications we have in the works.  We needed a company who is well recommended, and will help us scale and scale quickly.

You pay a more for a host like this  but it’s part of the investment costs you need to make if you want to be positioned well for solid growth as a business.

Anyways, the purpose of this post is NOT to discredit or gripe about yet another hosting company that fails to live up to expectations. We actually really like the setup we have at FireHost. Although getting things setup were a bit of a pain – their support has been very prompt and generally okay.  No, this post is more of a fyi for folks who are in a similar situation as us.  I couldn’t find any information on this subject on the nets so thought I’d post my own findings.

One of the major components of some projects we are working on this year involves the use of WordPress multisite.  It will provide the backbone of what we are building and is crucial that we have a server environment that supports this.  FireHost does except for one niggling problem.  They have a super awesome “Web Application Protection” firewall that works really well, too well, and prevents normal usage of WordPress multisite.

At issue is that any subsites created on WordPress multisite will fully function as long as those subsites don’t post any images or certain html in their posts.  Cause if they do,  BAM, the firewall sees that as a xss attack and shuts her down.

That’s no good is it?  No.  But wait, FireHost has the solution.  All you have to do, is whenever this happens you just send them the path for the sites that the firewall does its thing on and they’ll add an exception.  Greeatt!  Except that we’re planning on using WordPress multisite to well actually make it easy for people to signup and get started on a new site right away (you know kind of like how people expect things to work? right?).  So yeah, major pain to have to send a block of paths every time the firewall acts up.

I’m not going to tell you the solution we worked out but let’s just say not ideal.

Silly?  Yeah.  I get it. But obviously someone at FireHost needs to do some thinking about how this firewall is setup and put something in place to allow for easier management of WordPress multisite while keeping the firewall working on things that it should work on, or at least be clear about the side affect of the WAP for those using WP multisite, would have saved a lot of back and forth with tech staff.  At the very least, create some sort of API or secure service for automating the firewall exceptions in cases like this where sites are being created dynamically via an application like WordPress multisite.

Anyways, again we do like what we have so far with FireHost except for this firewall experience, but I just wanted to post this up in case anyone else is thinking of using multi-site with FireHost and wondering why its not working as expected.

(I also have another reason for posting…secretly hoping some server guru out there will be able to explain how I’m either an idiot for expecting the firewall to be set up so multi-site works, or how FireHost can do things so multisite will work fine).

Update: December 2014

Just posting an update for anyone who visits this post via search engines (there are a few of you its seems.  Besides the fact that Firehost did contact us within the 30 day window that was put forward by their CEO/founder in the comments to this post, we never did get on any “beta” program.  The solution they are proposing for clients needing their own managed WAF is a $1500+/mo cost solution, which is not startup friendly.  They did offer to help get us up on ModSecurity as an alternative to their WAF solution but in the end my client and I just decided to fire Firehost (yeah pun intended) as our hosting provider and we joined the cool cats over at Digital Ocean.  We figured if we’re going to be doing most of the server setup/managing ourselves then no sense in paying a “managed” hosting provider to do it for us.  We’ve been on Digital Ocean for about 5 months now and absolutely LOVE it.

WP 3.7 drops with an interesting surprise…

I thought I was following the development of WordPress 3.7 fairly closely but something totally missed my notice and only caught my attention when a plugin I develop stopped working with the latest version of WordPress.

The culprit?

do_action( 'save_post', $post_ID, $post, $update );

Notice anything different?  The difference is that this hook used to only have 2 parameters, “$post_ID”, and “$post” but NOW it has a third one, “$update”.  It’s actually a nice addition as it makes it super easy to determine whether the post is being updated or not.  However, due to the way I hooked into this action (with a function that had extra parameters on it), Organize Series broke.  Easy enough fix, but quirky enough that I thought it deserved a post as I haven’t seen anybody mention this little addition!

 

Get wp-cli running with MAMP

I got really intrigued with the wp-cli tool for command line WordPress (seriously awesome, check it out)… however I haven’t switched my osx machine to use the built in php and mysql so I kept getting this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Easy fix:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

And BOOM! I’ve got wp-cli working now.