php - 可重复使用的自定义 WordPress 元框

标签 php wordpress meta-boxes

我正在使用Reusable Custom WordPress Meta Boxes为了将自定义元框添加到我的主题中。

要求之一是我在元框中有所见即所得编辑器。

获取该东西的部分代码是:

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

现在,当我保存帖子时,元框中的信息会被保存但其未格式化,并且编辑器中的图像会丢失

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

我注意到它删除了格式,删除了 p <br> h1标签等

最佳答案

问题出在meta_box_sanitize函数上,位于https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes/blob/master/metaboxes/meta_box.php ,第 333-355 行。

我替换了:

default:
return sanitize_text_field( $string );

default:
return wp_kses_post( $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'
        ),
), 

关于php - 可重复使用的自定义 WordPress 元框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24575614/

相关文章:

php - 获取 Woocommerce 中带有空简短描述的所有产品 ID

php - WordPress 的自定义元框和字段 : Change directory upload based on user-edit page

php - 将WordPress Post Meta保存到数据库不起作用

php - 在 wordpress 插件中使用 zebra_form 时出错

php - 向数据库插入数据的好方法

php - 如何从自动填充随机数字的下拉菜单生成一组文本框?

php - MySQL获取HH :MM之间的时间

php - 使用前端用户插件在 WordPress 中添加带有表单的自定义页面

javascript - 检查 Disqus 插件是否存在

php - ASP.NET 使用 HttpWebRequest 到 Wordpress SSO