-
Notifications
You must be signed in to change notification settings - Fork 8
/
quick-mail.php
3301 lines (3046 loc) · 127 KB
/
quick-mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Quick Mail
* Description: Send emails with attachments and shortcodes from WP dashboard. Reply privately to comments. Select recipients from users or commenters. Compatible with Multisite. Does not use Gutenberg or REST API. Includes a powerful WP-CLI command for command-line operations.
* Version: 4.1.9
* Author: Mitchell D. Miller
* Author URI: https://mitchelldmiller.com/
* Update URI: https://github.com/mitchelldmiller/quick-mail-wp-plugin/releases/latest
* Plugin URI: https://mitchelldmiller.github.io/quick-mail-wp-plugin/
* GitHub Plugin URI: https://github.com/mitchelldmiller/quick-mail-wp-plugin
* Text Domain: quick-mail
* Domain Path: /lang
* License: MIT
* License URI: https://github.com/mitchelldmiller/quick-mail-wp-plugin/blob/master/LICENSE
*
* @package QuickMail
*/
/*
* Quick Mail WordPress Plugin - Send email from WordPress using Quick Mail
*
* Copyright (C) 2014-2024 Mitchell D. Miller
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
require_once 'inc/class-quickmailutil.php';
require_once 'inc/class-quickmailsender.php';
// Load our WP-CLI command, if needed.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once dirname( __FILE__ ) . '/inc/class-quick-mail-command.php';
}
/**
*
* Send email, reply to comments from WP Dashboard.
*/
class QuickMail {
/**
* Our version. Used by enqueue script / style.
*
* @var string version
* @since 3.5.5 10-3-19
*/
const VERSION = '4.1.9';
/**
* Current directory for Quick Mail helper plugins.
*
* Replaces QuickMail::$directory
*
* @var string current directory.
* @since 4.0.5 1-8-21
*/
const DIRECTORY = __DIR__ . '/';
/**
* Content type for our instance.
*
* @since 1.2.0
* @var string (text|html)
*/
public $content_type = 'text/html';
/**
* Our directory for Quick Mail helper plugins.
*
* @var string directory name
* @deprecated 4.0.5 QuickMail::DIRECTORY
* @see QuickMail::DIRECTORY for replacement.
*/
public $directory = '';
/**
* Your character set for multibyte functions.
*
* @var string $charset default UTF-8
*/
public $charset = 'UTF-8';
/**
* Local function used to filter replace_quick_mail_sender
*
* @var string filter name
* @since 3.3.1
*/
public $filter_sender = '';
/**
* Local function used to filter quick mail sender
*
* @var string filter name
* @since 3.3.3
*/
public $filter_name = '';
/**
* Static property for our instance.
*
* @since 1.0.0
* @var (boolean|object) $instance
*/
public static $instance = false;
/**
* Our dismissed pointer name.
*
* @var string
* @since 1.3.0
*/
public static $pointer_name = 'quickmail_320';
/**
* Returns an instance.
*
* If an instance exists, return it. If not, create one and return it.
*
* @since 1.0.0
*
* @return object instance of class
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
} // end get_instance
/**
* Initialize class for WordPress.
*
* @return QuickMail
* @since 4.0.6
*/
public static function init() {
if ( ! function_exists( 'register_activation_hook' ) ) {
exit;
}
$qm = new self();
$qm->directory = plugin_dir_path( __FILE__ );
$qm->charset = is_multisite() ? get_blog_option( get_current_blog_id(), 'blog_charset', 'UTF-8' ) : get_option( 'blog_charset', 'UTF-8' );
register_activation_hook( __FILE__, array( $qm, 'check_wp_version' ) );
add_action( 'activated_plugin', array( $qm, 'install_quick_mail' ), 10, 2 );
add_action( 'admin_footer', array( $qm, 'qm_get_comment_script' ) );
add_action( 'admin_footer', array( $qm, 'qm_get_title_script' ) );
add_action( 'admin_enqueue_scripts', array( $qm, 'add_email_scripts' ), 10, 0 );
add_action( 'admin_menu', array( $qm, 'init_quick_mail_menu' ) );
add_action( 'deactivated_plugin', array( $qm, 'deactivate_quick_mail_plugin' ), 10, 2 );
add_action( 'load-tools_page_quick_mail_form', array( $qm, 'add_qm_help' ), 20, 0 );
add_action( 'plugins_loaded', array( $qm, 'init_quick_mail_translation' ) );
add_action( 'plugins_loaded', array( $qm, 'show_qm_pointer' ), 10, 0 );
add_action( 'wp_ajax_qm_get_comment', array( $qm, 'qm_get_comment' ) );
add_action( 'wp_ajax_qm_get_title', array( $qm, 'qm_get_title' ) );
add_action( 'wp_ajax_nopriv_quick_mail_banned', array( $qm, 'quick_mail_banned' ) );
add_action( 'wp_ajax_quick_mail_banned', array( $qm, 'quick_mail_banned' ) );
add_filter( 'comment_row_actions', array( $qm, 'qm_filter_comment_link' ), 10, 2 );
add_filter( 'comment_notification_text', array( $qm, 'qm_comment_reply' ), 10, 2 );
add_filter( 'plugin_action_links', array( $qm, 'qm_action_links' ), 10, 2 );
add_filter( 'plugin_row_meta', array( $qm, 'qm_plugin_links' ), 10, 2 );
add_filter( 'quick_mail_setup_capability', array( $qm, 'let_editor_set_quick_mail_option' ) );
return $qm;
}
/**
* Not used since 4.0.6.
*
* @since 1.2.0
*/
public function __construct() {
} // end constructor
/**
* Get info for basic help tab.
*
* @return array args for WP_Screen::add_help_tab(array $args)
*/
public static function get_qm_help_tab() {
$qm_desc = __( 'Quick Mail is the easiest way to send email with attachments to WordPress users on your site, or send private replies to comments.', 'quick-mail' );
$want_privacy = get_user_option( 'want_quick_mail_privacy', get_current_user_id() );
if ( 'N' !== $want_privacy ) {
$want_privacy = 'Y';
} // end if not set
if ( 'Y' === $want_privacy ) {
$qm_desc = sprintf(
"<h3 class='wp-ui-text-highlight'>%s</h3>",
__( 'Please grant permission to use your mail address.', 'quick-mail' )
);
} // end if
$github = __( 'Follow development on Github', 'quick-mail' );
$glink = "<a target='_blank' href='https://github.com/mitchelldmiller/quick-mail-wp-plugin/'>{$github}</a>.";
$faq = __( 'FAQ', 'quick-mail' );
$flink = '<a href="https://mitchelldmiller.github.io/quick-mail-wp-plugin/#frequently-asked-questions" target="_blank">' . $faq . '</a>';
$slink = '<a href="https://github.com/mitchelldmiller/quick-mail-wp-plugin/issues" target="_blank">' . __( 'Github Issues', 'quick-mail' ) . '</a>';
$resources = __( 'Resources', 'quick-mail' );
$more_info = __( 'has more information.', 'quick-mail' );
$use_str = __( 'Please use', 'quick-mail' );
$to_ask = __( 'to ask questions and report problems.', 'quick-mail' );
$qm_top = "<p>{$qm_desc}</p><h4>{$resources}</h4><ul><li>{$flink} {$more_info}</li><li>{$glink}</li><li>{$use_str} {$slink} {$to_ask}</li></ul>";
$qm_content = $qm_top;
return array(
'id' => 'qm_intro',
'title' => __( 'Quick Mail', 'quick-mail' ),
'content' => $qm_content,
);
} // end get_qm_help_tab
/**
* Get help for comment reply.
*
* @since 3.1.3
* @return array args for WP_Screen::add_help_tab(array $args)
*/
public static function get_qm_comment_help_tab() {
$help = sprintf(
'<dl><dt class="qm-help">%s</dt>
<dd>%s</dd><dd>%s</dd></dl>',
__( 'Send private replies to comments.', 'quick-mail' ),
__( 'Select a commenter to send a message.', 'quick-mail' ),
__( 'Subject and message are added automatically.', 'quick-mail' )
);
$support = sprintf(
'<h4><a class="wp-ui-text-highlight" target="_blank"
href="%s">%s</a></h4>',
'https://github.com/mitchelldmiller/quick-mail-wp-plugin/issues',
__( 'Please use Github Issues to ask questions and report problems.', 'quick-mail' )
);
return array(
'id' => 'qm_chelp',
'title' => __( 'Reply to Comments', 'quick-mail' ),
'content' => $help . $support,
);
} // end get_qm_comment_help_tab
/**
* Got Banned Domains? Used for invalid message.
*
* @return boolean
* @since 4.0.5
*/
public static function got_banned_domains() {
$banning = '';
if ( is_multisite() ) {
$banning = get_blog_option( null, 'quick_mail_banned', '' );
} else {
$banning = get_option( 'quick_mail_banned', '' );
}
return ( ! empty( $banning ) );
}
/**
* Is this domain banned? Static for WP-CLI.
*
* @param string $domain domain name.
* @return boolean
* @since 4.0.5
*/
public static function is_banned_domain( $domain ) {
$option = '';
if ( is_multisite() ) {
$option = get_blog_option( null, 'quick_mail_banned', '' );
} else {
$option = get_option( 'quick_mail_banned', '' );
} // end if multisite
$banned = explode( ' ', $option );
foreach ( $banned as $one ) {
if ( ! empty( $one ) && stristr( $domain, $one ) ) {
$domain = '';
break;
}
}
if ( empty( $domain ) ) {
return true;
}
return false;
}
/**
* Validate banned domains before adding them.
*
* @param string $entry User entry.
* @return string Validated domain list.
* @since 4.0.5
*/
public static function validate_banned_domains( $entry ) {
$option = '';
if ( is_multisite() ) {
$option = get_blog_option( null, 'quick_mail_banned', '' );
} else {
$option = get_option( 'quick_mail_banned', '' );
} // end if multisite
$previous = explode( ' ', $option );
$current = array_unique( explode( ' ', $entry ) );
$processed = '';
foreach ( $current as $one ) {
if (empty($one)) {
continue;
}
if ( is_string( strstr( $one, '@' ) ) ) {
$a_split = explode( '@', $one );
if ( 2 === count( $a_split ) ) {
$one = $a_split[1];
}
}
$a_split = explode( '.', $one );
$j = count( $a_split );
if ( $j > 2 ) {
$one = $a_split[ $j - 2 ] . '.' . $a_split[ $j - 1 ];
} // Remove subdomains.
if ( function_exists( 'idn_to_ascii' ) ) {
$intl = defined( 'INTL_IDNA_VARIANT_UTS46' ) && defined( 'IDNA_NONTRANSITIONAL_TO_ASCII' ) ? idn_to_ascii( $one[1], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46 ) : idn_to_ascii( $one );
if ( ! empty( $intl ) && 4 < strlen( $intl ) && 'xn--' === substr( $intl, 0, 4 ) ) {
$one = $intl;
} // end if we have punycode address.
} // end if we have idn_to_ascii
if ( ( ! strstr( $processed, $one ) ) && ( in_array( $one, $previous, true ) || checkdnsrr( $one, 'MX' ) ) ) {
$processed .= "{$one} ";
}
}
return trim( $processed );
}
/**
* Get count of banned domains.
*
* @return integer
* @since 4.0.5
*/
public function get_banned_count() {
if ( is_multisite() ) {
$banned = get_blog_option( get_current_blog_id(), 'quick_mail_banned', '' );
} else {
$banned = get_option( 'quick_mail_banned', '' );
}
$a = explode( ' ', $banned );
return empty( $banned ) ? 0 : count( $a );
}
/**
* Processes quick_mail_banned action to reject banned domains.
*
* @since 4.0.5
*/
public function quick_mail_banned() {
$domain = isset( $_POST['domain'] ) ? sanitize_text_field( $_POST['domain'] ) : '';
$hash = password_hash( $domain, PASSWORD_DEFAULT );
$maybe = password_verify( $domain, $hash );
if ( empty( $domain ) || empty( $maybe ) ) {
http_response_code( 204 );
exit;
}
if ( $this->get_banned_count() ) {
$retval = self::is_banned_domain( $domain ) ? '' : $domain;
} else {
$retval = $domain; // No banned domains.
}
wp_die( $retval );
}
/**
* Get user role.
*
* @return string lowercase role. author, editor, administrator, n/a
* @since 3.1.0
*/
public function qm_get_role() {
if ( current_user_can( 'activate_plugins' ) ) {
return 'administrator';
} // end if administrator
if ( current_user_can( 'delete_others_pages' ) ) {
return 'editor';
} // end if editor
if ( current_user_can( 'publish_posts' ) ) {
return 'author';
} // end if author
return 'n/a';
} // end qm_get_role
/**
* Does site have more than one user? Supports multisite.
*
* @param string $code 'A' (all), 'N' (users with first / last names), 'X' (no user list).
* @param int $blog Blog ID or zero if not multisite.
* @return bool more than one user for selected option
*
* @since 1.4.0
*/
public function multiple_matching_users( $code, $blog ) {
if ( 'X' === $code ) {
return true;
} // end if do not want user list
if ( is_multisite() && 0 === $blog ) {
$blog = get_current_blog_id();
} // end if blog not set
$you = wp_get_current_user();
$urole = $this->qm_get_role();
if ( 'author' === $urole ) {
return ( 'X' === $code );
} // author can only reply to comments
if ( 'editor' === $urole ) {
$editors = '';
if ( is_multisite() ) {
$editors = get_blog_option( $blog, 'editors_quick_mail_privilege', 'N' );
} else {
$editors = get_option( 'editors_quick_mail_privilege', 'N' );
} // end if multisite
if ( 'Y' !== $editors ) {
return ( 'X' === $code );
} // end if editors not allowed to see list
} // end if editor
$exclude = array( $you->ID ); // Exclude current user.
$hide_admin = '';
if ( is_multisite() ) {
$hide_admin = get_blog_option( $blog, 'hide_quick_mail_admin', 'N' );
} else {
$hide_admin = get_option( 'hide_quick_mail_admin', 'N' );
} // end if
if ( 'A' === $code || 'B' === $code ) {
if ( $blog > 1 ) {
if ( 'Y' === $hide_admin ) {
$args = array(
'blog_id' => $blog,
'role__not_in' => array( 'Administrator' ),
'exclude' => $exclude,
);
} else {
$args = array( 'exclude' => $exclude );
}
} else {
if ( 'Y' === $hide_admin ) {
$args = array(
'role__not_in' => array( 'Administrator' ),
'exclude' => $exclude,
);
} else {
$args = array( 'exclude' => $exclude );
}
} // end if multisite
$info = get_users( $args );
return 1 < count( $info );
} // end if ALL or ALL + roles.
// Check for first and last names.
$meta_query = array(
'key' => 'last_name',
'value' => '',
'compare' => '>',
);
if ( is_multisite() ) {
if ( 'Y' === $hide_admin ) {
$args = array(
'role__not_in' => array( 'Administrator' ),
'exclude' => $exclude,
'blog_id' => $blog,
'meta_query' => $meta_query,
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '>',
);
} else {
$args = array(
'blog_id' => $blog,
'meta_query' => $meta_query,
'exclude' => $exclude,
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '>',
);
} // end if hide admin
} else {
if ( 'Y' === $hide_admin ) {
$args = array(
'role__not_in' => array( 'Administrator' ),
'exclude' => $exclude,
'meta_query' => $meta_query,
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '>',
);
} else {
$args = array(
'meta_query' => $meta_query,
'exclude' => $exclude,
'meta_key' => 'first_name',
'meta_value' => '',
'meta_compare' => '>',
);
} // end if
} // end if 'N'
$info = get_users( $args );
return 1 < count( $info );
} // end multiple_matching_users
/**
* Content type filter for wp_mail.
*
* Filters wp_mail_content_type.
*
* @param string $type previous content type.
* @return string our content type
*/
public function get_mail_content_type( $type ) {
return $this->content_type;
} // end get_mail_content_type
/**
* Optionally display dismissible wp_pointer with setup reminder.
* cannot be loaded in constructor because user info is not available until plugins_loaded.
*
* @since 1.3.0
*/
public function show_qm_pointer() {
if ( is_multisite() && is_super_admin() && is_network_admin() ) {
return;
} // end if skipping pointer on network admin page
$dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
if ( ! in_array( self::$pointer_name, $dismissed, true ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'qm_pointer_setup' ) );
} // end if pointer was not dismissed
} // end show_qm_pointer
/**
* Displays wp_mail error message.
*
* @param WP_Error $e mail error.
* @since 1.3.0
*/
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( '<h1 role="alert">%s</h1>', esc_html( $e->get_error_message() ), esc_html( __( '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.
*
* @link http://wheredidmybraingo.com/quick-mail-1-3-0-supports-international-mail/#minversion
*
* @since 1.2.3
*/
public function check_wp_version() {
global $wp_version;
if ( version_compare( $wp_version, '4.6', 'lt' ) ) {
deactivate_plugins( basename( __FILE__ ) );
echo sprintf( "<div class='notice notice-error' role='alert'>%s</div>", esc_html( __( 'Quick Mail requires WordPress 4.6 or greater.', 'quick-mail' ) ) );
exit;
} // end if
if ( ! extension_loaded( 'curl' ) ) {
deactivate_plugins( basename( __FILE__ ) );
echo sprintf( "<div class='notice notice-error' role='alert'>%s</div>", esc_html( __( 'Quick Mail requires cURL extension.', 'quick-mail' ) ) );
exit;
}
} // end check_wp_version
/**
* Add options when Quick Mail is activated.
*
* Add options, do not autoload them.
*
* @param string $plugin name of plugin.
* @param boolean $network if we are on a network.
*
* @since 1.2.0
*/
public function install_quick_mail( $plugin, $network ) {
if ( ! strstr( $plugin, basename( __FILE__ ) ) ) {
return;
} // end if not Quick Mail
$blog = is_multisite() ? get_current_blog_id() : 0;
$qm_options = array(
'authors_quick_mail_privilege' => 'N',
'editors_quick_mail_privilege' => 'N',
'hide_quick_mail_admin' => 'N',
'quick_mail_cannot_reply' => 'N',
'quick_mail_logging' => 'N',
'replace_quick_mail_sender' => 'N',
'verify_quick_mail_addresses' => 'N',
'quick_mail_banned' => '',
);
foreach ( $qm_options as $option => $value ) {
if ( is_multisite() ) {
add_blog_option( $blog, $option, $value );
} else {
add_option( $option, $value, '', 'no' );
} // end if multisite
} // end foreach
/**
* Do not show users if one user. Do not apply wpautop by default.
*/
$code = $this->multiple_matching_users( 'A', $blog ) ? 'A' : 'X';
$this->qm_update_option( 'show_quick_mail_users', $code );
$this->qm_update_option( 'qm_wpautop', '0' ); // TODO this should be Y/N like others.
$this->qm_update_option( 'show_quick_mail_commenters', 'N' );
$this->qm_update_option( 'limit_quick_mail_commenters', '7' );
add_user_meta( get_current_user_id(), 'want_quick_mail_privacy', 'Y' );
add_user_meta( get_current_user_id(), 'save_quick_mail_addresses', 'N' );
} // install_quick_mail
/**
* Load Javascript to display wp_pointer after installation.
*
* @since 1.3.0
*/
public function quick_mail_pointer_scripts() {
$greeting = esc_html( __( 'Welcome to Quick Mail', 'quick-mail' ) );
$suggestion = esc_html( __( 'Please verify your settings before using Quick Mail.', 'quick-mail' ) );
$pointer_content = "<h3>{$greeting}</h3><p role='alert'>{$suggestion}</p>";
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function() {
jQuery('#menu-settings').pointer({
content: "<?php echo $pointer_content; ?>",
position: {
edge: 'left', // arrow direction
align: 'center' // vertical alignment
},
pointerWidth: 350,
close: function() {
jQuery.post( ajaxurl, {
pointer: '<?php echo self::$pointer_name; ?>',
action: 'dismiss-wp-pointer' });
}
}).pointer('open');
});
//]]>
</script>
<?php
}
/**
* Setup wp_pointer for new installations.
*
* @since 1.3.0
*/
public function qm_pointer_setup() {
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
add_action( 'admin_print_footer_scripts', array( $this, 'quick_mail_pointer_scripts' ) );
} // end qm_pointer_setup
/**
* Remove Quick Mail pointer on deactivation.
*
* @since 3.2.9
*/
public static function remove_qm_pointer() {
$you = get_current_user_id();
$key = 'dismissed_wp_pointers';
$dismissed = array_filter( explode( ',', (string) get_user_meta( $you, $key, true ) ) );
if ( ! in_array( self::$pointer_name, $dismissed, true ) ) {
return;
} // end if not found
$meta_value = '';
$j = count( $dismissed );
for ( $i = 0; $i < $j; $i++ ) {
if ( $dismissed[ $i ] === self::$pointer_name ) {
continue;
}
$meta_value .= "{$dismissed[$i]},";
} // end for
$len = strlen( $meta_value );
if ( $len && ',' === $meta_value[ $len - 1 ] ) {
$meta_value = substr( $meta_value, 0, -1 );
} // end if trailing comma
update_user_meta( $you, $key, $meta_value );
} // end remove_qm_pointer
/**
* Delete options when Quick Mail is deactivated.
*
* Delete global and user options.
*
* @param string $plugin name of plugin.
* @param boolean $network if we are on a network.
* @since 1.1.1
*/
public function deactivate_quick_mail_plugin( $plugin, $network ) {
if ( ! strstr( $plugin, basename( __FILE__ ) ) ) {
return;
} // end if not Quick Mail
self::remove_qm_pointer();
} // end deactivate_quick_mail_plugin
/**
* Load quick-mail.js for email select and quick-mail-addresses.js to count saved addresses.
*
* @since 1.2.0
*/
public function add_email_scripts() {
if ( strstr( $_SERVER['REQUEST_URI'], 'quick_mail' ) ) {
wp_enqueue_script(
'qmScript',
plugins_url( '/lib/js/quick-mail.js', __FILE__ ),
array( 'jquery' ),
self::VERSION,
false
);
$data = array(
'duplicate' => __( 'Duplicate', 'quick-mail' ),
/* translators: for duplicate email addresses */
);
wp_localize_script( 'qmScript', 'quick_mail_words', $data );
} // end if on quick mail form
if ( strstr( $_SERVER['REQUEST_URI'], 'quick_mail_options' ) ) {
wp_enqueue_script( 'qmCount', plugins_url( '/lib/js/quick-mail-addresses.js', __FILE__ ), array( 'jquery' ), self::VERSION, false );
$data = array(
'one' => __( 'Clear 1 saved address', 'quick-mail' ),
/* translators: number of saved email addresses */
'many' => sprintf( __( 'Clear %s saved addresses', 'quick-mail' ), '{number}' ),
);
wp_localize_script( 'qmCount', 'quick_mail_saved', $data );
} // end if on options page
} // end add_email_scripts
/**
* Create and display recipient input. user list or text input.
*
* @param string $to recipient email.
* @param int $id user ID.
*/
public function quick_mail_recipient_input( $to, $id ) {
$tlen = wp_is_mobile() ? 28 : 75;
$template = "<input aria-labelledby='qme_label' value='%s' id='qm-email'
name='qm-email' type='email' required aria-required='true' tabindex='0' autofocus size='{$tlen}'>";
$blog = is_multisite() ? get_current_blog_id() : 0;
$option = $this->qm_get_display_option( $blog );
$you = wp_get_current_user(); // From.
if ( 'author' === $this->qm_get_role() ) {
$option = 'X';
} // end if author
if ( 'X' !== $option ) {
$editors = '';
if ( is_multisite() ) {
$editors = get_blog_option( $blog, 'editors_quick_mail_privilege', 'N' );
} else {
$editors = get_option( 'editors_quick_mail_privilege', 'N' );
} // end if multisite
if ( 'Y' !== $editors ) {
if ( ! $this->qm_is_admin( $id, $blog ) ) {
$option = 'X';
} // end if not admin and option might have changed
} // end if editors not allowed to see list
} // end if wants user list
if ( 'A' !== $option && 'B' !== $option && 'N' !== $option && 'O' !== $option ) {
echo sprintf( $template, $to );
return;
} // end if invalid option.
$hide_admin = '';
if ( is_multisite() ) {
$hide_admin = get_blog_option( $blog, 'hide_quick_mail_admin', 'N' );
} else {
$hide_admin = get_option( 'hide_quick_mail_admin', 'N' );
} // end if
$args = ( 'Y' === $hide_admin )
? array(
'role__not_in' => 'Administrator',
'exclude' => array( $you->ID ),
)
: array( 'exclude' => array( $you->ID ) );
$user_query = new WP_User_Query( $args );
$users = array();
foreach ( $user_query->results as $user ) {
if ( $user->user_email === $you->user_email ) {
continue;
} // end duplicate email test
if ( 'A' === $option || 'B' === $option ) {
$nickname = ucfirst( get_user_meta( $user->ID, 'nickname', true ) );
$users[] = "{$nickname}\t{$user->user_email}\t{$user->ID}";
} else {
$last = ucfirst( get_user_meta( $user->ID, 'last_name', true ) );
$first = ucfirst( get_user_meta( $user->ID, 'first_name', true ) );
if ( ! empty( $first ) && ! empty( $last ) && ! empty( $user->user_email ) ) {
$users[] = "{$last}\t{$first}\t{$user->ID}\t{$user->user_email}";
} // end if valid name
} // end if all users else named only
} // end for
$j = count( $users );
if ( 1 > $j ) {
echo sprintf( $template, $to );
return;
} // end if at least one match
sort( $users );
$letter = '';
ob_start();
echo '<select aria-labelledby="qme_label" name="qm-email" id="qm-primary" required aria-required="true" size="1" tabindex="0" autofocus><option class="qmopt" value="" selected="selected">Select</option>';
for ( $i = 0; $i < $j; $i++ ) {
$row = explode( "\t", $users[ $i ] );
if ( 'A' === $option || 'B' === $option ) {
$address = rawurlencode( "\"{$row[0]}\" <{$row[1]}>" );
} else {
$address = rawurlencode( "\"{$row[1]} {$row[0]}\" <{$row[3]}>" );
} // end if
if ( $letter !== $row[0][0] ) {
if ( ! empty( $letter ) ) {
echo '</optgroup>';
} // end if not first letter group
$letter = $row[0][0];
echo "<optgroup class='qmog' label='{$letter}'>";
} // end if first letter changed
$role = '';
if ( 'B' === $option || 'O' === $option ) {
$user_meta = get_userdata( $row[2] );
$urole = empty( $user_meta->roles[0] ) ? __( 'No Role', 'quick-mail' ) : ucfirst( $user_meta->roles[0] );
$role = " ({$urole})";
} // end if want role.
if ( 'A' === $option || 'B' === $option ) {
$selected = ( $row[1] !== $to ) ? ' ' : ' selected="selected" ';
echo "<option{$selected}value='{$address}' class='qmopt'>{$row[0]}{$role}</option>";
} else {
$selected = ( $row[3] !== $to ) ? ' ' : ' selected="selected" ';
echo "<option{$selected}value='{$address}' class='qmopt'>{$row[1]} {$row[0]}{$role}</option>";
}
} // end for
echo '</optgroup></select>';
return ob_get_clean();
} // end quick_mail_recipient_input
/**
* Get input control for cc input.
*
* @param string $cc cc.
* @param integer $id user ID.
* @return void|string
*/
public function quick_mail_cc_input( $cc, $id ) {
$tlen = wp_is_mobile() ? '28' : '75';
$template = "<input aria-labelledby='qmcc_label' value='%s' id='qm-cc' name='qm-cc' type='text' size='{$tlen}' tabindex='3'>";
$blog = is_multisite() ? get_current_blog_id() : 0;
$option = $this->qm_get_display_option( $blog );
if ( ! $this->multiple_matching_users( $option, $blog ) ) {
$option = 'X';
} // end if since 1.4.0
$you = wp_get_current_user();
if ( 'author' === $this->qm_get_role() ) {
$option = 'X';
} // end if author
if ( 'X' !== $option ) {
// Check if site permissions were changed.
$editors = '';
if ( is_multisite() ) {
$editors = get_blog_option( $blog, 'editors_quick_mail_privilege', 'N' );
} else {
$editors = get_option( 'editors_quick_mail_privilege', 'N' );
} // end if multisite
if ( 'Y' !== $editors ) {
if ( ! $this->qm_is_admin( $id, $blog ) ) {
$option = 'X';
} // end if not admin
} // end if editors not allowed to see list
} // end if wants user list
if ( 'A' !== $option && 'B' !== $option && 'N' !== $option && 'O' !== $option ) {
echo sprintf( $template, $cc );
return;
}
$hide_admin = '';
if ( is_multisite() ) {
$hide_admin = get_blog_option( $blog, 'hide_quick_mail_admin', 'N' );
} else {
$hide_admin = get_option( 'hide_quick_mail_admin', 'N' );
} // end if
$args = ( 'Y' === $hide_admin ) ? array(
'role__not_in' => 'Administrator',
'exclude' => array( $you->ID ),
) : array( 'exclude' => array( $you->ID ) );
$user_query = new WP_User_Query( $args );
$users = array();
foreach ( $user_query->results as $user ) {
if ( $user->user_email === $you->user_email ) {
continue;
} // end if duplicate email
if ( 'A' === $option || 'B' === $option ) {
$nickname = ucfirst( get_user_meta( $user->ID, 'nickname', true ) );
$users[] = "{$nickname}\t{$user->user_email}\t{$user->ID}";
} else {
$last = ucfirst( get_user_meta( $user->ID, 'last_name', true ) );
$first = ucfirst( get_user_meta( $user->ID, 'first_name', true ) );
if ( ! empty( $first ) && ! empty( $last ) && ! empty( $user->user_email ) ) {
$users[] = "{$last}\t{$first}\t{$user->ID}\t{$user->user_email}";
} // end if valid name
} // end if all users else named only
} // end for
$j = count( $users );
if ( 2 > $j ) {
echo sprintf( $template, $cc );
return;
} // end if one match
sort( $users );
$letter = '';
ob_start();
echo '<select aria-labelledby="qmcc_label" name="qm-cc[]" id="qm-secondary"
multiple="multiple" size="6" tabindex="3"><option class="qmopt" value=""
selected="selected">Select</option>';
for ( $i = 0; $i < $j; $i++ ) {
$row = explode( "\t", $users[ $i ] );
$role = '';
if ( 'B' === $option || 'O' === $option ) {
$user_meta = get_userdata( $row[2] );
if ( ! empty( $user_meta->roles ) ) {
$role = ' (' . ucfirst( $user_meta->roles[0] ) . ')';
} else {
$role = ' (' . __( 'No Role', 'quick-mail' ) . ')';
} // end if found role.
} // end if want role.
if ( 'A' === $option || 'B' === $option ) {
$address = rawurlencode( "\"{$row[0]}\" <{$row[1]}>" );
} else {
$address = rawurlencode( "\"{$row[1]} {$row[0]}\" <{$row[3]}>" );
} // end if
if ( $letter !== $row[0][0] ) {
if ( ! empty( $letter ) ) {
echo '</optgroup>';
} // end if not first letter group
$letter = $row[0][0];
echo "<optgroup class='qmog' label='{$letter}'>";
} // end if first letter changed
if ( 'A' === $option || 'B' === $option ) {
$selected = ( $row[1] !== $cc ) ? ' ' : ' selected="selected" ';
echo "<option{$selected}value='{$address}' class='qmopt'>{$row[0]}{$role}</option>";
} else {
$selected = ( $row[3] !== $cc ) ? ' ' : ' selected="selected" ';
echo "<option{$selected}value='{$address}' class='qmopt'>{$row[1]} {$row[0]}{$role}</option>";
}
} // end for