For you WordPress users, if you screw around with plugins at all, you might have noticed the Hello, Dolly plugin and wondered to yourself what the hell it does. Here’s the official description:
This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.
The source can be found here. It’s got lots of neat little tooltips, so bringing it over here would do it an injustice. Go check it out.
On line 15, where it says “$lyrics = “Hello, Dolly” and so on down to line 44, that whole thing in quotes is a variable containing the lyrics. I went ahead and replaced them with the lyrics to this Mastodon song:
As the comment on line 46 states, the explode method splits the lyrics into lines using the newline character as a delimiter. explode returns an array. (Since variables in PHP are evidently dynamically typed, it doesn’t matter if we return it to $lyrics.)
All right, now here’s the trick. On your admin screen – the dashboard – WordPress calls the ‘admin_notices’ action, which displays a little notice for you at the top right of the screen. On line 60, ‘add_action’ tacks on ‘hello_dolly’ (which I renamed to ‘hello_mastodon’) – that means, that the function ‘hello_mastodon’ on line 54 is going to be called. What ‘hello_mastodon’ does is prints out a randomly chosen element of the $lyrics variable (now an array, recall). And the next function, starting on line 63, positions the lyrics 5 pixels (5px) down from the top and 15 pixels from either the left or the right, depending on which way you read, while making the font size 11 pixels.
Finally, when ‘admin_head’ is called, which (presumably) prints out the header on your admin page, then the whole thing comes together. To put it all together, I uploaded it to my /wp-content/plugins directory as “hello.php,” and since Hello, Dolly was already activated, WordPress already runs it. Here’s the result:
Add a comment