Files
Testing/blog/wp-content/plugins/quiz-master-next/php/classes/class-qsm-audit.php
sean 0e8a8b3028
Some checks failed
deploy-testing / deploy (push) Has been cancelled
Initial testing snapshot
2026-11-17 16:15:01 -05:00

60 lines
1.3 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* This class handles the audit trail of the plugin
*/
class QSM_Audit {
/**
* Adds new audit to Audit Trail table
*
* @since 4.7.1
* @param string $action The action that is to be saved into the audit trail
* @return bool Returns true if successfull and false if fails
*/
public function new_audit( $action, $user = null ) {
// Sanitizes action just in case 3rd party uses this funtion
$action = sanitize_text_field( $action );
// Retrieves current user's data
if ( is_null( $user ) ) {
$current_user = wp_get_current_user();
} else {
$current_user = $user;
}
// Returns if the current user is not valid
if ( ! ( $current_user instanceof WP_User ) ) {
return false;
}
global $wpdb;
// Inserts new audit into table
$inserted = $wpdb->insert(
$wpdb->prefix . "mlw_qm_audit_trail",
array(
'action_user' => $current_user->display_name,
'action' => $action,
'time' => date("h:i:s A m/d/Y")
),
array(
'%s',
'%s',
'%s'
)
);
// If the insert returns false, then return false
if ( false === $inserted ) {
return false;
}
return true;
}
}
?>