This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
how-tos.php
171 lines (153 loc) · 10.2 KB
/
how-tos.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
<?php
class wpMandrill_HowTos {
static function show($section) {
$section = strtolower($section);
if ( !in_array($section, array('intro','auto','regular','filter', 'nl2br', 'direct','regions') ) ) $section = 'auto';
$title = '';
switch ($section) {
case 'intro':
break;
case 'auto':
$title = __('Mandrill: How to tell WordPress to use wpMandrill.', 'wpmandrill');
break;
case 'regular':
$title = __('Mandrill: How to send a regular email.', 'wpmandrill');
break;
case 'filter':
$title = __('Mandrill: How to modify a certain email using the <em>mandrill_payload</em> WordPress filter.', 'wpmandrill');
break;
case 'nl2br':
$title = __('Mandrill: How to tell WordPress to change line feeds by BR tags in a certain email using the <em>mandrill_nl2br</em> WordPress filter.', 'wpmandrill');
break;
case 'direct':
$title = __('Mandrill: How to send emails from within your plugins.', 'wpmandrill');
break;
case 'regions':
$title = __('Mandrill: How to use multiple editable regions in your template.', 'wpmandrill');
break;
}
$method = 'showSection' . ucwords($section);
$html = self::$method();
if ( $title != '' ) {
$html = <<<HTML
<div class="stuffbox" style="max-width: 90% !important;">
<h3>$title</h3>
<div style="width:90%; margin-left:auto;margin-right:auto;">
$html
</div>
</div>
HTML;
}
return $html;
}
static function showSectionIntro() {
return '<p>' . __('The purpose of this how-to is to show you how easy it is to start using the awesome platform that Mandrill offers to handle your transactional emails.', 'wpmandrill-how-tos').'</p>'
. '<ol>'
. '<li>'. __('Just by setting it up, all the emails sent from your WordPress installation will be sent using the power of Mandrill.', 'wpmandrill') . '</li>'
. '<li>'. __('If you want further customization, you can use the <strong>mandrill_payload</strong> filter we\'ve provided.', 'wpmandrill') . '</li>'
. '<li>'. __('And if you want an even greater integration between your application and Mandrill, we\'ve created a convenient call to send emails from within your plugins.', 'wpmandrill') . '</li>'
. '</ol>'
.'<p>' . __('You can learn more about all of these features right from this page.', 'wpmandrill').'</p>';
}
static function showSectionAuto() {
return '
<span class="setting-description">
<p>'.__('Simply install wpMandrill and configure it to make it handle all the email functions of your WordPress installation.', 'wpmandrill').'</p>
<p>'.__('Once it has been properly configured, it will replace the regular WordPress emailing processes, so it\'s basically transparent for you and for WordPress.', 'wpmandrill').'</p>
<p>'.__('To test wpMandrill, log out, and try to use the <em>Forgot your password?</em> feature in WordPress (you don\'t need to reset your password though. Just check the headers of the email that it sends you, and you\'ll see that it comes from Mandrill\'s servers).', 'wpmandrill').'</p>
</span>
';
}
static function showSectionRegular() {
return '
<span class="setting-description">
<p>'.__('If you\'re a Plugin Developer, and you need to send a regular email using wpMandrill, you don\'t need to learn anything else. You can use the good ol\' <strong>wp_mail</strong> function, as you would normally do if you were not using this plugin.', 'wpmandrill').'</p>
<p>'.__('For example:', 'wpmandrill').'</p>
<p><blockquote><pre>'.__('<?php wp_mail(\'[email protected]\', \'Your subject\', \'Your message\'); ?>', 'wpmandrill').'</pre></blockquote></p>
</span>
';
}
static function showSectionRegions() {
return '
<span class="setting-description">
<p>'.__('By default, wpMandrill uses only one editable section of your templates: <em>main</em> so its use is transparent for the you.', 'wpmandrill').'</p>
<p>'.__('If you need to use more than one, <em>main</em> included, you need to provided an array with the content to use for each editable region involved. This array should be supply in the field "html" of the payload.', 'wpmandrill').'</p>
<p>'.__('This array has the same structure of the parameter <em>template_content</em> of the API call <a href="https://mandrillapp.com/api/docs/messages.html#method=send-template" target="_blank">send-template</a>:', 'wpmandrill').'</p>
<p>'.__('$message["html"] = array( array("name" => region_name_1", "content" => "My awesome content for Region 1"), ... , array( "name" => region_name_2", "content" => "My awesome content for Region 2") )', 'wpmandrill').'</p>
';
}
static function showSectionFilter() {
return '
<span class="setting-description">
<p>'.__('if you need to fine tune one or some of the emails sent through your WordPress installation, you will need to use the <em>mandrill_payload</em> filter.', 'wpmandrill').'</p>
<p>'.__('To use it, you must create a function that analyzes the payload that is about to be sent to Mandrill, and modify it based on your requirements. Then you\'ll need to add this function as the callback of the mentioned filter, using the <em>add_filter</em> WordPress call. And finally, insert it into your theme\'s functions.php file or you own plugin\'s file.', 'wpmandrill').'</p>
<p>'.__('You can use the following code as an skeleton for your own callbacks:', 'wpmandrill').'</p>
<p>
<blockquote><pre>
<?php
function my_callback($message) {
if ( my_condition($message) ) {
$message = my_process($message)
}
return $message;
}
add_filter( \'mandrill_payload\', \'my_callback\' );
?>
</pre></blockquote>
</p>
<p>'.__('Let\'s say you\'re using the <a href="http://wordpress.org/extend/plugins/cart66-lite/" target="_blank">Cart66 Lite Ecommerce plugin</a> and you want to modify the emails sent from this plugin. Here\'s what you should do:', 'wpmandrill').'</p>
<p>
<blockquote><pre>
<?php
function cart66Emails($message) {
if ( in_array( \'wp_Cart66Common::mail\', $message[\'tags\'][\'automatic\'] ) ) {
// do anything funny here...
if ( isset($message[\'template\'][\'content\'][0][\'content\']) )
$html = &$message[\'template\'][\'content\'][0][\'content\'];
else
$html = &$message[\'html\'];
$html = nl2br($html);
}
return $message;
}
add_filter( \'mandrill_payload\', \'cart66Emails\' );
?>
</pre></blockquote>
</p>
</span>
';
}
static function showSectionNl2br() {
return '
<span class="setting-description">
<p>'.__('That\'s easy! Just do something like this:', 'wpmandrill').'</p>
<p>
<blockquote><pre>
<?php
function forgotMyPasswordEmails($nl2br, $message) {
if ( in_array( \'wp-retrieve_password\', $message[\'tags\'][\'automatic\'] ) ) {
$nl2br = true;
}
return $nl2br;
}
add_filter( \'mandrill_nl2br\', \'forgotMyPasswordEmails\' );
?>
</pre></blockquote>
</p>
</span>
';
}
static function showSectionDirect() {
return '
<span class="setting-description">
<p>'.__('If you are a Plugin Developer and you need to create a deep integration between Mandrill and your WordPress installation, wpMandrill will make your life easier.', 'wpmandrill').'</p>
<p>'.__('We have exposed a simple function that allows you to add tags and specify the template to use, in addition to specifying the To, Subject and Body sections of the email:','wpmandrill').'</p>
<p><blockquote><pre>'.__('<?php wpMandrill::mail($to, $subject, $html, $headers = \'\', $attachments = array(), $tags = array(), $from_name = \'\', $from_email = \'\', $template_name = \'\'); ?>', 'wpmandrill').'</pre></blockquote></p>
<p>'.__('But if you need Mandrill Powers, we have included a full-featured PHP class called Mandrill. It has every API call defined in Mandrill\'s API. Check it out at <em>/wp-content/plugin/wpmandrill/lib/mandrill.class.php</em>.', 'wpmandrill').'</p>
<p>'.__('To use it, just instantiate an object passing your API key, and make the calls:', 'wpmandrill').'</p>
<p><blockquote><pre>'.__('<?php $mandrill = Mandrill($my_api_key); echo $mandrill->ping(); ?>', 'wpmandrill').'</pre></blockquote></p>
</span>
';
}
}
?>