diff --git a/wp-content/plugins/wporg-learn/inc/sensei.php b/wp-content/plugins/wporg-learn/inc/sensei.php index b832e0e74..4c0fd801f 100644 --- a/wp-content/plugins/wporg-learn/inc/sensei.php +++ b/wp-content/plugins/wporg-learn/inc/sensei.php @@ -163,3 +163,60 @@ function wporg_fix_learning_mode_header_space() { wp_add_inline_style( 'learning-mode-header-fix', $custom_styles ); } add_action( 'sensei_course_learning_mode_load_theme', __NAMESPACE__ . '\wporg_fix_learning_mode_header_space' ); + +/** + * Add script to count unique learners + */ +function wporg_learn_add_student_count_to_reports( $type ) { + if ( 'users' !== $type ) { + return; // Only show the count on the students report screen. + } + + $from_date = \DateTime::createFromFormat( 'Y-m-d', $_GET['from_date'] ?? '', new \DateTimeZone( 'UTC' ) ); + $to_date = \DateTime::createFromFormat( 'Y-m-d', $_GET['to_date'] ?? '', new \DateTimeZone( 'UTC' ) ); + + global $wpdb; + $query = "SELECT COUNT(DISTINCT user_id) + FROM $wpdb->comments + WHERE comment_type = 'sensei_course_status'"; + + if ( $from_date ) { + $from_date->setTime( 0, 0, 0 ); + + $query .= " AND comment_date_gmt >= '" . $from_date->format( 'Y-m-d H:i:s' ) . "'"; + } + + if ( $to_date ) { + $to_date->setTime( 23, 59, 59 ); + + $query .= " AND comment_date_gmt <= '" . $to_date->format( 'Y-m-d H:i:s' ) . "'"; + } + + $student_count = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + + ?> +
+ + + + +
+
+