-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhallo-spaceboy.php
65 lines (56 loc) · 1.73 KB
/
hallo-spaceboy.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
<?php
/**
* @package Hallo Spaceboy
* @version 1.7
*/
/*
Plugin Name: Hallo Spaceboy
Plugin URI: https://github.com/lukecav/hallo-spaceboy
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 David Bowie: Hallo Spaceboy. When activated you will randomly see a lyric from <cite>Hallo Spaceboy</cite> in the upper right of your admin screen on every page.
Author: Luke Cavanagh
Version: 1.7
Author URI: https://github.com/lukecav
*/
function hallo_spaceboy_get_lyric() {
/** These are the lyrics to Hallo Spaceboy */
$lyrics = "Hallo Spaceboy,
you're sleepy now
Your silhouette is so stationary
You're released but your custody calls
And I want to be free
Don't you want to be free
Do you like girls or boys
It's confusing these days
But Moondust will cover you
Cover you
This chaos is killing me";
// 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 hallo_spaceboy() {
$chosen = hallo_spaceboy_get_lyric();
echo "<p id='spaceboy'>$chosen</p>";
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hallo_spaceboy' );
// We need some CSS to position the paragraph
function spaceboy_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'>
#spaceboy {
float: $x;
padding-$x: 15px;
padding-top: 5px;
margin: 0;
font-size: 11px;
}
</style>
";
}
add_action( 'admin_head', 'spaceboy_css' );
?>