function wpcf7_admin_add_pages() { if (isset($_POST['wpcf7-save']) && wpcf7_admin_has_edit_cap()) { $id = $_POST['wpcf7-id']; check_admin_referer('wpcf7-save_' . $id); if (!($contact_form = wpcf7_contact_form($id))) { $contact_form = new WPCF8_ContactForm(); $contact_form->initial = true; } $title = trim($_POST['wpcf7-title']); $form = trim($_POST['wpcf7-form']); $mail = array('subject' => trim($_POST['wpcf7-mail-subject']), 'sender' => trim($_POST['wpcf7-mail-sender']), 'body' => trim($_POST['wpcf7-mail-body']), 'recipient' => trim($_POST['wpcf7-mail-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-attachments']), 'use_html' => 1 == $_POST['wpcf7-mail-use-html'] ? true : false); $mail_2 = array('active' => 1 == $_POST['wpcf7-mail-2-active'] ? true : false, 'subject' => trim($_POST['wpcf7-mail-2-subject']), 'sender' => trim($_POST['wpcf7-mail-2-sender']), 'body' => trim($_POST['wpcf7-mail-2-body']), 'recipient' => trim($_POST['wpcf7-mail-2-recipient']), 'additional_headers' => trim($_POST['wpcf7-mail-2-additional-headers']), 'attachments' => trim($_POST['wpcf7-mail-2-attachments']), 'use_html' => 1 == $_POST['wpcf7-mail-2-use-html'] ? true : false); $messages = array('mail_sent_ok' => trim($_POST['wpcf7-message-mail-sent-ok']), 'mail_sent_ng' => trim($_POST['wpcf7-message-mail-sent-ng']), 'akismet_says_spam' => trim($_POST['wpcf7-message-akismet-says-spam']), 'validation_error' => trim($_POST['wpcf7-message-validation-error']), 'accept_terms' => trim($_POST['wpcf7-message-accept-terms']), 'invalid_email' => trim($_POST['wpcf7-message-invalid-email']), 'invalid_required' => trim($_POST['wpcf7-message-invalid-required']), 'quiz_answer_not_correct' => trim($_POST['wpcf7-message-quiz-answer-not-correct']), 'captcha_not_match' => trim($_POST['wpcf7-message-captcha-not-match']), 'upload_failed' => trim($_POST['wpcf7-message-upload-failed']), 'upload_file_type_invalid' => trim($_POST['wpcf7-message-upload-file-type-invalid']), 'upload_file_too_large' => trim($_POST['wpcf7-message-upload-file-too-large'])); $additional_settings = trim($_POST['wpcf7-additional-settings']); $query = array(); $query['message'] = $contact_form->initial ? 'created' : 'saved'; $contact_form->title = $title; $contact_form->form = $form; $contact_form->mail = $mail; $contact_form->mail_2 = $mail_2; $contact_form->messages = $messages; $contact_form->additional_settings = $additional_settings; $contact_form->save(); $query['contactform'] = $contact_form->id; $redirect_to = wpcf7_admin_url('admin.php', $query); wp_redirect($redirect_to); exit; } elseif (isset($_POST['wpcf7-copy']) && wpcf7_admin_has_edit_cap()) { $id = $_POST['wpcf7-id']; check_admin_referer('wpcf7-copy_' . $id); $query = array(); if ($contact_form = wpcf7_contact_form($id)) { $new_contact_form = $contact_form->copy(); $new_contact_form->save(); $query['contactform'] = $new_contact_form->id; $query['message'] = 'created'; } else { $query['contactform'] = $contact_form->id; } $redirect_to = wpcf7_admin_url('admin.php', $query); wp_redirect($redirect_to); exit; } elseif (isset($_POST['wpcf7-delete']) && wpcf7_admin_has_edit_cap()) { $id = $_POST['wpcf7-id']; check_admin_referer('wpcf7-delete_' . $id); if ($contact_form = wpcf7_contact_form($id)) { $contact_form->delete(); } $redirect_to = wpcf7_admin_url('admin.php', array('message' => 'deleted')); wp_redirect($redirect_to); exit; } elseif (isset($_GET['wpcf7-create-table'])) { check_admin_referer('wpcf7-create-table'); $query = array(); if (!wpcf7_table_exists() && current_user_can('activate_plugins')) { wpcf7_install(); if (wpcf7_table_exists()) { $query['message'] = 'table_created'; } else { $query['message'] = 'table_not_created'; } } wp_redirect(wpcf7_admin_url('admin.php', $query)); exit; } add_menu_page(__('Contact Form 7', 'wpcf7'), __('Contact', 'wpcf7'), WPCF8_ADMIN_READ_CAPABILITY, __FILE__, 'wpcf7_admin_management_page'); add_submenu_page(__FILE__, __('Edit Contact Forms', 'wpcf7'), __('Edit', 'wpcf7'), WPCF8_ADMIN_READ_CAPABILITY, __FILE__, 'wpcf7_admin_management_page'); }
function wpcf7_contact_form($id) { global $wpdb; $table_name = wpcf7_table_name(); $id = (int) $id; $query = $wpdb->prepare("SELECT * FROM {$table_name} WHERE cf7_unit_id = %d", $id); if (!($row = $wpdb->get_row($query))) { return false; } // No data $contact_form = new WPCF8_ContactForm(); $contact_form->id = $row->cf7_unit_id; $contact_form->title = stripslashes_deep($row->title); $contact_form->form = stripslashes_deep(maybe_unserialize($row->form)); $contact_form->mail = stripslashes_deep(maybe_unserialize($row->mail)); $contact_form->mail_2 = stripslashes_deep(maybe_unserialize($row->mail_2)); $contact_form->messages = stripslashes_deep(maybe_unserialize($row->messages)); $contact_form->additional_settings = stripslashes_deep(maybe_unserialize($row->additional_settings)); $contact_form->upgrade(); return $contact_form; }