加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何使自定义元框支持WordPress中的可视化作曲家?

发布时间:2020-12-13 22:23:36 所属栏目:PHP教程 来源:网络整理
导读:我正在使用视觉作曲家为WordPress的帖子和页面实际上为所有.但我想在帖子编辑器的屏幕下制作一些自定义元框.实际上我已经做了这些领域.但现在我想在视觉作曲家中提供这些字段.实际上我想在可视化编辑器中添加这些字段.我怎样才能做到这一点?请帮助我提供宝
我正在使用视觉作曲家为WordPress的帖子和页面实际上为所有.但我想在帖子编辑器的屏幕下制作一些自定义元框.实际上我已经做了这些领域.但现在我想在视觉作曲家中提供这些字段.实际上我想在可视化编辑器中添加这些字段.我怎样才能做到这一点?请帮助我提供宝贵的知识.

这是我的元框代码

<?php

function myplugin_add_meta_box() {

$screens = array( 'post','page' );

foreach ( $screens as $screen ) {

    add_meta_box(
        'myplugin_sectionid',__( 'My Post Section Title','myplugin_textdomain' ),'myplugin_meta_box_callback',$screen
    );
 }
}
add_action( 'add_meta_boxes','myplugin_add_meta_box' );

function myplugin_meta_box_callback( $post ) {
wp_nonce_field( 'myplugin_save_meta_box_data','myplugin_meta_box_nonce'   );
$value = get_post_meta( $post->ID,'_my_meta_value_key',true );

echo '<label for="myplugin_new_field">';
_e( 'Description for this field','myplugin_textdomain' );
echo '</label> ';
echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="' . esc_attr( $value ) . '" size="25" />';
}

function myplugin_save_meta_box_data( $post_id ) {

if ( ! isset( $_POST['myplugin_meta_box_nonce'] ) ) {
    return;
}

// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonce'],'myplugin_save_meta_box_data' ) ) {
    return;
}

if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    return;
}

// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {

    if ( ! current_user_can( 'edit_page',$post_id ) ) {
        return;
    }

} else {

    if ( ! current_user_can( 'edit_post',$post_id ) ) {
        return;
    }
}

/* OK,it's safe for us to save the data now. */

// Make sure that it is set.
if ( ! isset( $_POST['myplugin_new_field'] ) ) {
    return;
}

// Sanitize user input.
$my_data = sanitize_text_field( $_POST['myplugin_new_field'] );

// Update the meta field in the database.
update_post_meta( $post_id,$my_data );
}
add_action( 'save_post','myplugin_save_meta_box_data' );

解决方法

我看到你正在回应你的领域作为输入.您需要使用 wp_editor()功能.它将为您完成wysiwyg(可视化编辑器)字段创建.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读