function wpmtst_form_field($field_name) { $fields = wpmtst_get_form_fields(WPMST()->atts('form_id')); foreach ($fields as $key => $field) { if ($field['name'] == $field_name) { wpmtst_single_form_field($field); } } }
/** * Notify admin upon testimonial submission. * * @param array $post * @param string $form_name * @since 1.7.0 * @since 2.4.0 Logging mail failure. */ function wpmtst_notify_admin($post, $form_name = 'custom') { $fields = wpmtst_get_form_fields($form_name); $options = get_option('wpmtst_options'); $form_options = get_option('wpmtst_form_options'); if ($form_options['sender_site_email']) { $sender_email = get_bloginfo('admin_email'); } else { $sender_email = $form_options['sender_email']; } $sender_name = $form_options['sender_name']; if ($form_options['admin_notify']) { foreach ($form_options['recipients'] as $recipient) { if (isset($recipient['admin_site_email']) && $recipient['admin_site_email']) { $admin_email = get_bloginfo('admin_email'); } else { $admin_email = $recipient['admin_email']; } $admin_name = $recipient['admin_name']; $to = sprintf('%s <%s>', $admin_name, $admin_email); // Subject line $subject = $form_options['email_subject']; $subject = str_replace('%BLOGNAME%', get_bloginfo('name'), $subject); $subject = str_replace('%TITLE%', $post['post_title'], $subject); $subject = str_replace('%STATUS%', $post['post_status'], $subject); // custom fields foreach ($fields as $field) { $replace = isset($post[$field['name']]) ? $post[$field['name']] : '(blank)'; $field_as_tag = '%' . strtoupper($field['name']) . '%'; $subject = str_replace($field_as_tag, $replace, $subject); } // Message text $message = $form_options['email_message']; $message = str_replace('%BLOGNAME%', get_bloginfo('name'), $message); $message = str_replace('%TITLE%', $post['post_title'], $message); $message = str_replace('%CONTENT%', $post['post_content'], $message); $message = str_replace('%STATUS%', $post['post_status'], $message); // custom fields foreach ($fields as $field) { $replace = isset($post[$field['name']]) ? $post[$field['name']] : '(blank)'; $field_as_tag = '%' . strtoupper($field['name']) . '%'; $message = str_replace($field_as_tag, $replace, $message); } $headers = sprintf('From: %s <%s>', $sender_name, $sender_email); // @TODO More info here? A copy of testimonial? A link to admin page? A link to approve directly from email? $mail_sent = wp_mail($to, $subject, $message, $headers); // Log email action if (isset($options['email_log_level']) && $options['email_log_level']) { // for both levels, log failure only // for level 2, log both success and failure if (!$mail_sent || 2 == $options['email_log_level']) { $log_entry = array('response' => $mail_sent ? 'mail successful' : 'mail failed', 'to' => $to, 'subject' => $subject, 'message' => $message, 'headers' => $headers); WPMST()->log($log_entry, __FUNCTION__); } } } // for each recipient } // if notify }
/** * The form. * * @param $atts * * @return mixed|string|void */ function wpmtst_form_view($atts) { global $strong_templates; if (isset($_GET['success'])) { // Load stylesheet do_action('wpmtst_form_rendered', $atts); return apply_filters('wpmtst_form_success_message', '<div class="testimonial-success">' . wpmtst_get_form_message('submission-success') . '</div>'); } // TODO no need to extract extract(normalize_empty_atts($atts)); $fields = wpmtst_get_form_fields($form_id); $form_values = array('category' => $category); foreach ($fields as $key => $field) { $form_values[$field['name']] = ''; } $previous_values = WPMST()->get_form_values(); if ($previous_values) { $form_values = array_merge($form_values, $previous_values); } WPMST()->set_form_values($form_values); /** * Add filters here. */ /** * Load template */ $template_file = $strong_templates->get_template_attr($atts, 'template'); ob_start(); /** @noinspection PhpIncludeInspection */ include $template_file; $html = ob_get_contents(); ob_end_clean(); /** * Remove filters here. */ do_action('wpmtst_form_rendered', $atts); $html = apply_filters('strong_view_form_html', $html); return $html; }