Make WordPress Core

Opened 7 years ago

Last modified 39 hours ago

#40958 new defect (bug)

force_balance_tags breaks Ninjaforms and probably other plugins that output html within js.

Reported by: programmin's profile programmin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: Shortcodes Keywords:
Focuses: ui, administration Cc:

Description

If you have a shortcode for Ninjaforms and use the post in a context that runs force_balance_tags() it seriously breaks the script. For example if you have a form id=14, add this :

<?php

echo 'NO BALANCE:--'. apply_filters('the_content', '[ninja_form id=14]' ) .' --END NO BALANCE. ';
echo 'BALANCED:--'. force_balance_tags(apply_filters('the_content', '[ninja_form id=14]' )) .' --END BALANCED. ';

Notice that some ending /spans, /is, and or /as are added before the end script, breaking it. Seems to not be wp version dependent.

Change History (5)

#1 @programmin
7 years ago

It would be nice if there were a filter always applied at the end of the force balance function, for the possibility of cleaning up bugs like this.

#2 @vizvizka
5 weeks ago

remove_filter( 'the_content', 'force_balance_tags' ); Disable force_balance_tags
$content = apply_filters( 'the_content', $content_with_shortcodes );
Process content with shortcodes
add_filter( 'the_content', 'force_balance_tags' ); Re-enable force_balance_tags

function my_ninja_form_shortcode_handler( $atts ) {

return ninja_forms_display_form( array( 'id' => 14 ) ); Replace 14 with your form ID

}
add_shortcode( 'my_ninja_form', 'my_ninja_form_shortcode_handler' );

Last edited 43 hours ago by vizvizka (previous) (diff)

#3 @wpteccho
3 weeks ago


This worked for me

$form_content = apply_filters('the_content', '[ninja_form id=14]');
if (strpos($form_content, '[ninja_form') === false) {
    // Only use force_balance_tags if the content doesn't contain the Ninja Form shortcode
    $balanced_content = force_balance_tags($form_content);
} else {
    $balanced_content = $form_content; // Skip force_balance_tags for forms
}

echo 'BALANCED:--' . $balanced_content . ' --END BALANCED. ';

Last edited 3 weeks ago by wpteccho (previous) (diff)

#4 @dmsnell
2 weeks ago

Does anyone have some example output before and after force-balancing the tags? I've been exploring replacing the internal logic of force_balance_tags() with the HTML API, which should resolve pretty much every problem associated with it, but I want to verify that in this case, that there's not something strange going on with the interplay of the HTML produced by the shortcode.

https://github.com/WordPress/wordpress-develop/pull/7409

Notice that some ending /spans, /is, and or /as are added before the end script, breaking it. Seems to not be wp version dependent.

This is the part I'd love to see, since I don't have a test setup for ninja forms, nor would I know if what I see is what you are seeing.

#5 @joknoce
39 hours ago

Why am I unable to scroll down on pages or tabs in WordPress after clicking a menu item, while the menu scrolls correctly but the list of pages remains static? Could this issue be related to the theme, plugin conflicts, or possibly a CSS/JavaScript issue? How can I resolve this problem?

<