This guide provides code to save emails shared through the WPGENS RAF (Refer a Friend) plugin. You can add this code to your theme’s functions.php file.
Instructions:
1. Open your theme’s functions.php file. You can do this through the WordPress admin panel under Appearance > Theme Editor, or via FTP.
2. Copy and paste the following code at the end of your functions.php file:
// Save RAF shared emails
function save_raf_shared_emails($type, $data) {
if ($type === 'email_share') {
$shared_emails = get_option('raf_shared_emails', array());
$shared_emails[] = array(
'email' => $data['email'],
'name' => $data['name'],
'user_id' => $data['user'],
'date' => current_time('mysql')
);
update_option('raf_shared_emails', $shared_emails);
}
}
add_action('new_raf_data', 'save_raf_shared_emails', 10, 2);
// Retrieve saved RAF emails
function get_raf_shared_emails() {
return get_option('raf_shared_emails', array());
}
// Optional: Add a shortcode to display saved emails
function display_raf_shared_emails_shortcode() {
$shared_emails = get_raf_shared_emails();
$output = '<ul>';
foreach ($shared_emails as $email_data) {
$output .= '<li>' . esc_html($email_data['email']) . ' - ' . esc_html($email_data['date']) . '</li>';
}
$output .= '</ul>';
return $output;
}
add_shortcode('raf_shared_emails', 'display_raf_shared_emails_shortcode');
- Save the functions.php file.
Usage:
- The code will automatically save shared emails to the WordPress database.
- To retrieve saved emails in your PHP code, use:
$emails = get_raf_shared_emails();
- To display saved emails on a page or post, use the shortcode: [raf_shared_emails]