| Server IP : 13.126.101.145 / Your IP : 216.73.217.37 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/sendusernotifications/ |
Upload File : |
<?php
/*
Plugin Name: Send User Notification Plugin
Description: Send Email/SMS Notification for bulk users
Version: 1.0
Author: Itrosys
*/
function custom_email_admin_menu() {
add_menu_page(
'Send Email to Users',
'Send Email',
'manage_options',
'send-email-users',
'custom_email_admin_page',
'dashicons-email-alt',
100
);
}
add_action('admin_menu', 'custom_email_admin_menu');
function custom_email_admin_page() {
if (isset($_POST['send_email'])) {
custom_send_email_to_users($_POST['user_ids'], $_POST['subject'], $_POST['message']);
}
$users = get_users();
?>
<div class="wrap">
<!-- Bootstrap 5 CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
<!-- Choices.js CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css">
<h1>Send Notification to Users</h1>
<form method="post">
<table class="form-table">
<tr valign="top">
<th scope="row">Select Users</th>
<td>
<select id="multi-select" class="form-select" name="user_ids[]" multiple>
<?php foreach ($users as $user) : ?>
<option value="<?php echo esc_attr($user->ID); ?>"><?php echo esc_html($user->display_name); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Subject</th>
<td>
<input type="text" name="subject" required style="width: 100%;">
</td>
</tr>
<tr valign="top">
<th scope="row">Message</th>
<td>
<textarea name="message" required style="width: 100%;" rows="10"></textarea>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="send_email" class="button-primary" value="Send Email">
<!-- <input type="submit" name="send_sms" class="button-primary" value="Send SMS"> -->
</p>
</form>
</div>
<!-- Bootstrap 5 JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<!-- Choices.js JS -->
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const element = document.getElementById('multi-select');
const choices = new Choices(element, {
removeItemButton: true,
searchEnabled: true,
shouldSort: false,
placeholder: true,
placeholderValue: 'Select an option',
});
});
</script>
<?php
}
function custom_send_email_to_users($user_ids, $subject, $message) {
foreach ($user_ids as $user_id) {
$user = get_userdata($user_id);
if ($user) {
$sendmail = wp_mail($user->user_email, $subject, $message);
if($sendmail ){
echo "Email sent successfully";
}else{
echo "Error Occurs!!!";
}
}else{
echo "User is not available";
}
}
}
function hide_screen_options_for_notification() {
?>
<style>
<?php if (isset($_GET['page']) && ($_GET['page'] === 'send-email-users')) : ?>
#screen-meta-links {
display: none !important;
}
<?php endif; ?>
</style>
<?php
}
add_action('admin_head', 'hide_screen_options_for_notification');