Add All Super Admins To All Sites On WordPress

One of the most annoying features of WordPress Multisites (besides domain mapping) is adding a Super Admin a few years after your network is established and grown. Sure, being a Super Admin allows said user to access any site on the network, but the user is technically not added to the site – so the Super Admins users My Sites tab will only have sites that s/he has been manually added to. The user is then forced to jump between sites with a headache of manually typing.

The follow script solves the problem, it runs through all super admins and adds them to all sites in the network they’re not yet added to.

The function needs to be run once to get everyone up to date. For the future it can be wrapped in a $_GET conditional to fire manually, a cronjob to run in background, or like I did, a transient, so that you can run it as often as you need. Mind you this isn’t a network plugin or intended to run on all sites, it just needs to run once on a single site. All the multisite data and blog_switching annoyance happens within the functions themselves.

Quickly And Easily Send To Slack via PHP Function

Quickly And Easily Send To Slack via PHP Function

Building a PHP app that communicates with Slack a lot, I found it was much cleaner to tuck everything away in a function and call it in a single function that resembles the attributes of mail(). This makes for changing your apps icon andor color easy, as well as staying consistent with the Title and PreText.

Slack Incoming Hook required.

WordPress Custom Taxonomy Meta

I remember all the custom solutions and plugins needed before this was supported in WordPress 4.4.

A great snippet to have in your toolbox. I’ve reduced it to the bare basics.

One Password Form For All Password Protected WordPress Posts

When using a custom post type for portfolio items, I needed several of them to be password protected, showing a lock icon instead of the portfolio item. The posts are shown via a normal loop, but they’re just thumbnails with lightbox links. To password protect them all, and have them all unlock with a single method, I came up with the following:

For the above to work, all posts passwords need to be the same password. The above uses featherlight, or whatever lightbox you prefer to hide/reveal the password form. Remove the display:none from #passwordInput to bypass lightbox.

Google Maps v3 API AutoComplete Use First Result

The following script stores the first result from Google Maps v3 API AutoComplete into a hidden input, allowing you to do something with the autocomplete input field if the user decides to type their address instead of click a result. I’ve included only the extra code ontop of the normal autoComplete script.

WP-CLI Works But Gives ERRORs For All Updating

Every developer has these all-day’er’s. What in the happenings of happenings is happening. I had it with one of my favourite tools wp-cli something I rely on heavily for my workflow.

Clean installed, valid versions, so on. wp list plugins returned all good. However any real writing like wp plugin update --all failed. And the error’s are so vague:

PHP Warning: array_filter() expects parameter 1 to be array, boolean given in phar:///usr/local/bin/wp/php/WP_CLI/CommandWithUpgrade.php on line 319
Warning: array_filter() expects parameter 1 to be array, boolean given in phar:///usr/local/bin/wp/php/WP_CLI/CommandWithUpgrade.php on line 319
Error: No plugins updated.

What made matters worse: no one else seemed too of experienced this, so I had no resources online to work off of.

The problem was two-fold:

1) The php.ini file being used (found via wp --info) was PHP cli’s, not apache’s, so short_open_tag wasn’t set to On. I have many plugins that use this tag and I didn’t know about cli having it’s own php configuration.

2) I had folders in my themes/ and plugin/ that were soft deleted (there but inaccessible) set to chmod 700. That needed to be removed. Apparently wp likes to read every folder therein and if it can’t it throws a fit.

I was able to discover these problems and bypass them with the --skip-plugins flag. So if you’ve experienced anything like what I just went through, try that, and lookout for those two issues above.