Tim moves our rampages database to our dev server roughly every month. Our database is big and awkward and uses Multi DB to deal with the scale. Because of the multiple databases some of the typical migration patterns to get the URLs right don’t work. We were suffering through that for a while but I’d find myself ported from the dev environment to the live site at times without realizing that’s what happened. That is not a fun way to live. Because Jeff was working on a really smart way to do this in the database I realized I didn’t know more than I thought I didn’t know. As a result I stumbled upon the ability to filter the site url and home options. That means we can make a tiny little network activated plugin that leaves our database alone and just filters things on the fly with a dab of regex.
I took the opportunity to participate in the #PressedConf yesterday. Described as “. . . a twitter conference (#pressedconf18) looking into how WordPress is used in teaching, pedagogy and research.” it was a pretty impressive number of people and topics covered on Twitter in roughly 20 minute “Tweet storms.”1 Presenting on Twitter was something new to me and I tried to think through some interesting ways to approach things. Given how limited Twitter was I tried to tackle complexity in a few different ways while taking advantage of the way Twitter treats different content integrations. The Post I ended up deciding to build out a WordPress post with various sections that were associated with a number of the Tweets I’d make. I used good ol’ anchor links in the Tweets to be able to link specifically to those sections without having to resort lots of little posts. For example – brings you to the Custom Composition section directly. Not very visual on the Twitter end and probably cheating in the scheme of things. The Videos I tried to tackle other complexity through videos. I made a number of new videos and took advantage of a few others I’d had to try to show more details. I kind of wonder if this worked well. They appeared in two different ways. Some […]
This is my supporting documentation for the #PressEd WordPress conference that I’ll be doing via Twitter on Thursday. The Topic Given I’ve been playing around in WordPress since what feels like the dawn of time, I’ve heard lots of people say lots of things about it. I’ve heard it’s too complex. I’ve heard it’s too easy. I’ve been told it won’t allow you to map/GIS information and that it can’t be used for any number of other things. I’ve been told it won’t do things that you can do in this other CMS or that other LMS. As with most things, these boundaries are mostly imaginary and live more in people’s heads than they do in the software itself. My goal here will be to take you on a tour of what you can do to impact the authoring experience in WordPress. We’ll start by removing complexity from WordPress itself but staying within the typical authoring patterns. We’ll do that in the easiest ways first and then move to more involved interventions. After that, we’ll jump to non-standard authoring patterns and run around seeing where the edges are. Minimalism/Reducing Complexity Screen Options There’s quite a bit of control you have just within the Screen Options settings available to the author. If you can check/uncheck a box these options are available […]
If you’re running the H5P plugin in WordPress, you might notice that there’s an advanced settings option when you go to embed it. If you click on that you’ll see an additional script to add to enable dynamic sizing of embedded H5P content. I wanted that but that option doesn’t make much sense in our environment. If you read this blog a lot and have an amazing memory, you’ll know I have a plugin that’s network activated where I put little things that make sense but don’t need their own dedicated plugin. This seemed like one that fits that bill. It’s really simple. It asks if the site is running H5P and if the answer is yes, it enqueues the h5p-resizer.js.
This may be one of those things that everyone knows but it was new to me. I’m also duplicating the information I found in the StackOverflow post because I think it’s good to have information in multiple places where it might be found by other people. Additionally, writing the post makes it easy for me to find later when I forget and the act of writing the post helps get it stuck in my own head. With all of that as the lead up . . . A common way to trigger events in WordPress is the save_post action. It runs any time the post is created, published, or updated. What I found out though was that it also runs when you try to delete the post. That makes sense. It is an update and it’s no big deal if the function is relatively small and/or if you’re not trying to get rid of a ton of posts. My current experiment had both a fairly involved function and a couple hundred posts I wanted deleted. Luckily, I found this post on StackOverflow. Now I can set a simple check at the beginning of the function that looks to make sure it’s the right post type (site) and it’s a trashed post. In either of those cases the function gets skipped.
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.
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.
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.
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 […]
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 […]