ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-11 16:31:05  阅读:130  来源: 互联网

标签:wordpress php meta-boxes


我正在使用视觉作曲家为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_meta_value_key', $my_data );
}
add_action( 'save_post', 'myplugin_save_meta_box_data' );

解决方法:

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

标签:wordpress,php,meta-boxes
来源: https://codeday.me/bug/20190711/1433762.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有