1. Go to this page and download the library: Download juvo/wp-secure-actions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Create action at any time after init hook was executed
add_action( 'profile_update', 'createAction', 10, 2 );
function createAction( $user_id, $old_user_data ) {
$user = get_userdata( $user_id );
$secActionsManager= \juvo\WordPressSecureActions\Manager::getInstance();
// Create action
$key = $secActionsManager->addAction(
"send_mail_$user_id", // name
"wp_mail", // callback
[
$user->user_email, // arg1
"Secure action executed", // arg2
"The secure action was executed successfully." // arg3
]
);
}
// Execute the stored action any time later
(\juvo\WordPressSecureActions\Manager::getInstance())->executeAction($key);
// Create action at any time after init hook was executed
add_action( 'profile_update', 'createAction', 10, 2 );
function createAction( $user_id, $old_user_data ) {
$user = get_userdata( $user_id );
$secActionsManager= \juvo\WordPressSecureActions\Manager::getInstance();
// Create Action
$key = $secActionsManager->addAction(
"send_mail_$user_id", // name
"ourCallbackFunction", // callback
[
$user, // arg1
]
);
// Generate url with helper function to automatically execute action
$actionUrl = $secActionsManager->buildActionUrl($key);
// Send mail containing the url
wp_mail(
$user->user_email,
"Profile Updated",
"Your profile was updated click here to check it out $actionUrl"
);
}
// Callback that executes when link is clicked
function ourCallbackFunction(WP_User $user, Action $action) {
wp_set_auth_cookie($user->ID, false);
do_action('wp_login', $user->user_login, $user);
// Manually increment count because this callback function has no return value
\juvo\WordPressSecureActions\Manager::getInstance()->incrementCount($action);
wp_safe_redirect(get_edit_profile_url($user->ID)); // Redirect to profile page
exit;
}
// Disable cleanup
add_filter( 'secure_action_cleanup', function() {
return false;
}, 10, 3 );
// Exclude based on name
add_filter( 'secure_action_cleanup', 'whitelistActions', 10, 3 );
function whitelistActions(bool $delete, Action $action, string $name) {
if ($name === "my_action") {
return false;
}
return $delete;
}