2
votes

Im using Reusable Custom WordPress Meta Boxes in order to add custom meta boxes to my theme.

One of the requirements is that i have WYSIWYG Editor in metabox.

Part of the code to get that thing is:

array(
        'label' => __('Availability content'),
        'desc'  => __('Some desc'),
        'id'    => 'availability_text',
        'type'  => 'editor'
    ),  

Now when I save post, information in metabox is saved but its not formatted and images that were in editor are lost.

Why that could happen and how to solve it?

I noticed that it removes formatting, strips out p <br> h1 tags etc

1
Could you please share me the content that you are saving in to it so that i can reproduce the issue? - Vinod Dalvi
Is your content working fine in the default post editor? - Vinod Dalvi
@VinodDalvi yes it is working fine in post editor. The content that I'm trying to save is formatted text (heading, paragraph tags and images). Also I have tried to build my own metabox with WYSIWYG editor and it works fine, which leaves me with conclusion that there is problem with saving with custom metaboxes from github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes - RhymeGuy

1 Answers

2
votes

Problem is with meta_box_sanitize function, located at https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes/blob/master/metaboxes/meta_box.php, line 333-355.

I replaced:

default:
return sanitize_text_field( $string );

with

default:
return wp_kses_post( $string );

And it works!

Just discovered that it would also work this:

array(
        'label' => __('Availability content'),
        'desc'  => __('Some desc'),
        'id'    => 'availability_text',
        'type'  => 'editor',
        'sanitizer' => array( // array of sanitizers with matching kets to next array
            'type' => 'wp_kses_post'
        ),
),