admin管理员组文章数量:1126301
Wordpress- I need to get an email which signed up user visited/clicked on link/button/or visited specific page. Email needs to tell me at least their username, or something from sign up form from User Registration plugin. My plan is to use this button/page/link as payment link + notification for me which user registered for an event. Access to that page will be restricted to logged in users only. Im using User Registration plugin on Wordpress. Thank you
Wordpress- I need to get an email which signed up user visited/clicked on link/button/or visited specific page. Email needs to tell me at least their username, or something from sign up form from User Registration plugin. My plan is to use this button/page/link as payment link + notification for me which user registered for an event. Access to that page will be restricted to logged in users only. Im using User Registration plugin on Wordpress. Thank you
Share Improve this question edited Jan 20, 2024 at 22:08 Andrej Chalas asked Jan 20, 2024 at 21:56 Andrej ChalasAndrej Chalas 11 bronze badge1 Answer
Reset to default 0To achieve your goal of tracking when a signed-up user clicks on a link/button or visits a specific page on your WordPress site, and then sending an email notification with their details, you can follow these steps. Since you are using the User Registration plugin, we'll make sure to utilize its features where relevant.
Step 1: Tracking User Activity To track user clicks or page visits, you can use a custom JavaScript. This script will detect when a user interacts with a specific element (like a button or link) or visits a particular page.
Identify the Element or Page: Determine the ID or class of the button/link or the specific page you want to track.
JavaScript Tracking: Add a JavaScript snippet to your site that listens for clicks on the identified element or for page visits. You can add this script in your includes/js/script.js file.
<script>
jQuery(document).ready(function($) {
$('#yourElementId').click(function() {
var userData = {
'action': 'track_user_activity',
'user_id': wpb_user_info.user_id, // assuming user ID is available
'username': wpb_user_info.username // assuming username is available
};
$.post(wpb_ajax_url, userData, function(response) {
// Handle response if needed
});
});
});
</script>
Replace #yourElementId with the ID or class of your element. wpb_user_info and wpb_ajax_url are placeholders and need to be replaced with actual data and AJAX URL.
Step 2: AJAX Handler in WordPress You'll need to create an AJAX handler in WordPress that receives the data from your JavaScript and then sends the email.
Enqueue the Script and Localize Script: Use wpb_enqueue_scripts_plugin_name to enqueue your script and pass data like AJAX URL and user info to JavaScript.
function wpb_enqueue_scripts_plugin_name() {
wp_enqueue_script('wpb_custom_script', get_template_directory_uri() . '/includes/js/script.js', array('jquery'), mt_rand(00000, 9999999), true);
wp_localize_script('wpb_custom_script', 'wpb_user_info', array(
'user_id' => get_current_user_id(),
'username' => wp_get_current_user()->user_login,
'wpb_ajax_url' => admin_url('admin-ajax.php')
));
}
add_action('wp_enqueue_scripts', 'wpb_enqueue_scripts_plugin_name');
AJAX Callback Function: Create a function in your plugin's main file to handle the AJAX request.
function wpb_track_user_activity() {
$user_id = $_POST['user_id'];
$username = $_POST['username'];
// Perform your checks here
// Send email notification
$to = '[email protected]';
$subject = 'User Activity Notification';
$message = "Username: $username\nUser ID: $user_id";
wp_mail($to, $subject, $message);
echo 'Email sent';
wp_die();
}
add_action('wp_ajax_track_user_activity', 'wpb_track_user_activity');
add_action('wp_ajax_nopriv_track_user_activity', 'wpb_track_user_activity');
This setup allows you to track user activity on specific elements or pages and receive email notifications with user details, aiding in managing registrations for events on your WordPress site.
本文标签: pluginsEmail notification when registred user clicks a linkvisits page
版权声明:本文标题:plugins - Email notification when registred user clicks a linkvisits page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736683538a1947545.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论