User Registration Chart Widget

This WordPress plugin provides a dashboard widget that displays a bar chart of user registrations over the past 7 days. It utilizes Google Charts to render the bar chart and queries the WordPress database to retrieve the necessary data.

<?php /* Plugin Name: User Registration Chart Plugin URI: Description: Adds a widget to the WordPress dashboard showing user registration data as a bar chart for the past 7 days. Version: 1.0 Author: CodeWP Assistant Author URI: */ function codewp_dashboard_widget() { wp_add_dashboard_widget( 'codewp_user_registration_chart', 'User Registration Chart', 'codewp_user_registration_chart_function' ); } add_action('wp_dashboard_setup', 'codewp_dashboard_widget'); function codewp_user_registration_chart_function() { global $wpdb; $dates = []; for ($i = 0; $i < 7; $i++) { $dates[] = date('Y-m-d', strtotime("-{$i} days")); } $user_counts = []; foreach ($dates as $date) { $user_counts[] = (int) $wpdb->get_var($wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users WHERE DATE(user_registered) = %s", $date )); } echo '<div id="user_registration_chart"></div>'; wp_enqueue_script('google-charts', ''); wp_add_inline_script('google-charts', sprintf(" google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable(%s); var options = { title: 'User Registration', legend: { position: 'none' }, hAxis: { title: 'Date', format: 'M/d/yy', }, vAxis: { title: 'Number of registrations', }, bars: 'vertical' }; var chart = new google.visualization.ColumnChart(document.getElementById('user_registration_chart')); chart.draw(data, options); } ", json_encode(array_merge([['Date', 'Registrations']], array_reverse(array_map(null, $dates, $user_counts)))))); }

Frequently Asked Questions

It's a WordPress plugin that adds a widget to your dashboard to display user registration statistics as a bar chart.