Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可重用的自定义WordPress元框_Php_Wordpress_Meta Boxes - Fatal编程技术网

Php 可重用的自定义WordPress元框

Php 可重用的自定义WordPress元框,php,wordpress,meta-boxes,Php,Wordpress,Meta Boxes,我使用,以便添加自定义元框到我的主题 其中一个要求是我在metabox中有WYSIWYG编辑器 获取该内容的部分代码是: array( 'label' => __('Availability content'), 'desc' => __('Some desc'), 'id' => 'availability_text', 'type' => 'editor' ), 现在,当我保存文章

我使用,以便添加自定义元框到我的主题

其中一个要求是我在metabox中有WYSIWYG编辑器

获取该内容的部分代码是:

array(
        'label' => __('Availability content'),
        'desc'  => __('Some desc'),
        'id'    => 'availability_text',
        'type'  => 'editor'
    ),  
现在,当我保存文章时,metabox中的信息被保存,但它没有格式化,编辑器中的图像也丢失了

为什么会发生这种情况以及如何解决


我注意到它删除了格式,去掉了h1标签等,问题在于位于第333-355行的meta_box_清理功能

我替换了:

default:
return sanitize_text_field( $string );

而且它有效

刚刚发现它也可以这样工作:

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'
        ),
), 

你能和我分享一下你保存在其中的内容吗?这样我就可以重现这个问题了?你的内容在默认的post editor中工作正常吗?@VinodDalvi是的,在post editor中工作正常。我试图保存的内容是格式化文本(标题、段落标记和图像)。此外,我还尝试使用WYSIWYG编辑器构建自己的metabox,效果很好,这让我得出结论,使用来自的自定义metabox进行保存存在问题
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'
        ),
),