Jag försöker ändra lite i en Wordpress plugin. Men om jag ändrar något i texten så skickas e-post meddelandet inte iväg.
Det jag vill ändra är texten som syns i e-post meddelandet t.ex. ämnet som nu är "Subscription/Contact form submitted". Sen även texten där det stå "Phone" ska ju vara telefon osv. Någon som vet vad jag ska göra för att kunna ändra texten?
<?php
/* Admin Notification for Layered Popups */
class ulp_mail_class {
var $default_popup_options = array(
"mail_enable" => "off",
"mail_email" => ""
);
function __construct() {
if (is_admin()) {
add_action('ulp_popup_options_show', array(&$this, 'popup_options_show'));
add_action('ulp_subscribe', array(&$this, 'subscribe'), 10, 2);
add_filter('ulp_popup_options_check', array(&$this, 'popup_options_check'), 10, 1);
add_filter('ulp_popup_options_populate', array(&$this, 'popup_options_populate'), 10, 1);
add_filter('ulp_use_mailing', array(&$this, 'use_mailing'), 10, 1);
}
}
function use_mailing($_use) {
return true || $_use;
}
function popup_options_show($_popup_options) {
$popup_options = array_merge($this->default_popup_options, $_popup_options);
echo '
<h3>'.__('Admin Notification Parameters', 'ulp').'</h3>
<table class="ulp_useroptions">
<tr>
<th>'.__('Enable mailing', 'ulp').':</th>
<td>
<input type="checkbox" id="ulp_mail_enable" name="ulp_mail_enable" '.($popup_options['mail_enable'] == "on" ? 'checked="checked"' : '').'"> '.__('Send details to admin', 'ulp').'
<br /><em>'.__('Please tick checkbox if you want to receive submitted contact details by e-mail.', 'ulp').'</em>
</td>
</tr>
<tr>
<th>'.__('Admin e-mail address', 'ulp').':</th>
<td>
<input type="text" id="ulp_mail_email" name="ulp_mail_email" value="'.esc_attr($popup_options['mail_email']).'" class="widefat">
<br /><em>'.__('Enter your e-mail address. Submitted contact details will be sent to this e-mail address. You can set several comma-separated e-mails.', 'ulp').'</em>
</td>
</tr>
</table>';
}
function popup_options_check($_errors) {
$errors = array();
$popup_options = array();
foreach ($this->default_popup_options as $key => $value) {
if (isset($_POST['ulp_'.$key])) {
$popup_options[$key] = stripslashes(trim($_POST['ulp_'.$key]));
}
}
if (isset($_POST["ulp_mail_enable"])) $popup_options['mail_enable'] = "on";
else $popup_options['mail_enable'] = "off";
if ($popup_options['mail_enable'] == 'on') {
$emails = explode(',', $popup_options['mail_email']);
$emails_found = false;
$emails_invalid = false;
foreach ($emails as $email) {
$email = trim($email);
if (!empty($email)) {
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,9})$/i", $email)) $emails_invalid = true;
else $emails_found = true;
}
}
if (!$emails_found) $errors[] = __('Admin e-mail must be valid e-mail address.', 'ulp');
else if ($emails_invalid) $errors[] = __('Admin e-mail must be valid e-mail address.', 'ulp');
}
return array_merge($_errors, $errors);
}
function popup_options_populate($_popup_options) {
$popup_options = array();
foreach ($this->default_popup_options as $key => $value) {
if (isset($_POST['ulp_'.$key])) {
$popup_options[$key] = stripslashes(trim($_POST['ulp_'.$key]));
}
}
if (isset($_POST["ulp_mail_enable"])) $popup_options['mail_enable'] = "on";
else $popup_options['mail_enable'] = "off";
return array_merge($_popup_options, $popup_options);
}
function subscribe($_popup_options, $_subscriber) {
global $ulp;
$popup_options = array_merge($this->default_popup_options, $_popup_options);
if ($popup_options['mail_enable'] == 'on') {
$body = __('Subscription/Contact form submitted.', 'ulp').'<br /><br />
'.(empty($_subscriber['name']) ? '' : '<strong>'.__('Name', 'ulp').':</strong> '.esc_attr($_subscriber['name']).'<br />').'
<strong>'.__('E-mail', 'ulp').':</strong> '.esc_attr($_subscriber['email']).'<br />
'.(empty($_subscriber['phone']) ? '' : '<strong>'.__('Phone #', 'ulp').':</strong> '.esc_attr($_subscriber['phone']).'<br />').'
<strong>'.__('IP', 'ulp').':</strong> '.$_SERVER['REMOTE_ADDR'].'<br />
<strong>'.__('Popup', 'ulp').':</strong> '.esc_attr($popup_options['title']).'<br />
<strong>'.__('URL', 'ulp').':</strong> '.$_SERVER['HTTP_REFERER'].'<br />
'.(empty($_subscriber['message']) ? '' : '<strong>'.__('Message', 'ulp').':</strong><br />'.str_replace(array("\r", "\n"), array("", "<br />"), esc_attr($_subscriber['message'])).'<br />').'<br />
'.__('Thanks,', 'ulp').'<br />Layered Popups';
$mail_headers = "Content-Type: text/html; charset=utf-8\r\n";
$mail_headers .= "Reply-To: ".(empty($_subscriber['name']) ? esc_attr($_subscriber['email']) : esc_attr($_subscriber['name']))." <".esc_attr($_subscriber['email']).">\r\n";
if (isset($ulp)) {
$mail_headers .= "From: ".(empty($ulp->options['from_name']) ? esc_attr($ulp->options['from_email']) : esc_attr($ulp->options['from_name']))." <".esc_attr($ulp->options['from_email']).">\r\n";
}
$mail_emails = explode(',', $popup_options['mail_email']);
foreach ($mail_emails as $mail_email) {
$mail_email = trim($mail_email);
if (!empty($mail_email)) {
if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,9})$/i", $mail_email)) {
wp_mail($mail_email, __('Subscription/Contact form submitted', 'ulp'), $body, $mail_headers);
}
}
}
}
}
}
$ulp_mail = new ulp_mail_class();
?>
__() är WordPress översättningsfunktion, och strängen som skickas med som argument 1 är det som används som msgid i språkfilerna. Ändrar du den strängen kommer den alltså inte hitta någon msgid som överensstämmer med strängen.
Antingen kan du skippa anropet till översättningsfunktionen, och hårdkoda in texter på svenska, men då kommer det vara svenska även om du i framtiden vill kunna ha stöd för flera språk på din webbplats.
Exempel:
wp_mail($mail_email, __('Subscription/Contact form submitted', 'ulp'), $body, $mail_headers);
Det andra alternativet är att skapa en svensk språkfil till pluginet. Språkfilerna ligger i sökvägen %wordpress_root%/wp-content/plugins/%plugin_name%/lang.
Exempel:
Fil: ulp-sv_SE.po
msgid "Subscription/Contact form submitted"
msgstr "Kontaktformulär skickat"
142 ms totalt · 3 externa anrop · v20260731065814-full.4bcf49fe