function process_form_submission()
{
// Add a filter to replace tokens in the subject field with sanitized field values
add_filter('contact_form_subject', array($this, 'replace_tokens_with_input'), 10, 2);
$id = stripslashes($_POST['contact-form-id']);
if (is_user_logged_in()) {
check_admin_referer("contact-form_{$id}");
}
$is_widget = 0 === strpos($id, 'widget-');
$form = false;
if ($is_widget) {
// It's a form embedded in a text widget
$this->current_widget_id = substr($id, 7);
// remove "widget-"
$widget_type = implode('-', array_slice(explode('-', $this->current_widget_id), 0, -1));
// Remove trailing -#
// Is the widget active?
$sidebar = is_active_widget(false, $this->current_widget_id, $widget_type);
// This is lame - no core API for getting a widget by ID
$widget = isset($GLOBALS['wp_registered_widgets'][$this->current_widget_id]) ? $GLOBALS['wp_registered_widgets'][$this->current_widget_id] : false;
if ($sidebar && $widget && isset($widget['callback'])) {
// This is lamer - no API for outputting a given widget by ID
ob_start();
// Process the widget to populate Grunion_Contact_Form::$last
call_user_func($widget['callback'], array(), $widget['params'][0]);
ob_end_clean();
}
} else {
// It's a form embedded in a post
$post = get_post($id);
// Process the content to populate Grunion_Contact_Form::$last
/** This filter is already documented in core. wp-includes/post-template.php */
apply_filters('the_content', $post->post_content);
}
$form = Grunion_Contact_Form::$last;
// No form may mean user is using do_shortcode, grab the form using the stored post meta
if (!$form) {
// Get shortcode from post meta
$shortcode = get_post_meta($_POST['contact-form-id'], '_g_feedback_shortcode', true);
// Format it
if ($shortcode != '') {
// Get attributes from post meta.
$parameters = '';
$attributes = get_post_meta($_POST['contact-form-id'], '_g_feedback_shortcode_atts', true);
if (!empty($attributes) && is_array($attributes)) {
foreach (array_filter($attributes) as $param => $value) {
$parameters .= " {$param}=\"{$value}\"";
}
}
$shortcode = '[contact-form' . $parameters . ']' . $shortcode . '[/contact-form]';
do_shortcode($shortcode);
// Recreate form
$form = Grunion_Contact_Form::$last;
}
if (!$form) {
return false;
}
}
if (is_wp_error($form->errors) && $form->errors->get_error_codes()) {
return $form->errors;
}
// Process the form
return $form->process_submission();
}