Created
April 9, 2014 07:58
-
-
Save hlashbrooke/10238513 to your computer and use it in GitHub Desktop.
Sensei: Reset all user activity (for all users or specified user)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sensei_reset_activity( $user_id = 0 ) { | |
// Get all Sensei activities | |
$token = 'sensei_'; | |
$activities = array( 'course_start', 'course_end', 'lesson_start', 'lesson_end', 'quiz_grade', 'quiz_answers', 'quiz_asked' ); | |
if( 0 < intval( $user_id ) ) { | |
$args['user_id'] = intval( $user_id ); | |
} | |
// Loop through all types of comments and delete | |
foreach ($activities as $activity ) { | |
$args['type'] = $token . $activity; | |
$comments = WooThemes_Sensei_Utils::sensei_check_for_activity( $args, true ); | |
foreach ( $comments as $key => $value ) { | |
if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { | |
wp_delete_comment( $value->comment_ID, true ); | |
} | |
} | |
} | |
} |
One caveat, this didn't work for resetting the Sensei Modules progress indicators which ended up sticking around after I ran the process.
For the time being, I ended up finding the values in the database directly.
They can be found under the wordpress usermeta table with the meta_key starting with "_module_progress" (and some sort of numerical underscored values attached) for a specific user_id just delete that row in the database and it will reset the module progress indicators.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those who are curious how to use this, setting the user_id value:
0 = all users (may take a long time to process depending on how many users, how many courses, lessons and progress activity they are involved with)
1 = admin user (usually)
2 and onward = specific users