WordPress Dynamically Write Number of Years Since With Shortcode

As the lengthy title says, the follow simple script allows you to use a shortcode to dynamically output the number of years since a specified date. I wrote this for my own bio, which I used to have to update the number of years since the start of my employment once a year. The simple’r solution would be to write, “blah blah blah since 2010” instead of “blah blah blah for 7 years“. But hey, why not.

Simple usage is []years since="2010-07-01"[] would output something like 7.

WordPress Display MarkDown ReadMe File With Shortcode

For demo/home sites of a theme/plugin that wish to include the projects main readme files as part of the website, this quick snippet loads the folders README.md file, and parses the MarkDown (to githubs flavour) with a awesome jQuery plugin, all with the simple call of a [readme] shortcode.

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

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.

Server Stats on Desktop

Knowing how my server is preforming at all times kind of an hobby with mine. I know I can subscribe to some tools and services that display this info in beautiful graphics and charts, but I like simple things, and I like using default stuff. Years ago I wrote about a similar script to this, that used this info with jQuery gauges and Panic StatusBoard, but this is a much cleaner and easier method, and much simpler, and I just like it a whole heck of a lot better. So to do this, we have three steps:

  1. Remote Server cronjob that puts top output into a non-public server_top.txt file
  2. Remote Server public PHP file server_top.php that regex’s and sorts out the server_top.txt values and creates a serialized array of our desired stats for public
  3. Finally a local PHP file geeklet-server_top.php file that converts theserialized array into something and put it on our desktop with GeekTool

First on Remote Server we need to make sure top outputs all CPU’s so we can factor them all in and find an average. To do that, run top and hit the key 1 this will reveal all CPUs. Next hit W to save this CPU-revealed configuration as default.

We then setup a cronjob with crontab -e that puts the top result in a file in a non-public directory:

Second, with our server outputing top into a non-public file, we don’t want to share all the info, so we’ll be cryptic with this next script. We’ll make a file in the public directory called server_top.php and we’ll read the .txt file, and only output a vauge array of non-compromising data, which we’ll interperut locally in the next step:

Lastly, with out Remote Server now giving us an array of the CPU, Memeory, Average Load, Top Time, and HDD size, we’ll render this data on our local server into bars for GeekTool:

We locally, now have a script creating our server stats into bars. We then create a new Shell Geeklet and run the command:

Then set the font to somthing monospace for lining up the text, and to refresh as often as our crontab does, and that’s all!

You’ll notice there’s a warning point, which simply changes the progress bar to somthing more attention grabbing if any of the stats are above a conerning percentage. If static text hidden on the desktop isn’t enough, you could take this script further and use mail() or to email you a notification of this high stat.