我有一个拥有20多个网站的WordPress多站点网络。我正在使用重力表格进行联系/注册/订阅表格。我想为我的wordpress多站点安装创建全局表单。重力表单是否可能仅将表单条目保存到主/父站点?我试过在儿童网站上使用switch_to_blog()
。但它不工作。任何帮助将不胜感激:)
Gravity表单根据博客数据库表前缀存储数据,
在多站点中,所有站点都使用相同的数据库,但数据基于表前缀分隔,前缀类似于wp_1_,wp_2_,wp_3 _.....
如果您有一个网站,例如带有表格前缀的my.blog1.com,wp_1_,则重力形式将my.blog1.com的所有表单条目存储到wp_1_rg_lead,wp_1_rg_lead_detail,wp_1_rg_lead_detail_long,
现在,如果要在父安装上保存这些详细信息,则需要使用数据库并使用gform_pre_submission
或gform_after_submission
等钩子修改重力形式
这个post可能会帮助http://www.endocreative.com/save-gravity-forms-data-custom-database-table/
如果您将表单复制到所有站点,您可以将它们全部发送到主站点,方法是将其包含在“子站点”中:
$formId = 1; //Put your form id here
add_filter('gform_confirmation_'.$formId, 'gform_confirmation', 10, 4);
function gform_confirmation($confirmation, $form, $entry, $is_ajax) {
//Switch to Main site
switch_to_blog(1);
//Insert the entry into the main site
$new_entry_id = \GFAPI::add_entry($entry);
//Switch back
restore_current_blog();
//Tidy up by deleting the entry from THIS site
$result = GFAPI::delete_entry($entry['id']);
return $confirmation;
}