I am developing an integration plugin to enable wpDiscuz as the default comment system for Tutor LMS lessons. The primary goal is to replace the default Tutor LMS comment system with wpDiscuz, injecting the comments into the lesson sidebar rather than the main content area. While the integration plugin works well in concept, we have encountered issues related to wc_options
that are preventing the integration from functioning as intended.
Below is an overview of the integration plugin, the specific issues we’re facing, and the insights we’ve gathered from analyzing wpDiscuz’s code. I can send an invite to collaborate in the repo if there are developers of the wpDiscuz team, or any others that have bona fides.
Integration Plugin Overview
The plugin achieves the following:
- Replace Tutor LMS Comments: Deregisters the Tutor LMS comment system on lesson pages and replaces it with wpDiscuz.
- Enable wpDiscuz for the Lesson Post Type: Ensures the
lesson
custom post type is included in thewpdiscuz_post_types
key ofwc_options
. - Inject Comments into Sidebar: Dynamically adds wpDiscuz comments to the lesson sidebar for better visibility and user engagement.
Issues Encountered
-
wc_options
Missing or Malformed:- The
wc_options
entry in thewp_options
table is either missing or does not include thewpdiscuz_post_types
key. - Logs indicate repeated failures to locate or initialize
wpdiscuz_post_types
.
- The
-
wpdiscuz_init_options
Action:- We use the
wpdiscuz_init_options
hook to add thelesson
post type dynamically:add_action('wpdiscuz_init_options', function ($options) { if (!isset($options['wpdiscuz_post_types'])) { $options['wpdiscuz_post_types'] = []; } if (!in_array('lesson', $options['wpdiscuz_post_types'], true)) { $options['wpdiscuz_post_types'][] = 'lesson'; } update_option('wc_options', $options); });
- Despite this, the
lesson
post type does not persist inwc_options
, andwpdiscuz_post_types
remains unset.
- We use the
-
Comments Not Loading:
- Since
wpdiscuz_post_types
is not initialized correctly, the wpDiscuz comments are not loaded for lessons, and Tutor LMS comments are not deregistered.
- Since
Insights from Analyzing wpDiscuz Code
-
wc_options
Management:wc_options
is initialized and validated viaaddOptions()
andinitOptions()
inclass.WpdiscuzOptions.php
.- The
wpdiscuz_post_types
key is essential for enabling wpDiscuz on custom post types likelesson
.
-
Dynamic Updates via Hooks:
- The
wpdiscuz_init_options
action is available for modifyingwc_options
. However, it is unclear:- When this hook is executed during plugin initialization.
- Whether there are constraints on modifying
wc_options
through this hook.
- The
-
Database Behavior:
update_option
is used to persist changes towc_options
. However, it appears that either the changes are overwritten or not saved due to potential conflicts or restrictions in wpDiscuz’s logic.
Questions
To resolve these issues, we would appreciate your insights on the following:
-
How does wpDiscuz manage
wc_options
?- Are there scenarios where
wc_options
is reset or dynamically overwritten, blocking external updates? - Does wpDiscuz validate or restrict updates to
wc_options
made throughupdate_option
?
- Are there scenarios where
-
How should
wpdiscuz_post_types
be updated?- Is the
wpdiscuz_init_options
action the correct method to dynamically add post types likelesson
? - Are there additional steps needed to ensure the
lesson
post type persists inwc_options
?
- Is the
-
Best Practices for Integration:
- What is the recommended way to enable wpDiscuz for custom post types?
- Are there known limitations or conflicts when using wpDiscuz with dynamic post types or integrations like Tutor LMS?
-
Fallback Logic:
- If
wc_options
is missing, does wpDiscuz dynamically enable its features for default post types? If so, is it possible to leverage this for custom post types?
- If
Thank you for your time and assistance! Please let me know if additional details, code snippets, or logs would be helpful for diagnosing the issue.
Regards,
Brandon
Tutor-wpDiscuz Lesson Integration Plugin