hi.
i had created two custom user meta fields in my user profiles manually using functions.php in my theme. (not using ACF)
same as my friend Shaneholden, i wanted to create custom event and logs when those meta fields change for any user.
so i made some modifications in plugin files (which certainly is not a correct solution). but as a temporary solution, i’m going to share it with you and i hope this help.
my custom user meta fields are two selectbox and their meta-keys are:
1. bid_num_permit
2. special_bid_permit
At first i opened up UserProfile.php (pluginroot\classes\Sensors) and added these lines after line 100 (email changed condition) :
// email changed
if(!empty($_REQUEST['email'])){
...
}
// Line 101 - my code starts here
$oldPermit = get_user_meta( $user_id, 'bid_num_permit', true );
$newPermit = trim($_REQUEST['bid_num_permit']);
if($oldPermit != $newPermit){
$this->plugin->alerts->TriggerIf(4015, array(
'TargetUserID' => $user_id,
'TargetUsername' => $user->user_login,
'OldPermit' => $oldPermit,
'NewPermit' => $newPermit,
), array($this, 'MustNotContainUserChanges'));
}
$oldSpecial = get_user_meta( $user_id, 'special_bid_permit', true );
$newSpecial = trim($_REQUEST['special_bid_permit']);
if($oldSpecial != $newSpecial){
$this->plugin->alerts->TriggerIf(4016, array(
'TargetUserID' => $user_id,
'TargetUsername' => $user->user_login,
'oldSpecial' => $oldSpecial,
'newSpecial' => $newSpecial,
), array($this, 'MustNotContainUserChanges'));
}
as u can see, i created two new alert code for these events: 4015 & 4016.
now for creating a custom message for these events, i opend up default.php file in plugin root and added these lines after line 123 (array(4007….):
array(4007, E_CRITICAL, __('A user was deleted by another user', 'wp-security-audit-log'), __('Deleted User %TargetUserData->Username% with the role of %TargetUserData->Roles%', 'wp-security-audit-log')),
array(4015, E_NOTICE, __('Special Bid Permission', 'wp-security-audit-log'), __('Number of allowed special bids for user %TargetUsername% changed from %OldPermit% to %NewPermit%.', 'wp-security-audit-log')),
array(4016, E_NOTICE, __('Special Bid Offer Permission', 'wp-security-audit-log'), __('Permission to send offer in special bids for user %TargetUsername%, changed from %oldSpecial% to %newSpecial%.', 'wp-security-audit-log')),
),
__('Plugins & Themes', 'wp-security-audit-log') => array(
.....
after save, it worked as i expect.
& also those events (4015 & 4016) were automatically added in User Profiles Tab in plugin alters.
WPWhiteSecurity, tnx for your great plugin ??