WordPress Tutorial

WordPress obtains statistics of registered users today, yesterday, this week and this month

 Alibaba Cloud

When using Wordpress to obtain the statistics of today, yesterday, this week and this month's registered users, the problem is that the date is UTC time. So how to convert it to UTC+8 before statistics?

Use CONVERT_TZ (` user_registered ','+00:00 ','+08:00 ')

Want to be here? contact us bar
 Maker host
  1.  add_action ( 'wp_dashboard_setup' ,  'erphp_user_total_dashboard_widgets'  ) ;
  2.  function erphp_user_total_dashboard_widgets ( )  {
  3.  if ( current_user_can ( 'administrator' ) ) {
  4.  add_meta_box (  'erphp_user_total_widget' ,  'Registration statistics' ,  'erphp_user_total_widget_function' , 'dashboard' ,  'normal' ,  'core'  ) ;
  5.  }
  6.  }
  7.   
  8.  function erphp_user_total_widget_function ( ) {
  9.  global  $wpdb ;
  10.  $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" ) ;
  11.  $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" ) ;
  12.  $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())" ) ;
  13.  $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' )" ) ;
  14.   
  15.  echo  '<div class="activity-block"><ul style="margin:0 -10px;overflow:hidden">' ;
  16.  echo  '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  17.  <div style="font size: 19px; margin bottom: 20px;">Register today</div>
  18.  <div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $today_user ? $today_user -> ct : '0' ) . 'Users</a></div>
  19.  </li>' ;
  20.  echo  '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  21.  <div style="font size: 19px; margin bottom: 20px;">Register yesterday</div>
  22.  <div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $yestoday_user ? $yestoday_user -> ct : '0' ) . 'Users</a></div>
  23.  </li>' ;
  24.  echo  '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  25.  <div style="font size: 19px; margin bottom: 20px;">Register this week</div>
  26.  <div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $week_user ? $week_user -> ct : '0' ) . 'Users</a></div>
  27.  </li>' ;
  28.  echo  '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px); border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  29.  <div style="font size: 19px; margin bottom: 20px;">Register this month</div>
  30.  <div><a style="font-size:16px" href="' . admin_url ( 'users.php' ) . '">' . ( $month_user ? $month_user -> ct : '0' ) . 'Users</a></div>
  31.  </li>' ;
  32.  echo  '</ul></div>' ;
  33.  }

WordPress obtains statistics of registered users today, yesterday, this week and this month

242 people have bought
View Demo Upgrade VIP Buy Now

Collection
fabulous ( one )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!