Get certificate list on a specific date

In assessment tab, I can see the Last Active column, but I need to know who got certificates on a specific date. Is it possible to find out?

I just need some way to see who got certified on a single day, trying to look manually through all these students, but that becomes unusable.

I don't mind if it's a downloaded report or anything.

  • Ivan
    • Developer

    Hi Jonathan !

    You could try adding the following snippet in a mu-plugin

    <?php
    function wpmu_coursepress_get_certificate_by_date( $obj ) {
    	if ( !empty( $_GET['action'] ) && 'coursepress_assessments' === $_GET['action'] ) {
    		if ( !empty( $obj->query_vars['search_columns'] ) && array( 'user_login', 'user_nicename', 'user_email' ) === $obj->query_vars['search_columns']
    				&& ( $date = strtotime( str_replace( '*', '', $obj->query_vars['search'] ) ) ) ) {
    			$id_course = (int)str_replace( 'enrolled_course_date_', '', $obj->query_vars['meta_key'] );
    			if ( $id_course ) {
    				global $wpdb;
    				$date = date( 'Y-m-d', $date );
    				$user_ids = $wpdb->get_col( "SELECT post_author FROM {$wpdb->posts} WHERE post_type='cp_certificate' AND post_parent={$id_course} AND post_date LIKE '{$date}%'" );
    				if ( empty( $user_ids ) ) {
    					$user_ids[] = 0;
    				}
    				$user_args = array(
    						'fields' => 'ID',
    						'include' => $user_ids,
    				);
    
    				$obj->query_vars = $obj->fill_query_vars( $user_args );
    			}
    		}
    	}
    }
    
    add_action( 'pre_get_users', 'wpmu_coursepress_get_certificate_by_date' );

    After that, you can search users by date when they had certificate in this format - Y-m-d ( for example, 2017-10-24 )

    Let me know how it goes for you!

    Best regards,
    Ivan.

  • Ivan
    • Developer

    Hi Jonathan !

    You are right. It happened because I created that snippet only for a single site but you use Multisite. So, it's final MU plugin and it will work for both options

    <?php
    function wpmu_coursepress_get_certificate_by_date( $obj ) {
    	if ( !empty( $_GET['action'] ) && 'coursepress_assessments' === $_GET['action'] ) {
    		if ( !empty( $obj->query_vars['search_columns'] ) && array( 'user_login', 'user_nicename', 'user_email' ) === $obj->query_vars['search_columns']
    				&& ( $date = strtotime( str_replace( '*', '', $obj->query_vars['search'] ) ) ) ) {
    
    			preg_match( '/\d+$/', $obj->query_vars['meta_key'], $matches );
    			$id_course = !empty( $matches[0] ) ? (int)$matches[0] : '';
    
    			if ( $id_course ) {
    				global $wpdb;
    				$date = date( 'Y-m-d', $date );
    				$user_ids = $wpdb->get_col( "SELECT post_author FROM {$wpdb->posts} WHERE post_type='cp_certificate' AND post_parent={$id_course} AND post_date LIKE '{$date}%'" );
    				if ( empty( $user_ids ) ) {
    					$user_ids[] = 0;
    				}
    				$user_args = array(
    						'fields' => 'ID',
    						'include' => $user_ids,
    				);
    
    				$obj->query_vars = $obj->fill_query_vars( $user_args );
    			}
    		}
    	}
    }
    
    add_action( 'pre_get_users', 'wpmu_coursepress_get_certificate_by_date' );

    Also, I already changed it on your site and it seems it works fine.

    Best regards,
    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.