Wordpress 5.4 将 <p> 标签插入到 Buddypress activity 提要上的 Javascript 代码中

Wordpress 5.4 inserting <p> tags into Javascript code on Buddypress activity feed

升级到 Wordpress 5.4 后,我们发现它将流氓 <p> 标签插入到 Javascript 代码中,而这些代码之前在我们的 Buddypress activity 提要上工作。

代码包含在对 bp_get_template_part 的调用中:

bp_get_template_part( 'activity/submit-tabs' );

这是来自 Web 检查器的代码示例,显示了这些 roque <p> 标签:

<p><script>
    jQuery(function($) {
        var input = $('#our-activity-action-input');
        var privacy = $('#our-activity-action-privacy');
        var type = $('#our-activity-action-type');
        var button = $('#our-activity-action-button');</p>
<p>        type.change(function() {
            var typeValue = type.val();
            var placeholder = '';</p>
<p>            if (typeValue == 'news') {
                placeholder = 'Enter the URL of a news article you’d like to rate or fact-check.';
            }</p>
<p>            input.attr('placeholder', placeholder);
        });</p>
<p>        button.click(function() {
            var inputValue = input.val().trim();</p>
<p>            if (!inputValue) {
                input.val('').focus();
                return false;
            }</p>
<p>            var submitAction = function() {
                var typeValue = type.val();</p>
<p>                var action;
                var actionInput;
                var actionSubmit;</p>
<p>                if (typeValue == 'news') {
                    action = $('.our-activity-actions .action-news');
                    actionInput = action.find('#af_ournews_url_input');
                    actionSubmit = action.find('#af_ournews_url_submit');
                } else if (typeValue == 'claim') {
                    action = $('.our-activity-actions .action-claim');
                    actionInput = action.find('#af_ournews_url_input_quote');
                    actionSubmit = action.find('#af_ournews_url_submit_quote');
                } else if (typeValue == 'status') {
                    action = $('.our-activity-actions .action-status');
                    actionInput = action.find('#whats-new');
                    actionSubmit = action.find('#aw-whats-new-submit');
                }</p>
<p>                actionInput.val(inputValue);</p>
<p>                actionSubmit.trigger('click');</p>
<p>                if (typeValue == 'status') {
                    input.val('');</p>
<p>                                    }
            };</p>
<p>            var privacyValue = privacy.val();</p>
<p>            var ajaxUrl = 'https://our.news/wp-admin/admin-ajax.php';</p>
<p>            var data = {
                action: 'ours_set_temp_privacy',
                privacy: privacyValue
            };</p>
<p>            button.attr('disabled', true);</p>
<p>            $.post( ajaxUrl, data, function(response) {
                submitAction();</p>
<p>                button.attr('disabled', false);
            });</p>
<p>        });
    });

我们尝试了通常的解决方案,例如将此添加到我们的子主题 functions.php:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

我们更进一步尝试猜测一些 Buddypress 过滤器,但没有成功:

remove_filter( 'bp_get_template_part', 'wpautop');
remove_filter( 'bp_before_has_activities_parse_args', 'wpautop');
remove_filter( 'bp_after_has_activities_parse_args', 'wpautop');

关于如何阻止这种情况发生的任何意见或建议?

好的,我们找到了一个可行的 hacky 解决方法,但必须有更好的方法:

add_filter ('the_content','our_remove_autop',0);
function our_remove_autop($content)
{
    $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    $is_activity = strpos($request_uri, 'activity/',0);
    if ($is_activity)
    {
            remove_filter('the_content','wpautop');
    }
    return $content;
}