Description: I am developing a custom feature for a WordPress site that integrates with the wpDiscuz plugin. The goal is to add inline feedback forms to each paragraph of a post using the wpdiscuz-feedback
shortcode. While the shortcode works correctly when used directly in post content, it does not function properly when invoked programmatically through my custom function addInlineFeedbackToParagraphs
.
function addInlineFeedbackToParagraphs($content) { global $post; // Ensure this only applies to single post views where comments are open if (!is_single() || !comments_open($post->ID)) { return $content; } // Split content by paragraphs $paragraphs = explode('</p>', $content); foreach ($paragraphs as $index => $paragraph) { if (trim($paragraph)) { // Create a unique ID for each paragraph $unique_id = 'inline-' . $post->ID . '-' . $index; // Wrap each paragraph with wpDiscuz feedback shortcode $paragraphs[$index] = '[wpdiscuz-feedback id="' . $unique_id . '" question="Please leave a feedback on this" opened="0"]' . $paragraph . '</p>[/wpdiscuz-feedback]'; } } // Reassemble the content return implode('', $paragraphs); } // Hook the function to 'the_content' filter add_filter('the_content', 'addInlineFeedbackToParagraphs');
Problem Details
-
Function Behavior:
- The
addInlineFeedbackToParagraphs
function is designed to wrap each paragraph in a post with thewpdiscuz-feedback
shortcode to display a feedback form for each paragraph. - The function is hooked to
the_content
filter and iterates through each paragraph, applying the shortcode dynamically usingdo_shortcode()
.
- The
-
Observations from Debugging:
- The function executes correctly and iterates through the paragraphs.
- The
wpdiscuz-feedback
shortcode is applied successfully when added manually to post content but fails when invoked viado_shortcode()
within my function. - The error log shows repeated messages of "No feedback form applied for paragraph X", indicating the shortcode is not processed as expected when dynamically inserted.
-
Debugging Steps Taken:
- Verified that the conditions to apply the shortcode (
wpDiscuz
loaded, comments open, user permissions) are correctly met. - Confirmed that
do_shortcode()
is correctly invoked and returns the expected content format. - Checked for potential conflicts with multiple hooks or filters, ensuring the function only runs during the main query.
- Added extensive logging to track each step and outcome within the
addInlineFeedbackToParagraphs
function.
- Verified that the conditions to apply the shortcode (
-
Potential Causes Considered:
- Plugin settings or configuration preventing dynamic shortcode processing.
- A bug or limitation in the
wpdiscuz-feedback
shortcode when used programmatically versus manually. - Conflict with another filter or plugin interfering with the
the_content
filter ordo_shortcode()
processing.
-
Request for Assistance:
- Guidance on whether the
wpdiscuz-feedback
shortcode supports dynamic execution viado_shortcode()
in custom functions. - Any known limitations, conflicts, or alternative methods to achieve inline feedback functionality for each paragraph.
- Suggestions for debugging steps or configurations to check that may resolve this issue.
- Guidance on whether the
Thank you for your support!