Block 1 is the second class in the WordPress plugin development series.

Click here to find the other blocks on the chain.

Materials

phpStorm – download here

Objectives

Setup and learn about phpStorm and git

Notes

Monday April 19th 2018

The first part of the class was making sure people had wrapped up Block 0 items — setting up their virtual machine. The combination of VVV, Vagrant, and VirtualBox. This is important to move forward with coding which will start with block 2 at our next class.

Host Updater Plugin

This is important. When Vagrant is being installed it will ask about installing the Host Updater plugin. If you did not install this and restart Vagrant you will find that you cannot surf to http://one.wordpress.test

If this happens go to the directory where you have vagrant installed and run this command as per the docs:

vagrant plugin install vagrant-hostsupdater

Finding Your Vagrant Folder

Search your computer for a file named Vagrantfile , first letter is capitalized.

This is most likely where you unzipped your VVV download and first ran the vagrant up command.

Get To Your Command Line As Administrator

On Windows this is important. MacOS not so much. When you find the working folder for Vagrant you will want to open a command prompt window with Administrator rights to perform your work.

This is especially useful during vagrant up because the hostsupdater plugin will need administrative access to write to the hosts file used to map one.wordpress.test to your local virtual machine.

The Hosts Update

Every time Vagrant boots with vagrant up it needs to map every domain name you are using on your development virtual machine to the Virtualbox.

On MacOS it writes to /etc/hosts — like any decent Linux distro.

If you want to save some boot time find that hosts file after the vagrant up command has completed and look for the .test entries.

They should. have the typical IP address and hostname followed by a comment referencing vagrant afterwards.

To make these entries permanent simply remove the comment portion after the hostname. This will prevent Vagrant from removing those temporary entries when it shuts down. On next boot it will see they are already in the hosts file and skip running the hostsupdater plugin to write new entries.

Install phpStorm

We went over the phpStorm installation and made sure everyone had a copy downloaded and installed.

This is far easier than the virtual machine setup.

For now you can get a free 30-day trial. We are still working on getting a license for our class attendees for a free 6-month trial to use during class.

We covered some of the features of phpStorm such:

  • PHP command autocomplete
  • WordPress internal functions autocomplete and code referencing
  • Autocomplete for well-documented classes and functions we build (custom code)
  • The MySQL database interface
  • git version control integration

Don’t worry if you missed this — we didn’t get deep into these. It was a cursory review to point out they are there. We didn’t delve deep into how it worked; we will do that at the appropriate time during future classes.

We will use object oriented coding

As we start to get into code we will start with using object oriented approaches from the beginning. If you learn OO coding you will know procedural coding.

Don’t worry it sounds like an advanced programmer thing. It is just as easy to learn as procedural coding — especially if you have not been trained previously in procedural code. Why all coding classes start with procedural code then throw a whole new layer on top is beyond me. Maybe to sell more classes?

Again, no need to worry about this if you missed it. We only touched on why we will be doing object oriented coding in WordPress — mostly to serve as a stand-in for namespaces and “sandboxing” our plugin code. It keeps us from stomping other peoples code and gives us another layer of protection from third party code.

A brief intro to VCS and git

We also talked about git and why we will use a version control system. Thankfully phpStorm has some great VCS tools built in.

Many classes skip this as you don’t need to worry too much about versioning software for personal/solo use. However, it is an invaluable tool even for solo work for recording an ongoing history that you can use to review your progress & notes along the way , pick up a project you’ve not worked on for months, or recover from a series of mistakes or bad decisions.

We didn’t get into specifics, only covered what version control is and what some of the benefits are.

We will be using phpStorm’s built-in VCS tools for git at first and will start to learn how tcreate our own repositories, clone repositories, and push commits in a future class.

For those that want to get ahead of the game and make sure their phpStorm git interface is working you can use the VCS git commands from the drop down menu and try to clone this repo:

https://gitlab.com/the-code-block/https://gitlab.com/the-code-block/wordpress-plugins-block-0.git-plugins-block-0

It will create a single markdown file when the repository is cloned to your laptop.

gitflow

As part of the git focus we will be using gitflow as our nomenclature standard. It is nothing more than an agreed-upon standard way to name our work flow elements when working with git.

Don’t worry about master, develop, feature, and release branches. Or what a branch is. We will get there when the time is right.

%d bloggers like this: