forked from wp-plugins/hello-dolly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathironic.php
68 lines (59 loc) · 2.25 KB
/
ironic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @package Hello_Irony
* @version 1.0
*/
/*
Plugin Name: Hello Irony
Plugin URI: https://wp.rmoore.dev/plugins/hello-irony/
Description: This is not just a plugin, it symbolizes the waning hope and dwindling enthusiasm of an entire generation, summed up in three words sung most famously by Alanis Morrissette: Isn’t it ironic? When activated, you will randomly see a lyric from Ironic in the upper right of your admin screen on every page. Forked from the classic “Hello Dolly” plugin by Matt Mullenweg.
Author: Rob Moore
Version: 1.0
Author URI: http://rmoore.dev/
*/
function hello_irony_get_lyric() {
/** These are the lyrics to Ironic */
$lyrics = "
An old man turned 98. He won the lottery, and died the next day.
It's a black fly in your Chardonnay.
It's a death row pardon two minutes too late.
Mr. \"Play It Safe\" was afraid to fly. He packed his suitcase and kissed his kids goodbye. He waited his whole damn life to take that flight, and as the plane crashed down, he thought, \"Well, isn't this nice?\"
A traffic jam when you're already late.
A no-smoking sign on your cigarette break.
It's like ten thousand spoons when all you need is a knife.
It's meeting the man of my dreams, and then meeting his beautiful wife.
It's like rain on your wedding day
It's a free ride when you've already paid
It's the good advice that you just didn't take
And who would've thought, it figures
And isn't it ironic, don't you think?";
// Here we split it into lines
$lyrics = explode( "\n", $lyrics );
// And then randomly choose a line
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
// This just echoes the chosen line, we'll position it later
function hello_irony() {
$chosen = hello_irony_get_lyric();
echo "<p id='irony'>$chosen</p>";
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_irony' );
// We need some CSS to position the paragraph
function irony_css() {
// This makes sure that the positioning is also good for right-to-left languages
$x = is_rtl() ? 'left' : 'right';
echo "
<style type='text/css'>
#irony {
float: $x;
padding-$x: 15px;
padding-top: 5px;
margin: 0;
font-size: 11px;
}
</style>
";
}
add_action( 'admin_head', 'irony_css' );
?>