The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Allow and tags | Do...
 
Share:
Notifications
Clear all

[Solved] Allow and tags | Do not remove classes on edit

10 Posts
3 Users
0 Reactions
1,706 Views
Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

I have a custom made suggestion system on my site that shows you a colored diff to the original text. I just append it to the comment form per JavaScript. This works, albeit the the auto formatting causes some inconsistencies.

Anyway, there are two major problems. The first one, as in the title, is that the <ins> and <del> tags are filtered out. Which baffles me since they are content tags that do no harm. I need to mark the inserted and deleted texts. Right now, I misappropriate the sup/sub tags for that and add a class to style them as I like.

Which leads me to the second problem. When you edit the comment, the CSS classes get stripped and the whole formatting is gone. I either would like for that not to happen or allow more content tags I can safely use.

Screen Shot 2021 08 14 at 12.30.03
Screen Shot 2021 08 14 at 12.30.24
9 Replies
Posts: 129
Support
(@jacob)
Estimable Member
Joined: 9 years ago

Hi @tetrakern

Read this doc please - https://wpdiscuz.com/docs/codex/filters/wpdiscuz_allowedtags/

You can add custom tags with its attributes using the hook provided in this doc.

Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

Unfortunately, this doesn't work. Provided I did it right.

add_filter( "wpdiscuz_allowedtags", function ( $allowedtags ) {
  $allowedtags["ins"] = true;
  $allowedtags["del"] = true;
  return $allowedtags;
});

The visual editor will reject or rather vandalize the appended HTML, remove all tags including their content and only leave a plain block. I didn't test it for the non-visual editor but that's not what I want to use. I think the Quill Editor does not care for the allowed tags by this filter.

1 Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7661

@tetrakern,

Please use this code:

add_filter( "wpdiscuz_allowedtags", function ( $allowedtags ) {
  $allowedtags["ins"] = true;
  $allowedtags["del"] = true;
  return $allowedtags;
});
add_action("wpdiscuz_front_scripts", function ($options) {
    if ($options->form["richEditor"] === "both" || (!wp_is_mobile() && $options->form["richEditor"] === "desktop")) {
        if ($options->general["loadComboVersion"]) {
            wp_add_inline_script("wpdiscuz-combo-js", quillAddNewTagSupport(), "after");
        } else {
            wp_add_inline_script("quill", quillAddNewTagSupport(), "after");
        }
    }
});
function quillAddNewTagSupport() {
    ob_start();
    ?>
    let Inline = Quill.import('blots/inline');
    class wpdQuillDel extends Inline {}
    wpdQuillDel.blotName = 'del';
    wpdQuillDel.tagName = 'DEL';
    Quill.register(wpdQuillDel, true);
    class wpdQuillIns extends Inline {}
    wpdQuillIns.blotName = 'ins';
    wpdQuillIns.tagName = 'INS';
    Quill.register(wpdQuillIns, true);
    <?php
    return ob_get_clean();
}

It should work fine. 

Please don't forget to delete all kind of caches before checking. 

Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

Thank you for the effort; seems to be more involved than one might expect. Unfortunately, it still doesn't work. The ql-editor still sanitizes the tags away -- I could not test if they are saved and loaded, obviously.

I did clear all caches I could think of, deactivated any plugins like WP Super Cache and Autoptimize to be sure, turned wpDiscuz off and on, cleared the browser data, hard reloaded, used a different browser, used a different computer, used a different WordPress installation on a live test server.

I'm to 99% sure it was not a caching issue.

1 Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7661

@tetrakern,

Have you put the code in the functions.php file? We've checked the code several times, it works fine in our case. 

Please note the code works only for <del> u <ins> tags. Probably you've not tested for those tags. 

Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

It is inside the functions.php and I did test it for <del> and <ins>. After all, that's how the diff-match-patch script works.

What the script is trying to append:

Screen Shot 2021 09 06 at 10.42.29

What appears:

Screen Shot 2021 09 06 at 10.43.25

I also get "Uncaught ReferenceError: Quill is not defined". This might be the issue.

Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

Yep, I think I found the error. It's Autoptimize that aggregates all scripts and apparently causes the script to be executed before it is ready. Or whatever. I turned it off before and it changed nothing, but oh well. I'll find a solution for that myself. Thanks for the help.

Tetrakern
Posts: 18
Topic starter
(@tetrakern)
Eminent Member
Joined: 5 years ago

For those who might encounter a similar problem with the plugin: add "wp-content/plugins/wpdiscuz" to the "Exclude scripts from Autoptimize" list.

1 Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7661

Thank you for sharing the solution. 

Share: