maddisondesigns / customizer-custom-controls

WordPress Customizer Custom Controls
403 stars 120 forks source link

TinyMCE Custom Control #13

Closed troytempleman closed 5 years ago

troytempleman commented 5 years ago

Hi Anthony,

These customizer controls are fantastic!

For the TinyMCE control, paragraph tags aren't automatically inserted as they are in a default WordPress Text widget and have to be manually added in the Text/HTML tab, which is not ideal. Do you know how to fix this?

Thanks!

troytempleman commented 5 years ago

Actually, I just fixed it by setting wpautop: false on line 328 of customizer.js

maddisondesigns commented 5 years ago

Hi Troy,

Thanks for the kind words. I'm glad you've found these controls useful.

I had to do a little investigation as to why I was doing it like this. The short answer is, I'm setting that wpautop value to true because that's exactly how the Text Widget works, so I wanted to keep it consistent with that.

If you have a look at WordPress core, you can see how they initialise the Text widget here - https://github.com/WordPress/WordPress/blob/master/wp-admin/js/widgets/text-widgets.js#L265

When setting that value to false the TinyMCE field value will be saved with <p> tags, and when it's true, it's simply saved with CR/LF's. You can also noticed this difference just by switching to the Text tab.

Rather than changing that value to false, what you can simply do is run your field value through wpautop(). So, rather than doing:

echo get_theme_mod( 'my_tinymce_editor', '' );

you can do:

echo wpautop( get_theme_mod( 'my_tinymce_editor', '' ) );

This will basically give you same result and will add the <p> tags around your lines, where they're needed.

I hope this helps.

troytempleman commented 5 years ago

Hey Anthony,

Thanks for the quick response and thorough explanation. I put it back to true and did what you suggested as I like to be consistent with WordPress too :)