本文整理汇总了PHP中WPCF7_ContactForm::save方法的典型用法代码示例。如果您正苦于以下问题:PHP WPCF7_ContactForm::save方法的具体用法?PHP WPCF7_ContactForm::save怎么用?PHP WPCF7_ContactForm::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPCF7_ContactForm
的用法示例。
在下文中一共展示了WPCF7_ContactForm::save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gd_quicksetup_setup_contact_form_7
/**
* Set up the contact form 7 plugin.
* Set up the default contact form with the user's e-mail address, and create a
* contact page to contain the form.
* @global type $gd_quicksetup_plugin
* @return null
*/
function gd_quicksetup_setup_contact_form_7()
{
global $gd_quicksetup_plugin;
$options = $gd_quicksetup_plugin->get_current_plugin_options();
// Get email address
$email = '';
foreach ((array) $_POST['type'] as $k => $v) {
if (!$_POST['enabled'][$k] || 'false' === $_POST['enabled'][$k]) {
continue;
}
if ('contact' === $v) {
$email = sanitize_email(stripslashes_deep($_POST['contact_email'][$k]));
break;
}
}
if (empty($email)) {
return;
}
// Update the contact form
$post_content = '';
$posts = get_posts(array('post_type' => 'wpcf7_contact_form', 'numberposts' => 1));
if (class_exists('WPCF7_ContactForm') && is_array($posts) && !empty($posts[0]) && $posts[0] instanceof WP_Post) {
// Use Contact Form 7's API
$post = $posts[0];
$contact_form = new WPCF7_ContactForm($post);
// Add CAPTCHA
$search = '[textarea your-message] </p>';
$cid = rand(0, 1000);
$contact_form->form = str_replace($search, $search . "\n\n<p>Please enter the text below<br />\n [captchac captcha-{$cid}]<br />\n [captchar captcha-{$cid}]<br /></p>", $contact_form->form);
// Change title
$contact_form->title = isset($options['page_title']) ? $options['page_title'] : __('Contact', 'gd_quicksetup');
if (!empty($email)) {
$contact_form->mail['recipient'] = $email;
}
// Save
$contact_form->save();
// New tag for the contact page
$post_content = '[contact-form-7 id="' . $post->ID . '" title="' . $post->post_title . '"]';
}
// Create a Contact page
wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => $post_content, 'post_name' => 'contact', 'post_title' => isset($options['page_title']) ? $options['page_title'] : __('Contact Us', 'gd_quicksetup'), 'post_type' => 'page', 'post_status' => 'publish', 'menu_order' => 800));
}
示例2: wpcf7_load_contact_form_admin
function wpcf7_load_contact_form_admin()
{
$action = wpcf7_current_action();
if ('save' == $action) {
$id = $_POST['post_ID'];
check_admin_referer('wpcf7-save-contact-form_' . $id);
if (!current_user_can('wpcf7_edit_contact_form', $id)) {
wp_die(__('You are not allowed to edit this item.', 'wpcf7'));
}
if (!($contact_form = wpcf7_contact_form($id))) {
$contact_form = new WPCF7_ContactForm();
$contact_form->initial = true;
}
$contact_form->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' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
$mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], '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' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
$messages = isset($contact_form->messages) ? $contact_form->messages : array();
foreach (wpcf7_messages() as $key => $arr) {
$field_name = 'wpcf7-message-' . strtr($key, '_', '-');
if (isset($_POST[$field_name])) {
$messages[$key] = trim($_POST[$field_name]);
}
}
$additional_settings = trim($_POST['wpcf7-additional-settings']);
$props = apply_filters('wpcf7_contact_form_admin_posted_properties', compact('form', 'mail', 'mail_2', 'messages', 'additional_settings'));
foreach ((array) $props as $key => $prop) {
$contact_form->{$key} = $prop;
}
$query = array();
$query['message'] = $contact_form->initial ? 'created' : 'saved';
$contact_form->save();
$query['post'] = $contact_form->id;
$redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
wp_safe_redirect($redirect_to);
exit;
}
if ('copy' == $action) {
$id = empty($_POST['post_ID']) ? absint($_REQUEST['post']) : absint($_POST['post_ID']);
check_admin_referer('wpcf7-copy-contact-form_' . $id);
if (!current_user_can('wpcf7_edit_contact_form', $id)) {
wp_die(__('You are not allowed to edit this item.', 'wpcf7'));
}
$query = array();
if ($contact_form = wpcf7_contact_form($id)) {
$new_contact_form = $contact_form->copy();
$new_contact_form->save();
$query['post'] = $new_contact_form->id;
$query['message'] = 'created';
} else {
$query['post'] = $contact_form->id;
}
$redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
wp_safe_redirect($redirect_to);
exit;
}
if ('delete' == $action) {
if (!empty($_POST['post_ID'])) {
check_admin_referer('wpcf7-delete-contact-form_' . $_POST['post_ID']);
} elseif (!is_array($_REQUEST['post'])) {
check_admin_referer('wpcf7-delete-contact-form_' . $_REQUEST['post']);
} else {
check_admin_referer('bulk-posts');
}
$posts = empty($_POST['post_ID']) ? (array) $_REQUEST['post'] : (array) $_POST['post_ID'];
$deleted = 0;
foreach ($posts as $post) {
$post = new WPCF7_ContactForm($post);
if (empty($post)) {
continue;
}
if (!current_user_can('wpcf7_delete_contact_form', $post->id)) {
wp_die(__('You are not allowed to delete this item.', 'wpcf7'));
}
if (!$post->delete()) {
wp_die(__('Error in deleting.', 'wpcf7'));
}
$deleted += 1;
}
$query = array();
if (!empty($deleted)) {
$query['message'] = 'deleted';
}
$redirect_to = add_query_arg($query, menu_page_url('wpcf7', false));
wp_safe_redirect($redirect_to);
exit;
}
if (empty($_GET['post'])) {
$current_screen = get_current_screen();
if (!class_exists('WPCF7_Contact_Form_List_Table')) {
require_once WPCF7_PLUGIN_DIR . '/admin/includes/class-contact-forms-list-table.php';
}
add_filter('manage_' . $current_screen->id . '_columns', array('WPCF7_Contact_Form_List_Table', 'define_columns'));
add_screen_option('per_page', array('label' => __('Contact Forms', 'wpcf7'), 'default' => 20, 'option' => 'cfseven_contact_forms_per_page'));
}
}
示例3: wpcf7_admin_add_pages
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 WPCF7_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' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
$mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], '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' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
$messages = $contact_form->messages;
foreach (wpcf7_messages() as $key => $arr) {
$field_name = 'wpcf7-message-' . strtr($key, '_', '-');
if (isset($_POST[$field_name])) {
$messages[$key] = trim($_POST[$field_name]);
}
}
$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($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($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(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($query));
exit;
}
add_menu_page(__('Contact Form 7', 'wpcf7'), __('Contact', 'wpcf7'), WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page');
add_submenu_page('wpcf7', __('Edit Contact Forms', 'wpcf7'), __('Edit', 'wpcf7'), WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page');
}
示例4: wpcf7_admin_add_pages
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 WPCF7_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']), 'upload_failed_php_error' => trim($_POST['wpcf7-message-upload-failed-php-error']));
$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'), WPCF7_ADMIN_READ_CAPABILITY, wpcf7_plugin_path('admin/admin.php'), 'wpcf7_admin_management_page');
wpcf7_add_contact_page(__('Edit Contact Forms', 'wpcf7'), __('Edit', 'wpcf7'), WPCF7_ADMIN_READ_CAPABILITY, wpcf7_plugin_path('admin/admin.php'), 'wpcf7_admin_management_page');
}
示例5: wpcf7_admin_init
function wpcf7_admin_init()
{
if (!wpcf7_admin_has_edit_cap()) {
return;
}
if (isset($_POST['wpcf7-save'])) {
$id = $_POST['post_ID'];
check_admin_referer('wpcf7-save_' . $id);
if (!($contact_form = wpcf7_contact_form($id))) {
$contact_form = new WPCF7_ContactForm();
$contact_form->initial = true;
}
$contact_form->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' => isset($_POST['wpcf7-mail-use-html']) && 1 == $_POST['wpcf7-mail-use-html']);
$mail_2 = array('active' => isset($_POST['wpcf7-mail-2-active']) && 1 == $_POST['wpcf7-mail-2-active'], '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' => isset($_POST['wpcf7-mail-2-use-html']) && 1 == $_POST['wpcf7-mail-2-use-html']);
$messages = isset($contact_form->messages) ? $contact_form->messages : array();
foreach (wpcf7_messages() as $key => $arr) {
$field_name = 'wpcf7-message-' . strtr($key, '_', '-');
if (isset($_POST[$field_name])) {
$messages[$key] = trim($_POST[$field_name]);
}
}
$additional_settings = trim($_POST['wpcf7-additional-settings']);
$props = apply_filters('wpcf7_contact_form_admin_posted_properties', compact('form', 'mail', 'mail_2', 'messages', 'additional_settings'));
foreach ((array) $props as $key => $prop) {
$contact_form->{$key} = $prop;
}
$query = array();
$query['message'] = $contact_form->initial ? 'created' : 'saved';
$contact_form->save();
$query['contactform'] = $contact_form->id;
$redirect_to = wpcf7_admin_url($query);
wp_safe_redirect($redirect_to);
exit;
}
if (isset($_POST['wpcf7-copy'])) {
$id = $_POST['post_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($query);
wp_safe_redirect($redirect_to);
exit;
}
if (isset($_POST['wpcf7-delete'])) {
$id = $_POST['post_ID'];
check_admin_referer('wpcf7-delete_' . $id);
if ($contact_form = wpcf7_contact_form($id)) {
$contact_form->delete();
}
$redirect_to = wpcf7_admin_url(array('message' => 'deleted'));
wp_safe_redirect($redirect_to);
exit;
}
}