Skip to content

More than just "Hello" #7

@yoren

Description

@yoren

We want to be more friendly by greeting the current user based on the current time, so we can greet them with "Good Morning" before noon and "Good Afternoon" in the noon etc.

ChatGPT kindly offers us two functions (in PHP and JavaScript) that divide 24 hours into 3 parts so we can decide what message to return:

function getWelcomeMessage() {
    date_default_timezone_set('Your/Timezone'); // Set your desired timezone

    $currentTime = date('H:i'); // Get the current time in 24-hour format (e.g., 13:45)

    if ($currentTime >= '00:00' && $currentTime < '12:00') {
        $message = 'Good morning!';
    } elseif ($currentTime >= '12:00' && $currentTime < '18:00') {
        $message = 'Good afternoon!';
    } else {
        $message = 'Good night!';
    }

    return $message;
}

// Example usage
$welcomeMessage = getWelcomeMessage();
echo $welcomeMessage;
function getWelcomeMessage() {
  var currentTime = new Date();
  var currentHour = currentTime.getHours();

  if (currentHour >= 0 && currentHour < 12) {
    return 'Good morning!';
  } else if (currentHour >= 12 && currentHour < 18) {
    return 'Good afternoon!';
  } else {
    return 'Good night!';
  }
}

// Example usage
var welcomeMessage = getWelcomeMessage();
console.log(welcomeMessage);

We shall also update them with WordPress's secret source like __() to make the greetings translatable or reading the timezone from get_option().

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions