Notifications
Clear all

Issue with add inline feedback forms to each paragraph.

2 Posts
2 Users
0 Reactions
53 Views
Posts: 1
Topic starter
(@masstack)
New Member
Joined: 2 weeks ago

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

  1. Function Behavior:

    • The addInlineFeedbackToParagraphs function is designed to wrap each paragraph in a post with the wpdiscuz-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 using do_shortcode().
  2. 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 via do_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.
  3. 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.
  4. 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 or do_shortcode() processing.
  5. Request for Assistance:

    • Guidance on whether the wpdiscuz-feedback shortcode supports dynamic execution via do_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.

Thank you for your support!

1 Reply
Astghik
Posts: 6068
Admin
(@astgh)
Illustrious Member
Joined: 7 years ago

Hi,

Please note all questions related to the free wpDiscuz plugin should be asked in the wpDiscuz.com forum. Here we only support issues related to paid addons.      

Reply
Share:
Scroll to top