WordCamp Joburg 2017 Composer Workshop

Composer has been around for a little while now and it has made the lives of thousands of PHP developers around the world just a little better (OK, quite a lot better).

Using Composer in your theme and/or plugin will allow you to add a range of great features and libraries that are available to the general PHP community without having to worry about actually managing those libraries (Composer does that for you).

In this workshop, we will look at:

  • how Composer works from a very high level;
  • start a very simple plugin and including composer in it;
  • and use some of the really cool packages out there to make our plugin awesome.

You can find the repo for the workshop on GitHub: https://github.com/seagyn/wcjhb-composer-workshop

https://docs.google.com/presentation/d/1L2lx1AS4lHzwaV6X2McJ8P5rXSrIl9F9La0mPGw5xwQ/edit?usp=sharing

WordCamp Cape Town 2017 Composer Workshop

I had the privilege of doing a workshop at WordCamp Cape Town 2017 on Composer and WordPress. I covered how we can use Composer to manage WordPress projects and how we could create parity between the different environments we have (like development, staging and production).

Tools I used:

What I would have liked to have clarified before the workshop was that this was for entire project management and not managing a single plugins dependencies (something that I think I’m going to rather do at WordCamp Joburg 2017).

Here are my slides from the workshop, I hope they help and feel free to pop me questions you might have.

https://docs.google.com/presentation/d/1bRS-qfsWmUR0PGiYn4k1ev6l36N2GKmLL1IpV8MPuIw/edit?usp=sharing 

Setting the PHP version in command line on CPanel Servers

Over the last couple of days, I’ve been really struggling to try to get Composer to install a project on a CPanel server. As you know, Composer can also check environment constraints and for some reason  php -v would show PHP 7.1 but when running composer install or php composer install, it would say that I’m using PHP 5.6.

I tried using the full path to both PHP and Composer (to find that out, you can use which php and which composer) with no luck. After a bit of research, I finally found that EasyApache 4 (the system that manages Apache and PHP on CPanel servers) has the ability to pass an argument to the command allowing you to see the PHP version.

You can replace 56 with the specific version of PHP that you want like 70 for PHP 7.0.x or 71 for PHP 7.1.x. My new command looked like this:

It’s obviously important to run Composer with the version of PHP that your web server is running as it will install the dependencies with those constraints in mind.

Get Custom Post Type by Slug

I recently had a case where I needed to get the post object for a custom post type in WordPress – I had to do this by a slug that the user passed in. There is a function ( get_page_by_path) which I initially thought was to only find the post object for pages but it actually goes deeper.

The function takes 3 arguments:

  1. The path/slug that you’re looking for.
  2. How you want the post to be returned – basically as an array or object.
  3. The post type(s) you want to search through.

So to get the post object (let’s call my custom post type ‘book’) I can just do the following:

Now that I have the object I can reference it as I would any post object in WordPress:

For more information, you can visit the get_page_by_path function reference on WordPress.

WordCamp Joburg – Want to setup an online store?

Here are my slides from my workshop from WordCamp Joburg 2016. Most of the content was covered in the workshop (not on the slides) but the slides might give you a good idea of the flow.

The stuff you’d really care about is most likely where to get the software that we used. Here are the things we used in the workshop:

Remember, you don’t have to use these plugins but they’re a good store. You can head to the WooCommerce Extensions page for plugins that add functionality. You can also look on WooCommerce, Themeforest and even the WordPress Theme Directory for more themes.

Here’s a link to my slides. I’d love to get feedback from you about the workshop and anyway I could improve it 🙂