wordpress收费下载资源主题
wordpress付费下载资源插件

wordpress获取今天、昨天、本周、本月注册用户统计

模板兔在用wordpress获取今天、昨天、本周、本月注册用户统计时遇到个问题就是日期是UTC时间,那么如何转成UTC+8后再统计呢?

使用CONVERT_TZ(`user_registered`,'+00:00','+08:00')

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', '注册统计', '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;">今日注册</div>
<div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($today_user?$today_user->ct:'0').' 用户</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;">昨日注册</div>
<div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($yestoday_user?$yestoday_user->ct:'0').' 用户</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;">本周注册</div>
<div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($week_user?$week_user->ct:'0').' 用户</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;">本月注册</div>
<div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($month_user?$month_user->ct:'0').' 用户</a></div>
</li>';
echo '</ul></div>';
}

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请先加Q,临时会话收不到
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情