Skip to content

Commit

Permalink
removed output buffering while loading comments to improve perceived …
Browse files Browse the repository at this point in the history
…response. hide comment display option for administrator if comment replies are disabled. check user permission before allowing Reply with Quick Mail in case site option changed. change tabindex on mail form textarea, if replying to comment. standardized wp_die message style.
  • Loading branch information
mitchelldmiller committed Jul 9, 2017
1 parent 3f9f3c0 commit 819f636
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
quick-mail-wp-plugin
====================

Send text or html email with attachments from user's credentials. Select recipient from users or commenters. Russian, French, Spanish translations.
Send text or html email with attachments and shortcodes. Send private replies to comments. Select recipient from users or commenters. French, Russian, Spanish translations.

### WordPress Rating
[![WordPress rating](https://img.shields.io/wordpress/plugin/r/quick-mail.svg?maxAge=2592000)]()
Expand Down
4 changes: 2 additions & 2 deletions index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Quick Mail 3.1.3 Beta
Quick Mail 3.1.6 RC1
====================

Send text or html email with attachments from user's credentials. Select recipient from users or commenters.
Send text or html email with attachments and shortcodes. Send private replies to comments. Select recipient from users or commenters. French, Russian, Spanish translations.

Description
-----------
Expand Down
18 changes: 16 additions & 2 deletions quick-mail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Welcome to quick-mail.js 3.1.4
// Welcome to quick-mail.js 3.1.6

/**
* set local storage
Expand Down Expand Up @@ -501,9 +501,14 @@ jQuery(document).ready(function() {
{
return;
} // do not load if not on Quick Mail form

if (jQuery('#quick_mail_cannot_reply').prop('checked')) {
jQuery('#show_commenters_row').hide();
} else {
jQuery('#show_commenters_row').show();
} // hide show commenters if admin disabled comment replies

update_saved_cc_addresses();

jQuery('#qm-invalid').val('0');
jQuery("#qm-submit").prop('disabled', false);
if (jQuery('#qm-email').length) {
Expand All @@ -524,6 +529,15 @@ jQuery(document).ready(function() {
});
} // end if

// 3.1.6 hide show commenters on admin, if admin disabled replies
jQuery('#quick_mail_cannot_reply').click(function() {
if (jQuery('#quick_mail_cannot_reply').prop('checked')) {
jQuery('#show_commenters_row').hide();
} else {
jQuery('#show_commenters_row').show();
}
});

jQuery('#qm-first').click(function() {
clear_qm_msgs();
});
Expand Down
86 changes: 46 additions & 40 deletions quick-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: Quick Mail
Description: Send text or html email with attachments from user's credentials. Select recipient from users or commenters.
Version: 3.1.5 Beta
Version: 3.1.6 RC1
Author: Mitchell D. Miller
Author URI: https://wheredidmybraingo.com/
Plugin URI: https://wheredidmybraingo.com/reply-wordpress-comments-quick-mail/
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function get_qm_comment_help_tab() {
} // end get_qm_comment_help_tab

/**
* get user role
* get user role.
* @return string lowercase role. author, editor, administrator, n/a
* @since 3.1.0
*/
Expand Down Expand Up @@ -212,9 +212,9 @@ public function multiple_matching_users($code, $blog) {
} // end multiple_matching_users

/**
* content type filter for wp_mail
* content type filter for wp_mail.
*
* filters wp_mail_content_type
* filters wp_mail_content_type.
*
* @see wp_mail
* @param string $type
Expand All @@ -232,7 +232,7 @@ public function get_mail_content_type($type)
*/
public function __construct() {
/**
* if not called by WordPress, exit without error message
* if not called by WordPress, exit without error message.
* @since 1.2.5
*/
if ( ! function_exists( 'register_activation_hook' ) ) {
Expand Down Expand Up @@ -274,7 +274,7 @@ public function show_qm_pointer() {
} // end show_qm_pointer

/**
* displays wp_mail error message
* displays wp_mail error message.
*
* @param WP_Error $e
* @since 1.3.0
Expand All @@ -283,13 +283,13 @@ public function show_mail_failure($e) {
if ( is_wp_error( $e ) ) {
$direction = is_rtl() ? 'rtl' : 'ltr';
$args = array( 'response' => 200, 'back_link' => true, 'text_direction' => $direction );
wp_die( sprintf( '<h3 role="alert">%s</h3>', $e->get_error_message() ), __( 'Mail Error', 'quick-mail' ), $args );
}
}
wp_die( sprintf( '<h1 role="alert">%s</h1>', $e->get_error_message() ), __( 'Mail Error', 'quick-mail' ), $args );
} // end if error
} // end show_mail_failure

/**
* Check for minimum WordPress version before installation.
* Note: `quick_mail_version` filter was removed in 1.3.0
* Note: `quick_mail_version` filter was removed in 1.3.0.
*
* @link http://wheredidmybraingo.com/quick-mail-1-3-0-supports-international-mail/#minversion
*
Expand All @@ -307,7 +307,7 @@ public function check_wp_version()
} // end check_wp_version

/**
* add options when Quick Mail is activated
* add options when Quick Mail is activated.
*
* add options, do not autoload them.
*
Expand All @@ -334,7 +334,7 @@ public function install_quick_mail() {
} // install_quick_mail

/**
* load scripts to display wp_pointer after installation
* load scripts to display wp_pointer after installation.
*
* @since 1.3.0
*/
Expand Down Expand Up @@ -431,7 +431,7 @@ public function add_email_scripts()
* @return void displays input
*/
public function quick_mail_recipient_input( $to, $id ) {
$template = '<input aria-labelledby="qme_label" value="%s" id="qm-email" name="qm-email" type="email" required aria-required="true" tabindex="1" autofocus size="35" placeholder="%s">';
$template = '<input aria-labelledby="qme_label" value="%s" id="qm-email" name="qm-email" type="email" required aria-required="true" tabindex="0" autofocus size="35" placeholder="%s">';
$blog = is_multisite() ? get_current_blog_id() : 0;
$option = $this->qm_get_display_option( $blog );
$you = wp_get_current_user(); // from
Expand Down Expand Up @@ -497,7 +497,7 @@ public function quick_mail_recipient_input( $to, $id ) {
sort( $users );
$letter = '';
ob_start();
echo '<select aria-labelledby="qme_label" name="qm-email" id="qm-primary" required aria-required="true" size="1" tabindex="1" autofocus onchange="return is_qm_email_dup()"><option class="qmopt" value="" selected>Select</option>';
echo '<select aria-labelledby="qme_label" name="qm-email" id="qm-primary" required aria-required="true" size="1" tabindex="0" autofocus onchange="return is_qm_email_dup()"><option class="qmopt" value="" selected>Select</option>';
for ( $i = 0; $i < $j; $i++ ) {
$row = explode( "\t", $users[$i] );
if ($option == 'A') {
Expand Down Expand Up @@ -646,8 +646,8 @@ public function get_commenters() {
if (empty( $cquery ) ) {
return $problem;
} // end if no recent comments
ob_start();
echo '<select aria-labelledby="qme_label" name="qm-email" id="qm-primary" required aria-required="true" size="1" tabindex="1" autofocus onchange="return qm_get_comment()"><option class="qmopt" value="" selected>Select</option>';

$select = '<select aria-labelledby="qme_label" name="qm-email" id="qm-primary" required aria-required="true" size="1" tabindex="0" autofocus onchange="return qm_get_comment()"><option class="qmopt" value="" selected>Select</option>';
$matches = 0;
foreach ( $cquery as $comment ) {
if ( empty( $comment->comment_author ) || empty( $comment->comment_author_email ) ) {
Expand All @@ -674,11 +674,10 @@ public function get_commenters() {
$title = mb_substr( $title, 0, $maxlen -1, 'UTF-8' ) . '&hellip;';
} // end if long title
$address = urlencode( "\"{$comment->comment_author}\" <{$comment->comment_author_email}>" );
echo "\r\n<option {$attributes} value='{$address}' class='qmopt'>{$comment->comment_author} &nbsp; ({$title})</option>";
$select .= "\r\n<option {$attributes} value='{$address}' class='qmopt'>{$comment->comment_author} &nbsp; ({$title})</option>";
$matches++;
} // end foreach
echo '</select>';
$select = ob_get_clean();
$select .= '</select>';
return ($matches > 0) ? $select : $problem;
} // end get_commenters

Expand Down Expand Up @@ -818,7 +817,7 @@ function qm_get_comment() {
/**
* display data entry form to enter recipient, cc, subject, message.
*
* modified form if replying to comment.
* alternate form if replying to comment.
*
*/
public function quick_mail_form() {
Expand All @@ -842,7 +841,11 @@ public function quick_mail_form() {

$you = wp_get_current_user();
if ( !empty( $_REQUEST['comment_id'] ) ) {
// check for permission
if ( !$this->user_can_reply_to_comments() ) {
$direction = is_rtl() ? 'rtl' : 'ltr';
$args = array('response' => 200, 'back_link' => true, 'text_direction' => $direction);
wp_die( sprintf( '<h1 role="alert">%s</h1>', __( 'Comments disabled by system administrator.', 'quick-mail' ) ), __( 'Mail Error', 'quick-mail' ), $args );
} // end if check user has permission to reply

$id = intval( $_REQUEST['comment_id'] );
$info = get_comment( $id, ARRAY_A );
Expand Down Expand Up @@ -881,7 +884,7 @@ public function quick_mail_form() {
$success = '';
$from = '';
$attachments = array();
$commenter_list = (empty( $commenter ) && $this->user_wants_comments() ) ? $this->get_commenters() : null;
$commenter_list = (empty( $commenter ) && $this->user_can_reply_to_comments() ) ? $this->get_commenters() : null;
if ( is_wp_error( $commenter_list ) ) {
$error = $commenter_list->get_error_message();
} elseif ( is_string( $commenter_list ) ) {
Expand Down Expand Up @@ -912,12 +915,12 @@ public function quick_mail_form() {

if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
if ( ! wp_verify_nonce( $_POST['qm205'], 'qm205' ) ) {
wp_die( '<h2>' . __( 'Login Expired. Refresh Page.', 'quick-mail' ). '</h2>' );
wp_die( '<h1 role="alert">' . __( 'Login Expired. Refresh Page.', 'quick-mail' ). '</h1>' );
}
if ( empty( $commenter ) && empty( $_POST['qm-email'] ) ) {
$direction = is_rtl() ? 'rtl' : 'ltr';
$args = array('response' => 200, 'back_link' => true, 'text_direction' => $direction);
wp_die( sprintf( '<h3>%s</h3>', __( 'Invalid mail address', 'quick-mail' ) ), __( 'Mail Error', 'quick-mail' ), $args );
wp_die( sprintf( '<h1 role="alert">%s</h1>', __( 'Invalid mail address', 'quick-mail' ) ), __( 'Mail Error', 'quick-mail' ), $args );
} // end if user circumvented Javascript

$rec_type = empty($_POST['qm_bcc']) ? 'Cc' : 'Bcc';
Expand Down Expand Up @@ -1090,7 +1093,6 @@ public function quick_mail_form() {
} // end if no error
} // end if POST

ob_start();
$orig_link = plugins_url( '/qm_validate.php', __FILE__ );
$site = untrailingslashit( network_site_url( '/' ) );
$link = str_replace( $site, '', $orig_link );
Expand Down Expand Up @@ -1149,6 +1151,7 @@ public function quick_mail_form() {
$to_label = ( empty( $commenter ) || empty( $commenter_list ) ) ? __( 'To', 'quick-mail' ) : __( 'Commenters', 'quick-mail' );
$msg_label = ( empty( $commenter ) || empty( $commenter_list ) ) ? __( 'Message', 'quick-mail' ) : __( 'Reply', 'quick-mail' );
$save_address = ( empty( $commenter ) || empty( $commenter_list ) ) ? '<input type="hidden" id="qm-saving" value="1">' : '<input type="hidden" id="qm-saving" value="">';
$message_tabindex = (is_string($commenter_list) && empty($commenter_list) ) ? 50 : 1;
?>
<label id="tf_label" for="the_from" class="recipients"><?php _e( 'From', 'quick-mail' ); ?></label>
<p><?php echo $save_address; ?><input aria-labelledby="tf_label" <?php echo $tsize; ?> value="<?php echo $the_from; ?>" readonly aria-readonly="true" id="the_from" tabindex="5000"></p>
Expand All @@ -1164,8 +1167,8 @@ public function quick_mail_form() {
$crecipient = $commenter_list;
} else {
$crecipient = "<input aria-labelledby='qme_label' value='{$to}'
id='qm-email' name='qm-email' type='email' required aria-required='true' tabindex='1'
readonly autofocus size='35'>";
id='qm-email' name='qm-email' type='email' required aria-required='true' tabindex='6000'
readonly size='35'>";
} // end if
?>
<p><?php echo $crecipient; ?></p>
Expand Down Expand Up @@ -1232,12 +1235,14 @@ public function quick_mail_form() {
<p><textarea id="quickmailmessage" name="quickmailmessage"
placeholder="<?php _e( 'Enter your message', 'quick-mail' ); ?>"
aria-labelledby="qm_msg_label" required aria-required="true" aria-multiline=”true”
rows="8" cols="60" tabindex="50"><?php echo htmlspecialchars( $raw_msg, ENT_QUOTES ); ?></textarea></p>
rows="8" cols="60" tabindex="<?php echo $message_tabindex; ?>"><?php echo htmlspecialchars( $raw_msg, ENT_QUOTES ); ?></textarea></p>
<?php
} else {
$editor_id = 'quickmailmessage';
$settings = array('textarea_rows' => 8, 'tabindex' => 50 );
wp_editor( $raw_msg, $editor_id, $settings);
$settings = array('textarea_rows' => 8, 'tabindex' => $message_tabindex );
if (is_string($commenter_list) && !empty($commenter_list) ) {
$settings['tabindex'] = 1;
} // end if replying to comment
wp_editor( $raw_msg, 'quickmailmessage', $settings);
} // end if
?>
</fieldset>
Expand All @@ -1248,7 +1253,6 @@ public function quick_mail_form() {
</form>
<?php endif; ?>
<?php
echo ob_get_clean();
} // end quick_mail_form

/**
Expand Down Expand Up @@ -1409,7 +1413,7 @@ public function quick_mail_options() {
} // end for

$check_wpautop = ( '1' == get_user_meta( $you->ID, 'qm_wpautop', true ) ) ? 'checked="checked"' : '';
$check_commenters = $this->user_wants_comments() ? 'checked="checked"' : '';
$check_commenters = $this->user_can_reply_to_comments() ? 'checked="checked"' : '';
$check_all = ( 'A' == $this->qm_get_display_option( $blog ) ) ? 'checked="checked"' : '';
$check_names = ( 'N' == $this->qm_get_display_option( $blog ) ) ? 'checked="checked"' : '';
$check_none = ( 'X' == $this->qm_get_display_option( $blog ) ) ? 'checked="checked"' : '';
Expand Down Expand Up @@ -1514,7 +1518,7 @@ public function quick_mail_options() {
<?php if ( empty( $comment_label ) ) : ?>
<input type="hidden" name="show_quick_mail_commenters" value="N">
<?php else : ?>
<p><input aria-describedby="qm_commenter_desc" aria-labelledby="qm_commenter_label" id="show_quick_mail_commenters" class="qm-input" name="show_quick_mail_commenters"
<p id="show_commenters_row"><input aria-describedby="qm_commenter_desc" aria-labelledby="qm_commenter_label" id="show_quick_mail_commenters" class="qm-input" name="show_quick_mail_commenters"
type="checkbox" value="Y" <?php echo $check_commenters; ?>>
<label id="qm_commenter_label" for="show_quick_mail_commenters" class="qm-label"><?php echo $comment_label; ?></label>
<span id="qm_commenter_desc" class="qm-label"><?php _e( 'Send private replies to comments.', 'quick-mail' ); ?></span></p>
Expand Down Expand Up @@ -1594,7 +1598,9 @@ public function quick_mail_options() {
?>
<?php endif; ?>
<input name="showing_quick_mail_admin" type="hidden" value="Y"></p>
<p><input aria-describedby="quick_mail_cannot_reply_desc" aria-labelledby="quick_mail_cannot_reply_label" class="qm-input" name="quick_mail_cannot_reply" type="checkbox" <?php echo $check_cannot_reply; ?>>
<p><input aria-describedby="quick_mail_cannot_reply_desc" id="quick_mail_cannot_reply"
aria-labelledby="quick_mail_cannot_reply_label" class="qm-input"
name="quick_mail_cannot_reply" type="checkbox" <?php echo $check_cannot_reply; ?>>
<label id="quick_mail_cannot_reply_label" class="qm-label"><?php _e( 'Disable Replies to Comments', 'quick-mail' ); ?>.</label>
<span id="quick_mail_cannot_reply_desc" class="qm-label"><?php _e( 'Users will not see commenter list.', 'quick-mail' ); ?></span></p>
<p id="qm-authors"><input aria-describedby="qm_author_desc" aria-labelledby="qm_author_label" class="qm-input" name="authors_quick_mail_privilege" type="checkbox" <?php echo $check_author; ?>>
Expand Down Expand Up @@ -1710,7 +1716,7 @@ protected function qm_admin_count( $blog ) {
* @since 3.1.0
*/
public function qm_comment_reply($text, $id) {
if ( !$this->user_wants_comments() ) {
if ( !$this->user_can_reply_to_comments() ) {
return $text;
} // end if no comments for this user

Expand All @@ -1736,7 +1742,7 @@ public function qm_filter_comment_link($actions, $comment) {
return $actions;
} // end if invalid author email

if ( !$this->user_wants_comments() ) {
if ( !$this->user_can_reply_to_comments() ) {
return $actions;
} // end if user wants comments

Expand Down Expand Up @@ -1890,7 +1896,7 @@ public function add_qm_settings_help() {
$dc5 = "<dd>{$dc_see} {$dc_enabled} {$dc_info}</dd>{$rc5}";
} // end if admin
$dcontent = "<dl><dt><strong>{$dc_title}</strong></dt>{$dc1}{$dc2}{$dc3}{$dc4}{$dc_val}{$dc5}</dl>";
if ( $this->user_wants_comments() ) {
if ( $this->user_can_reply_to_comments() ) {
$screen->add_help_tab( array('id' => 'qm_commenter_help', 'title' => $dc_title, 'content' => $dcontent) );
} // add comment help, if user can reply to comments

Expand Down Expand Up @@ -1943,7 +1949,7 @@ public function add_qm_settings_help() {
* @return boolean if user can reply to comments.
* @since 3.1.5
*/
function user_wants_comments() {
function user_can_reply_to_comments() {
$blog = is_multisite() ? get_current_blog_id() : 0;
$cannot_reply = '';
if ( is_multisite() ) {
Expand All @@ -1969,7 +1975,7 @@ function user_wants_comments() {
} // end if user does not want comments

return true;
} // end user_wants_comments
} // end user_can_reply_to_comments

/**
* Quick Mail general help
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Stable tag: 3.0.4
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html

Send text or html email with attachments from user's credentials. Select recipient from users or commenters.
Send text or html email with attachments and shortcodes. Send private replies to comments. Select recipient from users or commenters.

== Description ==

Expand Down

0 comments on commit 819f636

Please sign in to comment.