Gravity Forms在子网站创建时创建Feed

时间:2017-06-16 07:56:44

标签: wordpress gravity-forms-plugin feeds multisite

我正在尝试在子网站创建时导入一些带有Feed的表单。我导出了feed并在代码中粘贴了sql,但是当我尝试执行它时,我得到“没有这样的表存在”错误。该表肯定存在,但我认为它不是在钩子触发时创建的。我已经包含了gravityforms feed addon和init。没有帮助;

 <?php

add_action('wpmu_new_blog', 'add_forms', 10, 6); // trigger when site is created

function add_forms($blog_id, $user_id, $domain, $path, $site_id, $meta) {

    switch_to_blog($blog_id);


    import_forms_on_loaded('/forms/primary-forms.json'); //import 1st forms set
    import_primary_feeds(); //import the feeds

    $import_additional = true; //some bool to define whether additional forms be created

    if ($import_additional) {
        import_forms_on_loaded('/forms/additional-forms.json'); //import 2nd forms set
        import_additional_feeds(); //import the feeds
    }


    restore_current_blog();
}

function import_primary_feeds() {

    $sql = "INSERT INTO %s (id, form_id, is_active, feed_order, meta, addon_slug) VALUES " .
            "(1, 1, 1, 0, '{\"feedName\":\"PayDock Donate Create Customer Feed\",\"mappedFields_first_name\":\"7.3\",\"mappedFields_last_name\":\"7.6\",\"mappedFields_email\":\"1\",\"mappedFields_phone\":\"8\",\"mappedFields_total\":\"19\",\"feed_condition_conditional_logic\":\"0\",\"feed_condition_conditional_logic_object\":[]}', 'gfpaydock')," .
            "(2, 2, 1, 0, '{\"feedName\":\"PayDock Donate Charge Customer Feed \",\"paymentDescription\":\"Single Payment\",\"transactionType\":\"product\",\"paymentAmount\":\"3\",\"feed_condition_conditional_logic\":\"0\",\"feed_condition_conditional_logic_object\":[]}', 'gfpaydockchargecustomer')," .
            "(3, 3, 1, 0, '{\"feedName\":\"PayDock Donate Recurrent Charge Customer Feed\",\"paymentDescription\":\"Recurrent Payment\",\"transactionType\":\"subscription\",\"recurringAmount\":\"3\",\"billingCycle_length\":\"1\",\"billingCycle_unit\":\"month\",\"transaction_end\":\"\",\"transaction_end_value\":\"\",\"feed_condition_conditional_logic\":\"0\",\"feed_condition_conditional_logic_object\":[]}', 'gfpaydockchargecustomer');";
    import_feeds($sql);
}

function import_additional_feeds() {

    $sql = "INSERT INTO %s (id, form_id, is_active, feed_order, meta, addon_slug) VALUES " .
            "(4, 5, 1, 0, '{\"feedName\":\"PayDock Membership Create Customer Feed \",\"mappedFields_first_name\":\"5.3\",\"mappedFields_last_name\":\"5.6\",\"mappedFields_email\":\"8\",\"mappedFields_phone\":\"7\",\"mappedFields_total\":\"37\",\"feed_condition_conditional_logic\":\"0\",\"feed_condition_conditional_logic_object\":[]}', 'gfpaydock')," .
            "(5, 6, 1, 0, '{\"feedName\":\"PayDock Membership Charge Customer Feed\",\"paymentDescription\":\"Membership Payment\",\"transactionType\":\"subscription\",\"recurringAmount\":\"3\",\"billingCycle_length\":\"1\",\"billingCycle_unit\":\"year\",\"transaction_end\":\"\",\"transaction_end_value\":\"\",\"feed_condition_conditional_logic\":\"0\",\"feed_condition_conditional_logic_object\":[]}', 'gfpaydockchargecustomer');";

    import_feeds($sql);
}

function import_feeds($sql) {
    if (!class_exists('GFForms')) {
        return;
    }
    GFForms::init();
    GFForms::include_feed_addon_framework();

    if (!class_exists('GFFeedAddOn')) {
        return;
    }

    global $wpdb;
    $feed_table = $wpdb->prefix . 'gf_addon_feed';

    $result = $wpdb->get_results(sprintf($sql, $feed_table));
    return $result;
}

?>

我没有使用表单创建常量,因为我需要导入几个文件。

1 个答案:

答案 0 :(得分:0)

问题解决了。要强制创建表,您必须通过扩展GFFeedAddOn并调用父进程的init方法来创建自己的空插件对象:

全球代码中的某个地方:

class EmptyAddon extends GFFeedAddOn { //an empty class required to import the GF Feeds

        function __construct() {
            parent::init();
        }

    }

在启动插件功能的函数中:

if (!class_exists('GFForms')) {
    return;
}

GFForms::init();
GFForms::include_feed_addon_framework();

if (!class_exists('GFFeedAddOn')) {
    return;
}

$emptyAddonObj = new EmptyAddon();