• Resolved guitarblast

    (@guitarblast)


    I have a script for importing articles into a WordPress multisite. It’s a custom PHP script that is called directly from the command line and require wp-load.php at the very beginning to load the WordPress core.

    For each article to be imported, the switch_to_blog() function is called to import the article into the correct site. The problem with wpdiscuz is that each time a post is created on a site other than the main site, the comment form disappears for all the articles on that site. To make it reappear, we have to save the wpdiscuz_form post again.

    To resolve the issue within the import script, I have to reset WpdiscuzOptions->formContentTypeRel before each post, like this:

    wpDiscuz()->options->formContentTypeRel = get_option("wpdiscuz_form_content_type_rel", []);

    Here are the traces of what I observed while debugging this issue.

    When the plugin loads, the WpdiscuzOptions->initFormRelations() method is called, which initializes WpdiscuzOptions->formContentTypeRel with a value from the main site. When switch_to_blog() is executed, this data is not reloaded to obtain the value for the site which has become the current site. Because of this, we end up executing the line unset($contentRel[$postType][$lang]); in the Form->setFormID() method, which causes comments to stop displaying on the article’s site until we save the wpdiscuz_form post of that site again.

    I think the permanent fix in wpdiscuz should be to add a hook on switch_blog to reset the value of WpdiscuzOptions->formContentTypeRel each time a blog switch occurs.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support gVectors Support

    (@gvectorssupport)

    Hi,

    Please add this code in the active theme’s functions.php file:

    add_action('switch_blog', function ($new_blog_id, $prev_blog_id, $switch) {
    if (function_exists('wpdiscuz')) {
    wpDiscuz()->getOptions()->formContentTypeRel = get_option("wpdiscuz_form_content_type_rel", []);
    wpDiscuz()->getOptions()->formPostRel = get_option("wpdiscuz_form_post_rel", []);
    }
    }, 10, 3);

    Thread Starter guitarblast

    (@guitarblast)

    Hi,

    Thanks for the function. Is it possible for your team to include this fix in your plugin? It will certainly save others from experiencing the same problem and spending several hours searching for the cause and the solution.

    Plugin Support gVectors Support

    (@gvectorssupport)

    Hi,

    It has been added in the latest version of the wpDiscuz plugin.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Bug report: Comment form disappears in multisite’ is closed to new replies.