Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions hello.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
Author URI: http://ma.tt/
*/

function hello_dolly_get_lyric() {
/** These are the lyrics to Hello Dolly */
$lyrics = "Hello, Dolly
namespace HelloDolly; // Removes the need for explicit prefixing

// These are the lyrics to Hello Dolly
const LYRICS = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
Expand Down Expand Up @@ -42,21 +43,21 @@ function hello_dolly_get_lyric() {
Promise, you'll never go away
Dolly'll never go away again";

function get_lyric(): string {
// Here we split it into lines.
$lyrics = explode( "\n", $lyrics );
$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_dolly() {
$chosen = hello_dolly_get_lyric();
function notice(): void {
$chosen = get_lyric();
$lang = '';
if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) {
$lang = ' lang="en"';
}

printf(
'<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s</span></p>',
__( 'Quote from Hello Dolly song, by Jerry Herman:', 'hello-dolly' ),
Expand All @@ -66,10 +67,10 @@ function hello_dolly() {
}

// Now we set that function up to execute when the admin_notices action is called.
add_action( 'admin_notices', 'hello_dolly' );
add_action( 'admin_notices', 'HelloDolly\notice' );

// We need some CSS to position the paragraph.
function dolly_css() {
function css(): void {
echo "
<style type='text/css'>
#dolly {
Expand Down Expand Up @@ -97,4 +98,4 @@ function dolly_css() {
";
}

add_action( 'admin_head', 'dolly_css' );
add_action( 'admin_head', 'HelloDolly\css' );