programing

워드프레스에서 비주얼 작곡가를 위한 맞춤 메타박스 지원을 만드는 방법은?

yellowcard 2023. 10. 17. 20:09
반응형

워드프레스에서 비주얼 작곡가를 위한 맞춤 메타박스 지원을 만드는 방법은?

저는 워드프레스 게시물과 페이지에 전체적으로 비주얼 작곡가를 사용하고 있습니다.하지만 포스트 에디터 화면 아래에 맞춤 메타박스를 만들고 싶습니다.사실 저는 이미 밭을 일구었습니다.하지만 이제는 그 분야들을 시각적 작곡가들이 이용할 수 있도록 하겠습니다.사실 저는 그 필드들을 시각 편집기에 추가하고 싶습니다.내가 어떻게 그럴 수 있을까?당신의 귀중한 지식을 도와주시기 바랍니다.

메타박스의 코드는 여기 있습니다.

<?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() 기능을 사용해야 합니다.위지윅(시각 편집기) 필드 작성을 대신 처리해 드립니다.

언급URL : https://stackoverflow.com/questions/32270907/how-to-make-the-custom-meta-boxes-support-for-the-visual-composer-in-wordpress

반응형