Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log all learner management bulk action events. #3146

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,36 @@ public function handle_http_post() {
}
}

// Log bulk actions events.
$filter_value = ! empty( $_POST['sensei_learners_bulk_action_filter'] ) ? sanitize_text_field( wp_unslash( $_POST['sensei_learners_bulk_action_filter'] ) ) : '-1'; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce already checked.

$event_properties = array(
'course_id' => $filter_value,
'course_count' => count( $course_ids ),
'learner_count' => count( $user_ids ),
);

switch ( $sensei_bulk_action ) {
case self::MANUALLY_ENROL:
$this->learner_management_bulk_actions_logger( 'learner_management_learner_bulk_add', $event_properties );
break;
case self::REMOVE_MANUAL_ENROLMENT:
$this->learner_management_bulk_actions_logger( 'learner_management_learner_bulk_remove', $event_properties );
break;
case self::REMOVE_PROGRESS:
$this->learner_management_bulk_actions_logger( 'learner_management_progress_bulk_reset', $event_properties );
break;
case self::COMPLETE_COURSE:
$this->learner_management_bulk_actions_logger( 'learner_management_course_completion_bulk_recalculate_notify', $event_properties );
break;
case self::RECALCULATE_COURSE_COMPLETION:
$this->learner_management_bulk_actions_logger( 'learner_management_course_completion_bulk_recalculate_no_notify', $event_properties );
break;
default:
break;
}
// End logging.

$this->redirect_to_learner_admin_index( 'action-success' );
}

Expand Down Expand Up @@ -420,4 +450,15 @@ public function add_notices() {
<?php
}

/**
* Helper method to log sensei events.
*
* @since 3.0.2
* @param string $event_name The name of the event to log.
* @param array $event_properties The properties to log for the event.
*/
public function learner_management_bulk_actions_logger( $event_name = '', $event_properties = array() ) {
sensei_log_event( $event_name, $event_properties );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private function render_bulk_actions_form( $courses ) {
<input type="hidden" id="bulk-action-user-ids" name="bulk_action_user_ids" value="">
<input type="hidden" id="sensei-bulk-action" name="sensei_bulk_action" value="">
<input type="hidden" id="bulk-action-course-ids" name="bulk_action_course_ids" value="">
<input type="hidden" id="sensei-learners-bulk-action-filter" name="sensei_learners_bulk_action_filter" value="<?php echo esc_attr( $this->query_args['filter_by_course_id'] ); ?>">
<?php wp_nonce_field( Sensei_Learners_Admin_Bulk_Actions_Controller::NONCE_SENSEI_BULK_LEARNER_ACTIONS, Sensei_Learners_Admin_Bulk_Actions_Controller::SENSEI_BULK_LEARNER_ACTIONS_NONCE_FIELD ); ?>
<button type="submit" id="bulk-learner-action-submit" class="button button-primary action"><?php echo esc_html__( 'Apply', 'sensei-lms' ); ?></button>
</form>
Expand Down