Rename files send-wp-mail

This commit is contained in:
abuyoyo 2024-11-03 23:12:22 +02:00
parent 1f5470e677
commit 36e735ae5a
3 changed files with 355 additions and 355 deletions

View File

@ -1,89 +1,89 @@
#sefa-wrapper h1 { #sefa-wrapper h1 {
font-size: 2.8em; font-size: 2.8em;
font-weight: 200; font-weight: 200;
margin-bottom: 26px; margin-bottom: 26px;
margin-left: -4px; margin-left: -4px;
} }
#sefa-wrapper h1:before { #sefa-wrapper h1:before {
font-family: "dashicons"; font-family: "dashicons";
content: "\f465"; content: "\f465";
top: 8px; top: 8px;
position: relative; position: relative;
margin-right: 10px; margin-right: 10px;
font-size: 1.2em; font-size: 1.2em;
} }
#sefa-wrapper div.error ul li { #sefa-wrapper div.error ul li {
list-style: initial; list-style: initial;
margin-left: 20px; margin-left: 20px;
margin-bottom: 0; margin-bottom: 0;
} }
#sefa-wrapper div.updated { #sefa-wrapper div.updated {
padding: 10px; padding: 10px;
margin-bottom: 5px; margin-bottom: 5px;
} }
#sefa-form .form-table { #sefa-form .form-table {
margin-top: 0; margin-top: 0;
} }
#sefa-form .form-table tr:first-child th { #sefa-form .form-table tr:first-child th {
padding-top: 5px; padding-top: 5px;
} }
#sefa-form .form-table tr:first-child td { #sefa-form .form-table tr:first-child td {
padding-top: 0; padding-top: 0;
} }
#sefa-form .form-table th { #sefa-form .form-table th {
width: auto; width: auto;
min-width: 100px; min-width: 100px;
} }
#sefa-form .form-table td { #sefa-form .form-table td {
vertical-align: text-top; vertical-align: text-top;
} }
#sefa-form .form-table tr:last-child td { #sefa-form .form-table tr:last-child td {
padding: 0 10px; padding: 0 10px;
} }
#sefa-form input[type=text], #sefa-form input[type=text],
#sefa-form input[type=email], #sefa-form input[type=email],
#sefa-form textarea, #sefa-form textarea,
#sefa-form .wp-editor-wrap { #sefa-form .wp-editor-wrap {
width: 100%; width: 100%;
padding: 6px 10px padding: 6px 10px
} }
#sefa-form .sefa-radio-wrap { #sefa-form .sefa-radio-wrap {
display: inline; display: inline;
} }
#sefa-form .wp-editor-wrap { #sefa-form .wp-editor-wrap {
padding-left: 0; padding-left: 0;
} }
#sefa-form #sefa-user-list { #sefa-form #sefa-user-list {
margin-top: 7px; margin-top: 7px;
} }
#sefa-form .note { #sefa-form .note {
font-size: 12px; font-size: 12px;
color: #888; color: #888;
padding: 5px 0 0 1px; padding: 5px 0 0 1px;
} }
@media screen and (max-width: 1300px) { @media screen and (max-width: 1300px) {
#sefa-wrapper { #sefa-wrapper {
width: 100%; width: 100%;
margin-left: 0; margin-left: 0;
} }
} }
@media screen and (max-width: 900px) { @media screen and (max-width: 900px) {
#sefa-form .sefa-radio-wrap { #sefa-form .sefa-radio-wrap {
display: block; display: block;
} }
} }
@media screen and (max-width: 850px) { @media screen and (max-width: 850px) {
#sefa-wrapper .postbox { #sefa-wrapper .postbox {
margin-right: 10px; margin-right: 10px;
} }
} }
@media screen and (max-width: 500px) { @media screen and (max-width: 500px) {
#sefa-wrapper h1 { #sefa-wrapper h1 {
font-size: 2em; font-size: 2em;
margin-left: 0; margin-left: 0;
} }
#sefa-wrapper h1:before { #sefa-wrapper h1:before {
top: 6px; top: 6px;
} }
} }

View File

@ -1,268 +1,268 @@
<?php <?php
/* /*
Plugin Name: Send Email From Admin Plugin Name: Send Email From Admin
Plugin URI: Plugin URI:
Description: Easily send a simple custom email with an attachment from the WordPress administration screen. Tools -> Send Email. Description: Easily send a simple custom email with an attachment from the WordPress administration screen. Tools -> Send Email.
Version: 1.0 Version: 1.0
Author: kojak711 Author: kojak711
Domain Path: /languages Domain Path: /languages
Text Domain: sefa Text Domain: sefa
Send Email From Admin is free software: you can redistribute it and/or modify Send Email From Admin is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Send Email From Admin is distributed in the hope that it will be useful, Send Email From Admin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Send Email From Admin. If not, see <http://www.gnu.org/licenses/>. along with Send Email From Admin. If not, see <http://www.gnu.org/licenses/>.
*/ */
# Exit if accessed directly # Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
define( 'SEFA_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); define( 'SEFA_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'SEFA_PLUGIN_VER', '0.9.3' ); define( 'SEFA_PLUGIN_VER', '0.9.3' );
/** /**
* Add our sub menu in the Tools menu * Add our sub menu in the Tools menu
* *
* @since 0.9.2 * @since 0.9.2
*/ */
function sefa_plugin_add_admin_page() { function sefa_plugin_add_admin_page() {
// create sefa submenu page under the Tools menu // create sefa submenu page under the Tools menu
$sefa_page = add_submenu_page( 'tools.php', 'Send Email From Admin', 'Send Email', 'manage_options', 'sefa_email', 'sefa_plugin_main' ); $sefa_page = add_submenu_page( 'tools.php', 'Send Email From Admin', 'Send Email', 'manage_options', 'sefa_email', 'sefa_plugin_main' );
// load js and css on sefa page only // load js and css on sefa page only
add_action( 'load-' . $sefa_page, 'sefa_plugin_scripts' ); add_action( 'load-' . $sefa_page, 'sefa_plugin_scripts' );
} }
add_action( 'admin_menu', 'sefa_plugin_add_admin_page' ); add_action( 'admin_menu', 'sefa_plugin_add_admin_page' );
/** /**
* Load our css and js. * Load our css and js.
* *
* @since 0.9.2 * @since 0.9.2
*/ */
function sefa_plugin_scripts() { function sefa_plugin_scripts() {
wp_enqueue_style( 'sefa_admin_css', SEFA_PLUGIN_DIR_URL . 'css/sefa.css', '', SEFA_PLUGIN_VER ); wp_enqueue_style( 'sefa_admin_css', SEFA_PLUGIN_DIR_URL . 'css/send-wp-mail.css', '', SEFA_PLUGIN_VER );
wp_enqueue_script( 'sefa_admin_js', SEFA_PLUGIN_DIR_URL . 'js/sefa.js', array('jquery'), SEFA_PLUGIN_VER); wp_enqueue_script( 'sefa_admin_js', SEFA_PLUGIN_DIR_URL . 'js/send-wp-mail.js', array('jquery'), SEFA_PLUGIN_VER);
} }
/** /**
* Register our text domain. * Register our text domain.
* *
* @since 0.9 * @since 0.9
*/ */
function sefa_plugin_load_textdomain() { function sefa_plugin_load_textdomain() {
load_plugin_textdomain( 'sefa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); load_plugin_textdomain( 'sefa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
} }
add_action('plugins_loaded', 'sefa_plugin_load_textdomain'); add_action('plugins_loaded', 'sefa_plugin_load_textdomain');
/** /**
* Our main function to display and process our form * Our main function to display and process our form
* *
* @since 0.9 * @since 0.9
*/ */
function sefa_plugin_main() { function sefa_plugin_main() {
// get site info to construct 'FROM' for email // get site info to construct 'FROM' for email
$from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES );
$from_email = get_bloginfo('admin_email'); $from_email = get_bloginfo('admin_email');
// initialize // initialize
$send_mail_message = false; $send_mail_message = false;
if ( !empty( $_POST ) && check_admin_referer( 'sefa_send_email', 'sefa-form-nonce' ) ) { if ( !empty( $_POST ) && check_admin_referer( 'sefa_send_email', 'sefa-form-nonce' ) ) {
// handle attachment // handle attachment
$attachment_path = ''; $attachment_path = '';
if ( $_FILES ) { if ( $_FILES ) {
if ( !function_exists( 'wp_handle_upload' ) ) { if ( !function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' );
} }
$uploaded_file = $_FILES['attachment']; $uploaded_file = $_FILES['attachment'];
$upload_overrides = array( 'test_form' => false ); $upload_overrides = array( 'test_form' => false );
$attachment = wp_handle_upload( $uploaded_file, $upload_overrides ); $attachment = wp_handle_upload( $uploaded_file, $upload_overrides );
if ( $attachment && !isset( $attachment['error'] ) ) { if ( $attachment && !isset( $attachment['error'] ) ) {
// file was successfully uploaded // file was successfully uploaded
$attachment_path = $attachment['file']; $attachment_path = $attachment['file'];
} else { } else {
// echo $attachment['error']; // echo $attachment['error'];
} }
} }
// get the posted form values // get the posted form values
$sefa_recipient_emails = isset( $_POST['sefa_recipient_emails'] ) ? trim($_POST['sefa_recipient_emails']) : ''; $sefa_recipient_emails = isset( $_POST['sefa_recipient_emails'] ) ? trim($_POST['sefa_recipient_emails']) : '';
$sefa_subject = isset( $_POST['sefa_subject'] ) ? stripslashes(trim($_POST['sefa_subject'])) : ''; $sefa_subject = isset( $_POST['sefa_subject'] ) ? stripslashes(trim($_POST['sefa_subject'])) : '';
$sefa_body = isset( $_POST['sefa_body'] ) ? stripslashes(nl2br($_POST['sefa_body'])) : ''; $sefa_body = isset( $_POST['sefa_body'] ) ? stripslashes(nl2br($_POST['sefa_body'])) : '';
$sefa_group_email = isset( $_POST['sefa_group_email'] ) ? trim($_POST['sefa_group_email']) : 'no'; $sefa_group_email = isset( $_POST['sefa_group_email'] ) ? trim($_POST['sefa_group_email']) : 'no';
$recipients = explode( ',',$sefa_recipient_emails ); $recipients = explode( ',',$sefa_recipient_emails );
// initialize some vars // initialize some vars
$errors = array(); $errors = array();
$valid_email = true; $valid_email = true;
// simple form validation // simple form validation
if ( empty( $sefa_recipient_emails ) ) { if ( empty( $sefa_recipient_emails ) ) {
$errors[] = __( "Please enter an email recipient in the To: field.", 'sefa' ); $errors[] = __( "Please enter an email recipient in the To: field.", 'sefa' );
} else { } else {
// Loop through each email and validate it // Loop through each email and validate it
foreach( $recipients as $recipient ) { foreach( $recipients as $recipient ) {
if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) { if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) {
$valid_email = false; $valid_email = false;
break; break;
} }
} }
// create appropriate error msg // create appropriate error msg
if ( !$valid_email ) { if ( !$valid_email ) {
$errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'sefa' ); $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'sefa' );
} }
} }
if ( empty($sefa_subject) ) $errors[] = __( "Please enter a Subject.", 'sefa' ); if ( empty($sefa_subject) ) $errors[] = __( "Please enter a Subject.", 'sefa' );
if ( empty($sefa_body) ) $errors[] = __( "Please enter a Message.", 'sefa' ); if ( empty($sefa_body) ) $errors[] = __( "Please enter a Message.", 'sefa' );
// send the email if no errors were found // send the email if no errors were found
if ( empty($errors) ) { if ( empty($errors) ) {
$headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n";
$headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n";
$attachments = $attachment_path; $attachments = $attachment_path;
if ( $sefa_group_email === 'yes' ) { if ( $sefa_group_email === 'yes' ) {
if ( wp_mail( $sefa_recipient_emails, $sefa_subject, $sefa_body, $headers, $attachments ) ) { if ( wp_mail( $sefa_recipient_emails, $sefa_subject, $sefa_body, $headers, $attachments ) ) {
$send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'sefa' ) . '</div>'; $send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'sefa' ) . '</div>';
} else { } else {
$send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'sefa' ) . '</div>'; $send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'sefa' ) . '</div>';
} }
} else { } else {
foreach( $recipients as $recipient ) { foreach( $recipients as $recipient ) {
if ( wp_mail( $recipient, $sefa_subject, $sefa_body, $headers, $attachments ) ) { if ( wp_mail( $recipient, $sefa_subject, $sefa_body, $headers, $attachments ) ) {
$send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'sefa' ) . esc_html($recipient) . '!</div>'; $send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'sefa' ) . esc_html($recipient) . '!</div>';
} else { } else {
$send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'sefa' ) . esc_html($recipient) . '</div>'; $send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'sefa' ) . esc_html($recipient) . '</div>';
} }
} }
} }
// delete the uploaded file (attachment) from the server // delete the uploaded file (attachment) from the server
if ( $attachment_path ) { if ( $attachment_path ) {
unlink($attachment_path); unlink($attachment_path);
} }
} }
} }
?> ?>
<div class="wrap" id="sefa-wrapper"> <div class="wrap" id="sefa-wrapper">
<h1><?php _e( 'Send Email From Admin', 'sefa' ); ?></h1> <h1><?php _e( 'Send Email From Admin', 'sefa' ); ?></h1>
<?php <?php
if ( !empty($errors) ) { if ( !empty($errors) ) {
echo '<div class="error"><ul>'; echo '<div class="error"><ul>';
foreach ($errors as $error) { foreach ($errors as $error) {
echo "<li>$error</li>"; echo "<li>$error</li>";
} }
echo "</ul></div>\n"; echo "</ul></div>\n";
} }
if ( $send_mail_message ) { if ( $send_mail_message ) {
echo $send_mail_message; echo $send_mail_message;
} }
?> ?>
<div id="poststuff"> <div id="poststuff">
<div id="post-body" class="metabox-holder columns-2"> <div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content"> <div id="post-body-content">
<form method="POST" id="sefa-form" enctype="multipart/form-data"> <form method="POST" id="sefa-form" enctype="multipart/form-data">
<?php wp_nonce_field( 'sefa_send_email', 'sefa-form-nonce' ); ?> <?php wp_nonce_field( 'sefa_send_email', 'sefa-form-nonce' ); ?>
<table cellpadding="0" border="0" class="form-table"> <table cellpadding="0" border="0" class="form-table">
<tr> <tr>
<th scope=”row”>From:</th> <th scope=”row”>From:</th>
<td><input type="text" disabled value="<?php echo "$from_name &lt;$from_email&gt;"; ?>" required><div class="note"><?php _e( 'These can be changed in Settings->General.', 'sefa' ); ?></div></td> <td><input type="text" disabled value="<?php echo "$from_name &lt;$from_email&gt;"; ?>" required><div class="note"><?php _e( 'These can be changed in Settings->General.', 'sefa' ); ?></div></td>
</tr> </tr>
<tr> <tr>
<th scope=”row”><label for="sefa-recipient-emails">To:</label></th> <th scope=”row”><label for="sefa-recipient-emails">To:</label></th>
<td><input type="email" multiple id="sefa-recipient-emails" name="sefa_recipient_emails" value="<?php echo esc_attr( sefa_plugin_issetor($sefa_recipient_emails) ); ?>" required><div class="note"><?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'sefa' ); ?></div> <td><input type="email" multiple id="sefa-recipient-emails" name="sefa_recipient_emails" value="<?php echo esc_attr( sefa_plugin_issetor($sefa_recipient_emails) ); ?>" required><div class="note"><?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'sefa' ); ?></div>
<select id="sefa-user-list"> <select id="sefa-user-list">
<option value="">-- <?php _e( 'user list', 'sefa' ); ?> --</option> <option value="">-- <?php _e( 'user list', 'sefa' ); ?> --</option>
<?php <?php
$users = get_users( 'orderby=user_email' ); $users = get_users( 'orderby=user_email' );
foreach ( $users as $user ) { foreach ( $users as $user ) {
if ( $user->first_name && $user->last_name ) { if ( $user->first_name && $user->last_name ) {
$user_fullname = ' (' . $user->first_name . ' ' . $user->last_name . ')'; $user_fullname = ' (' . $user->first_name . ' ' . $user->last_name . ')';
} else { } else {
$user_fullname = ''; $user_fullname = '';
} }
echo '<option value="' . esc_html( $user->user_email ) . '">' . esc_html( $user->user_email ) . esc_html( $user_fullname) . '</option>'; echo '<option value="' . esc_html( $user->user_email ) . '">' . esc_html( $user->user_email ) . esc_html( $user_fullname) . '</option>';
}; };
?> ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope=”row”></th> <th scope=”row”></th>
<td> <td>
<div class="sefa-radio-wrap"> <div class="sefa-radio-wrap">
<input type="radio" class="radio" name="sefa_group_email" value="no" id="no"<?php if ( isset($sefa_group_email) && $sefa_group_email === 'no' ) echo ' checked'; ?> required> <input type="radio" class="radio" name="sefa_group_email" value="no" id="no"<?php if ( isset($sefa_group_email) && $sefa_group_email === 'no' ) echo ' checked'; ?> required>
<label for="no"><?php _e( 'Send each recipient an individual email', 'sefa' ); ?></label> <label for="no"><?php _e( 'Send each recipient an individual email', 'sefa' ); ?></label>
</div> </div>
&nbsp;&nbsp; &nbsp;&nbsp;
<div class="sefa-radio-wrap"> <div class="sefa-radio-wrap">
<input type="radio" class="radio" name="sefa_group_email" value="yes" id="yes"<?php if ( isset($sefa_group_email) && $sefa_group_email === 'yes' ) echo ' checked'; ?> required> <input type="radio" class="radio" name="sefa_group_email" value="yes" id="yes"<?php if ( isset($sefa_group_email) && $sefa_group_email === 'yes' ) echo ' checked'; ?> required>
<label for="yes"><?php _e( 'Send a group email to all recipients', 'sefa' ); ?></label> <label for="yes"><?php _e( 'Send a group email to all recipients', 'sefa' ); ?></label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope=”row”><label for="sefa-subject">Subject:</label></th> <th scope=”row”><label for="sefa-subject">Subject:</label></th>
<td><input type="text" id="sefa-subject" name="sefa_subject" value="<?php echo esc_attr( sefa_plugin_issetor($sefa_subject) );?>" required></td> <td><input type="text" id="sefa-subject" name="sefa_subject" value="<?php echo esc_attr( sefa_plugin_issetor($sefa_subject) );?>" required></td>
</tr> </tr>
<tr> <tr>
<th scope=”row”><label for="sefa_body">Message:</label></th> <th scope=”row”><label for="sefa_body">Message:</label></th>
<td align="left"> <td align="left">
<?php <?php
$settings = array( "editor_height" => "200" ); $settings = array( "editor_height" => "200" );
wp_editor( sefa_plugin_issetor($sefa_body), "sefa_body", $settings ); wp_editor( sefa_plugin_issetor($sefa_body), "sefa_body", $settings );
?> ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope=”row”><label for="attachment">Attachment:</label></th> <th scope=”row”><label for="attachment">Attachment:</label></th>
<td><input type="file" id="attachment" name="attachment"></td> <td><input type="file" id="attachment" name="attachment"></td>
</tr> </tr>
<tr> <tr>
<td colspan="2" align="right"> <td colspan="2" align="right">
<input type="submit" value="<?php _e( 'Send Email', 'sefa' ); ?>" name="submit" class="button button-primary"> <input type="submit" value="<?php _e( 'Send Email', 'sefa' ); ?>" name="submit" class="button button-primary">
</td> </td>
</tr> </tr>
</table> </table>
</form> </form>
</div> </div>
<div id="postbox-container-1" class="postbox-container"> <div id="postbox-container-1" class="postbox-container">
<div class="postbox"> <div class="postbox">
<h3><span>Like this plugin?</span></h3> <h3><span>Like this plugin?</span></h3>
<div class="inside"> <div class="inside">
<ul> <ul>
<li><a href="https://wordpress.org/support/view/plugin-reviews/send-email-from-admin?filter=5" target="_blank">Rate it on WordPress.org</a></li> <li><a href="https://wordpress.org/support/view/plugin-reviews/send-email-from-admin?filter=5" target="_blank">Rate it on WordPress.org</a></li>
<li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=8HHLL6WRX9Z68" target="_blank">Donate to the developer</a></li> <li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=8HHLL6WRX9Z68" target="_blank">Donate to the developer</a></li>
</ul> </ul>
</div> <!-- .inside --> </div> <!-- .inside -->
</div> </div>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</div> </div>
</div> </div>
<?php <?php
} }
/** /**
* Helper function for form values * Helper function for form values
* *
* @since 0.9 * @since 0.9
* *
* @param string $var Var name to test isset * @param string $var Var name to test isset
* *
* @return string $var value if isset or '' * @return string $var value if isset or ''
*/ */
function sefa_plugin_issetor(&$var) { function sefa_plugin_issetor(&$var) {
return isset($var) ? $var : ''; return isset($var) ? $var : '';
} }