add_action ( 'wp_dashboard_setup' , 'erphp_user_total_dashboard_widgets' ) ;
function erphp_user_total_dashboard_widgets ( ) {
if ( current_user_can ( 'administrator' ) ) {
add_meta_box ( 'erphp_user_total_widget' , 'Registration statistics' , 'erphp_user_total_widget_function' , 'dashboard' , 'normal' , 'core' ) ;
}
}
function erphp_user_total_widget_function ( ) {
global $wpdb ;
$today_user = $wpdb -> get_row ( "SELECT count(ID) as ct FROM $wpdb->users WHERE TO_DAYS(NOW())- TO_DAYS(CONVERT_TZ(`user_registered`,'+00:00','+08:00')) = 0" ) ;
$yestoday_user = $wpdb -> get_row ( "SELECT count(ID) as ct FROM $wpdb->users WHERE TO_DAYS(NOW())- TO_DAYS(CONVERT_TZ(`user_registered`,'+00:00','+08:00')) = 1" ) ;
$week_user = $wpdb -> get_row ( "SELECT count(ID) as ct FROM $wpdb->users WHERE YEARWEEK(date_format(CONVERT_TZ(`user_registered`,'+00:00','+08:00'),'%Y-%m- %d ')) = YEARWEEK(now())" ) ;
$month_user = $wpdb -> get_row ( "SELECT count(ID) as ct FROM $wpdb->users WHERE DATE_FORMAT( CONVERT_TZ(`user_registered`,'+00:00','+08:00'), '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )" ) ;
echo '<div class="activity-block"><ul style="margin:0 -10px;overflow:hidden">' ;
echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
<div style="font size: 19px; margin bottom: 20px;">Register today</div>
<div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $today_user ? $today_user -> ct : '0' ) . 'Users</a></div>
</li>' ;
echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
<div style="font size: 19px; margin bottom: 20px;">Register yesterday</div>
<div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $yestoday_user ? $yestoday_user -> ct : '0' ) . 'Users</a></div>
</li>' ;
echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
<div style="font size: 19px; margin bottom: 20px;">Register this week</div>
<div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $week_user ? $week_user -> ct : '0' ) . 'Users</a></div>
</li>' ;
echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
<div style="font size: 19px; margin bottom: 20px;">Register this month</div>
<div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $month_user ? $month_user -> ct : '0' ) . 'Users</a></div>
</li>' ;
echo '</ul></div>' ;
}