A WordPress Plugin and Alfred Workflow to quickly retrieve a blog_id from a WP Multisite Network
Managing 70+ sites on a WordPress network is a big part of my day. These sites are not left and forgotten about, each site requires attention, maintenance, upgrades, imports, exports, duplication – just lots of moving things around and pin-pointing other things.
One of the biggest headaches I face in my work flow was looking up the
blog_id of a site within the network. It’s not a hard or specific task, currently I have four ways to retrieve one:
- Ask Slack with a proprietary slash command to look up client in project database
- WP Admin Network list of sites in
- WP Admin I’ve added the ID of each site in the footer of each sites
wp site listcommand
However, each of these ways still requires jumping out of what I’m doing, and they all have tiny headaches:
- using slack adds bloat to the channels
- getting into the WordPress network admin requires lots of clicking
- getting into a sites dashboard requires typing the domain and a login
- wp-cli site list is huge, and requires resizing terminal window & using cmd+f
wpsitelist command, followed by a keyword from the path of the site I’m looking for, reveals a list of the sites that contain the keyword. Selecting the site gives my clipboard the ID. Easy as pie. (Sites are asterisk out in demo for client privacy).
To do this, I first had to create a REST endpoint on my WordPress Multisite Network installation. An easy enough task, and broad enough functionality to release it as a simple 60-line PHP plugin. Activating this simple plugins gives my network the following endpoint (plus search filter):
Going to the REST API endpoint gives a JSON object of all sites path, domains, and their blog ID’s. In the plugin I’ve cache’d it for 24 hours, and added a query that does a rudimentary
strstr() argument to filter the cache’d results to only what’s looked for.
All told it’ll saves me just little over two dozen seconds a day – if that – and it took several hours to put together. However, as any developer knows, removing headache-tasks like the ID lookup saves so much stress, improves moral, and boosts productivity. As well as scratching your own itches and using different technologies and languages is fun and a good way to keep learning.
Well worth it.