From f5d0fb7e1d63e3a7dc776dea593be80465fac49f Mon Sep 17 00:00:00 2001 From: Ostap Brehin Date: Mon, 26 Aug 2024 01:27:09 +0100 Subject: [PATCH] Use namespace --- hello.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/hello.php b/hello.php index c2ba387..749ad75 100644 --- a/hello.php +++ b/hello.php @@ -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 @@ -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( '

%s %s

', __( 'Quote from Hello Dolly song, by Jerry Herman:', 'hello-dolly' ), @@ -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 "