Categories
Tech

Tripped Up By Composer

I recently started another stint of learning. I will be starting some Gutenberg block development soon, so I wanted to research it and other things that can help on my journey. A little WP-CLI here, a little NPM there, you get the picture. Since composer has come up a couple times, I decided to take a deeper dive into it.

Revisiting Composer in Existing Project

I am working on a project that needed custom fields. Normally I would just create my own meta fields, but the requirements for this one are a bit complex. Advanced Custom Fields Pro would be an option, but the recurring cost of premium plugins isn’t ideal. Instead I decided to use Carbon Fields, a free open source alternative. It has a few installation options, one of which is as a stand-alone plugin using composer.

Failed Installation Attempt

When I tried it the composer option first time it failed, and threw a fatal error in WordPress. After a short while I gave up, and installed the pre-built plugin manually. I have had to update it manually too. Given my new experience with composer, I decided to give it another try. I did my best to follow the documentation on their website, and the installation failed again.

The documentation said to run composer require htmlburger/carbon-fields-plugin from the root of the WordPress install. When I did that, a Carbon Fields folder and various contents were placed in the plugins folder. I thought that was it, it should be built and working, but it wasn’t.

Where I Went Wrong

After comparing the pre-built plugin to the plugin that was created with the composer command, I found that it wasn’t fully built. I also noticed that it has a composer.json file of its own. I assumed that the dependencies in that file would be installed when running the install command at the WordPress root, but I was wrong. This is where the confusion lies. I needed to also run composer install or composer update from the plugin’s directory. This was not in the Carbon Fields documentation. I can’t really blame them, it isn’t their job to teach me how to use composer. Now that I realized that it is not poor documentation, nor a bug in the code, but rather a PEBKAC error, I carry on.

Scaling

Assuming I want to start using composer on more plugins and themes, I wanted to find a way to quickly update everything without navigating to each directory. The following script will run updates on all composer projects in the WordPress root, as well as the plugin and theme directories.

#!/bin/bash

composer update

for dir in {*,wp-content/plugins/*,wp-content/themes/*}
do
  if [ -d $dir ]
  then
    pushd $dir
      if [ -f composer.json ]
      then
        composer update
      fi
    popd
  fi
done

Name this file composer-update.sh and place it in the WordPress root. After that run it from the terminal bash ./composer-update.sh.

Conclusion

I thought that you should be able to update everything with one command. After finding out it doesn’t work that way, I found a way to make it work that way.

Categories
Tech Uncategorized

Power Query – An Amazing Tool Built Into Excel

I recently started learning about Tableau, a business intelligence (BI) tool that helps you visualize data. I won’t get too deep into that, but it is relevant to how I stumbled upon Power Query, and may help me convey what it does. If you spend time adjusting spreadsheets, you need to learn Power Query. It will give you some of that time back.

Back to Tableau for a bit

So, as I mentioned Tableau helps you visualize data. The visualizations can be graphs, charts, maps, and more. The data can come from one or more of many different kinds of sources (spreadsheet, database, API, and more). When you combine multiple data sources, you have to use a tool called Tableau Prep. So for example, let’s say you have a three lists of names for an event. One for invitations (people who where explicitly invited to the event), one for registration (who registered, and when), and attendees (people that actually showed up to the event). Now let’s say you want to find out what people from the invitation list actually attended, and you want to see when they registered too. Tableau Prep can help you do that with ease. It is a pretty awesome tool too, but did I mention that Tableau is expensive? At this time, it is about $70/mo for each user.

Enter Power BI and Power Query

Since I wanted to use a tool like Tableau, but Tableau is prohibitively expensive, I looked at Microsoft’s Power BI. First to compare prices, and second to see if they have a neat tool like Tableau Prep. The price is laughably lower, like $10/mo if it isn’t already included in your Office suite, and yes it has a tool that you can use like Tableau Prep. That tool is Power Query, and not only is it included in Power BI, but it is included for free in Excel. I haven’t even gotten to Power BI yet because I’ve been enamored with Power Query.

Use Case #1 – Simple

You have a spreadsheet with a table of contacts. You want to sort by last name, but can’t, because each record is storing the full name. With a couple of clicks in Power Query, you can separate it out into first and last name so you can sort by last name.

Use Case #2 – From File

You have a sales department with a number of sales people that collect contact info for customers. At the end of each year, you want to send out holiday cards to those customers. You can have each sales person export the contacts from Outlook to CSV file, and put them into a single folder. Then you can use Power Query to merge all the files in that folder, and remove duplicates.

** Check back here in the future. I plan to implement this one, as I know someone that wants something similar.

Use Case #3 – From API

You have a website and a YouTube channel. You want to import the title, description, link, and publish date for each YouTube video into your website. You can connect to the YouTube API from Power Query to get all the info you need from each video, and format it so it can be imported into your site.

What Next?

Assuming I have talked you into giving Power Query a closer look, where should you start?

I am a fan of LinkedIn Learning, and it is how I learned. You can find the links to the courses below. The First one is only about 25 minutes, so it isn’t a big commitment. The second one is more in-depth.

https://www.linkedin.com/learning/excel-power-query-for-beginners/

https://www.linkedin.com/learning/excel-power-query-get-transform-2/

Categories
Random Tech

First Post… hi

Welcome to my new blog!

My first exposure to WordPress was in 2013 when my PHP 2 group at WCTC created a WordPress site for Pink Banana Theater in Milwaukee. I hadn’t touched it much until I started working for UWSA earlier this year. I now spend a lot of time maintaining the backend code for a heavily customized WordPress site, but still to this day, I haven’t spent much time at all on the front end. I feel like I’m missing something because of it.

How can I make my users’ experience more efficient and more enjoyable if I have no idea what they do, or how they do it?

For that reason, I created this blog. My plan is to start posting here more, and directly to social media sites less (we’ll see how it actually plays out). With the use of a plugin that I wouldn’t have found otherwise, I can update my social media sites from my blog [The Plugin]. I hope that I continue to find problems and annoyances that will help me find new tools to use and/or new ideas to explore.

I don’t have a direction other than trying to inspire my own self development. Please provide feedback, suggestions, or topic recommendations as you see fit.

Thanks for reading!

Jeff