06

jQuery & the WordPress Rest API – 1st Image as Background

Ordinarily it’s pretty easy to get the featured image from the WordPress API. You just have to remember to add the _embed element like so https://bionicteaching.com/wp-json/wp/v2/posts?_embed But maybe there’s some reason you don’t want to set the featured image but want to get the first image from the body of the post. This chunk of so very uncool jQuery gets the JSON data and finds the first img src URL in the post body. I’ve gone over the basic pieces previously so here’s the portion that differs. It’s just regex searching for anything with the img src pattern and spitting back out the URL. See the Pen antonio – jquery demo by Tom (@twwoodward) on CodePen.

06

Weather API + Google Sheets

I have many little robot scripts busy saving data to Google Sheets. Here’s one I made based on a little comment from one of my kid’s teachers. It goes to a very kind URL that returns the data structure at the bottom of the page. http://api.wunderground.com/api/YOUR_API_KEY/conditions/q/VA/Richmond.json It’s a pretty nice starter script for anyone wanting to play with an API and Google Scripts. The full Google Script is below and I’ve tried to comment it up pretty thoroughly. I’ll also break it down below for those of you who want to play at home. Get the Data The first variable ‘url’ is the API endpoint we’re getting the data from. Where it says YOUR_API_KEY, you should put your API Key. I recall early on trying to do this stuff I’d get confused when people did different things to indicate that an API Key should go somewhere. People would put it in quotes or surrounded by asterisk or something else. I’d end up confused about what should go there because I had no baseline to judge this against. It’s fairly obvious now but I haven’t forgotten that feeling of basic confusion. Sometimes it helps to be very basic. Google has a nice UrlFetchApp class that you use in Google Script instead of fetch like you’d use in vanilla javascript land. Since […]

04

Weekly Web Harvest for 2018-02-25

Mitigation of Shock: 6 Steps (with Pictures) The project transports you into a London flat, thirty five years in the future. A future where extreme weather has caused global supply chains to falter. Everyday items are often either out of stock or have become expensive luxuries. In response, living space has been increasingly given over to experimental forms of domestic agriculture. Food computers have been improvised from the detritus of a technological utopia that never quite arrived. apache/incubator-superset: Apache Superset (incubating) is a modern, enterprise-ready business intelligence web application h/t Downes Plotting the Course Through Charted Waters Heat maps, stacked area plots, mosaic plots, choropleths – oh my! There are so many different ways to visually convey relationships and patterns in data! In this workshop on data visualization literacy, you’ll learn to recognize many popular types of charts and how to glean insights from them. The Appendix contains some examples of data visualization as visual essays and it also includes links to resources for learning how to create your own.

01

Google Form to Google Sheets to Vue Website

When @cogdog & @twoodwar Were Building Websites From Google Spreadsheets Years Ago https://t.co/Im7oCecvpg — Keegan?Long-Wheeler (@KeeganSLW) February 28, 2018 This post from Keegan kicked of this demo.1 The goal is to create a pretty flexible template for using Google Forms to Google Sheets to simple website. I opted to do this one in Vue but may get around to doing it in plain JS or jquery if time allows. The first thing you need to do is make the form and put in some entries. You’ll be happier if your form prompts aren’t super long. Make them readable just keep them concise.2 Once you’ve made a few entries so you have some data to work with, publish your spreadsheet as HTML. File>Publish to the Web. Click OK and what not. Don’t bother going to that link as Google has made that a fake promise. You just need the ID of the document in your current view. It’ll be something painful like 12WsyLvtfIPJkCXgEXsRkrI6dS0_K6brJikZqzkQa8TU and is visible in the URL after the /d/ but before the /edit. You can see the spreadsheet here. It doesn’t really matter but !full transparency! With that ID in hand, you want to go to a URL like so. You could manipulate the number in the URL to hit different pages in the spreadsheet. https://spreadsheets.google.com/feeds/list/12WsyLvtfIPJkCXgEXsRkrI6dS0_K6brJikZqzkQa8TU/1/public/values?alt=json You should […]

26

Add Custom Field to WordPress API & Filter

I found myself in a strange situation where I needed to know if a page had a child. Natively the WP API lets you know if a page has a parent but not the reverse. First I had to write a function that writes some data to a custom field if a page has a child. Then I started writing this post and realized I needed to do the reverse and now I’ve written a function that writes data to a parent when the child is created. Now that I had the data being written to the custom field, I needed to make that data visible in the WP REST API. Luckily, Jeff put up a snippet for that not too long ago. Now I also wanted to be able to return data based on the contents of the has_children field. This filter1 does that. Now a URL like the one below will give me pages with children but without parents. /wp-json/wp/v2/pages?_embed&per_page=30&has_children=1&parent=0 This will help me make a fairly large menu structure more manageable and I figured having something like this all in one place might help someone else. 1 I usually call things ‘chunks’ of code but I’m trying to improve my vocab.

26

Unhide Custom Fields Screen Options When Using Advanced Custom Fields

If you use Advanced Custom Fields you may not realize it removes the ‘Custom Fields’ option from your Screen Options view and hides them entirely in the space they normally occupy below your posts/pages. That’s nice occasionally and a pain other times. Today it was a pain. I figured this out one time before but it took me a while to re-find it at this github page so I’m leaving it here in case I forget again.

25

Weekly Web Harvest for 2018-02-18

apache/incubator-superset: Apache Superset (incubating) is a modern, enterprise-ready business intelligence web application h/t Downes Plotting the Course Through Charted Waters Heat maps, stacked area plots, mosaic plots, choropleths – oh my! There are so many different ways to visually convey relationships and patterns in data! In this workshop on data visualization literacy, you’ll learn to recognize many popular types of charts and how to glean insights from them. The Appendix contains some examples of data visualization as visual essays and it also includes links to resources for learning how to create your own. About Frankenbook Frankenbook is a collective reading and collaborative annotation experience of the original 1818 text of Frankenstein; or, The Modern Prometheus, by Mary Wollstonecraft Shelley. The project launched in January 2018, as part of Arizona State University’s celebration of the novel’s 200th anniversary. Even two centuries later, Shelley’s modern myth continues to shape the way people imagine science, technology, and their moral consequences. Frankenbook gives readers the opportunity to trace the scientific, technological, political, and ethical dimensions of the novel, and to learn more about its historical context and enduring legacy. Do It Yourself – Futility Closet Society of Mutual Autopsy (Société d’autopsie mutuelle), founded in 1876 “for the purpose of furnishing to the investigations of medicists brains superior to those of the common people.”

A portrait of David that I took on a VCU shuttle bus.

Photography – #163

I ended up talking to David on the bus from the Medical Campus to Monroe Park. We started off talking a bit about cameras. From there I found out David has six children. Four of those children are adopted. He believes strongly in trying to do good in the world and this is part of that effort. David’s a very devout Christian and referenced God repeatedly in our conversation. He did it in a way that seemed very natural. We talked a bit about how much children learn from their parents and their actions even when that isn’t the intent. David talked about how he teaches a course and on radiology transportation (his current occupation). He talks about starting the class focusing on making good choices and how, with that foundation, everything else can be learned in time. David’s brother died about a year ago in a car accident and was an organ donor. He was there when the hospital called his father to confirm the organ donation. His father couldn’t answer the question and gave the phone to David who agreed that all the organs should be donated except the eyes. “Because the eyes are the windows to the soul.” All in all, a pretty intense and wide-ranging conversation for a short bus ride.

Screenshot indicating this user has several hundred sites associated with their account.

So Many Sites – Cleaning Up Users

There are lots of ways users can end up associated with many sites in a WordPress multisite install. That’s no big deal if it’s only five or ten but sometimes it’s way more. It’s not just messy, it actually degrades performance when you’re logged in because the admin menu bar loads all those sites. This can really become a drag as you pass a hundred or so sites. Previously, I’ve just given up on the user and made a new one. I’ve also gone through https://theSite.us/wp-admin/network/users.php and opened up a number of sites and removed the user from each one manually. That’s a pretty awful pattern but being in a hurry leads to all sorts of bad choices.1 Today I got the request to remove around six hundred sites from a particular faculty member. The request coincided with time and mental bandwidth so I opted to do this in an intelligent way. There was also no way I was going to do this by hand. First step would be to get the user’s id from the wp_users table. You can look up users here by user_login or user_email and get to what you need pretty quickly. If you’re using Sequel Pro rather than the terminal don’t forget to restrain your searches by the right field. For this example, we’ll pretend […]

23

WordPress Timeline JS Plugin

Background I like Timeline JS. It’s a nice way to create multimedia timelines. I’d previously done some work that would take WordPress JSON API data and insert it into the Timeline JS view.1 It was nice for creating alternate and standardized views of blogs that might be useful for different reasons. It didn’t serve some other needs and while doing it through a generic URL was handy for many reasons it was odd in other scenarios. As a result I decided to make a new version as a plugin. If you don’t like reading stuff there’s a quick video of how it works below. Plugin Goals First, I wanted this to be a plugin rather than a theme. That adds a bit of complexity because you don’t have control of the whole scenario but it makes it much more portable and more likely to be used as it doesn’t require people to change themes or spin up an additional site. I wanted people to be able to use WordPress rather than a spreadsheet to create the content for Timeline JS. Doing that has a few advantages- the WYSIWYG editor, the ability to upload images directly in WordPress, the ability to use posts you’ve already written, etc. etc. I also wanted people to be able to choose what posts ended up […]