PHP code snippet
This-month-birthday
<?php
$today = date("M");
$blogusers = get_users(array(
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
echo "<b>-This month</b>";
echo '<ol>';
foreach($blogusers as $user){
$name = $user->first_name;
$email = $user->user_email;
$date = $user->date_of_birth;
$date = date("M",strtotime($date));
if($today == $date){
echo '<li><span>' . esc_html($user->user_email) . ' : ' . esc_html($user->date_of_birth) . '</span></li>';
}
}
echo '</ol>';
?>
Today-birthday-user-list
<?php
$today = date("M d");
$blogusers = get_users(array(
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
echo "<b>-Today</b>";
echo '<ol>';
foreach($blogusers as $user){
$name = $user->first_name;
$email = $user->user_email;
$date = $user->date_of_birth;
$date = date("M d",strtotime($date));
if($today == $date){
echo '<li><span>' . esc_html($user->user_email) . ' : ' . esc_html($user->date_of_birth) . '</span></li>';
}
}
echo '</ol>';
?>
February-of-birthday
<?php
$str_date = "20240201";
$month = date("M", strtotime( $str_date ) );
$blogusers = get_users(array(
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
echo "<b>-February</b>";
echo '<ol>';
foreach($blogusers as $user){
$name = $user->first_name;
$email = $user->user_email;
$date = $user->date_of_birth;
$date = date("M",strtotime($date));
if($month == $date){
echo '<li><span>' . esc_html($user->user_email) . ' : ' . esc_html($user->date_of_birth) . '</span></li>';
}
}
echo '</ol>';
?>
Add admin menu
// Create a custom wordpress dashboard admin menu
function custom_menu() {
add_menu_page(
'Users Birthday', // Menu title
'Users Birthday', // Page title
'manage_options', // Capability (adjust as needed)
'users-birthday', // Menu slug
'custom_menu_callback', // Callback function
'dashicons-admin-generic', // Icon (optional)
99 // Position in the menu
);
}
// Callback function for the menu page
function custom_menu_callback() {
echo '<h1>Users Birthday</h1>';
echo '<div>';
echo do_shortcode('[xyz-ips snippet="Today-birthday-user-list"]');
echo '</div>';
echo '<div>';
echo do_shortcode('[xyz-ips snippet="This-month-birthday"]');
echo '</div>';
echo '<div>';
echo do_shortcode('[xyz-ips snippet="January-of-birthday"]
[xyz-ips snippet="February-of-birthday"]
[xyz-ips snippet="March-of-birthday"]
[xyz-ips snippet="April-of-birthday"]
[xyz-ips snippet="May-of-birthday"]
[xyz-ips snippet="June-of-birthday"]
[xyz-ips snippet="July-of-birthday"]
[xyz-ips snippet="August-of-birthday"]
[xyz-ips snippet="September-of-birthday"]
[xyz-ips snippet="October-of-birthday"]
[xyz-ips snippet="November-of-birthday"]
[xyz-ips snippet="December-of-birthday"]');
echo '</div>';
}
// Hook into the admin menu
add_action('admin_menu', 'custom_menu');