Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Created April 9, 2014 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlashbrooke/10238513 to your computer and use it in GitHub Desktop.
Save hlashbrooke/10238513 to your computer and use it in GitHub Desktop.
Sensei: Reset all user activity (for all users or specified user)
<?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 );
}
}
}
}
@mkormendy
Copy link

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

@mkormendy
Copy link

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