0
모든 것이 잘 작동하는 메타 박스를 설정했지만 HTML 또는 실제로 클래스를 허용하려고합니다. 그러나이 작업을 코드화하려고 시도했지만 그렇지 않습니다. 이유가 확실하지 않습니다.WordPress 메타 박스 추가 허용 HTML
내 코드는 다음과 같습니다
나는이 작품을 얻기 위해 변경해야 할 무엇/**
* Adds a box to the main column on the Page edit screens.
*/
function myplugin_add_meta_box() {
$screens = array('page');
foreach ($screens as $screen) {
add_meta_box(
'myplugin_sectionid',
__('Page Intro Text in Header', 'myplugin_textdomain'),
'myplugin_meta_box_callback',
$screen
);
}
}
add_action('add_meta_boxes', 'myplugin_add_meta_box');
/**
* Prints the box content.
*
* @param WP_Post $post The object for the current post/page.
*/
function myplugin_meta_box_callback($post) {
// Add an nonce field so we can check for it later.
wp_nonce_field('myplugin_meta_box', 'myplugin_meta_box_nonce');
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$value = get_post_meta($post->ID, 'pageintro', true);
echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="' . esc_html($value) . '" style="width: 100%;" />';
}
/**
* When the post is saved, saves our custom data.
*
* @param int $post_id The ID of the post being saved.
*/
function myplugin_save_meta_box_data($post_id) {
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
if (! isset($_POST['myplugin_meta_box_nonce'])) {
return;
}
// Verify that the nonce is valid.
if (! wp_verify_nonce($_POST['myplugin_meta_box_nonce'], 'myplugin_meta_box')) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
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;
}
// WP's default allowed tags
global $allowedtags;
// allow iframe only in this instance
$span = array('<span>' => array(
'<span>' => array()
));
$allowed_html = array_merge($allowedtags, $span);
// Sanitize user input.
$my_data = sanitize_text_field($_POST['myplugin_new_field'], $allowed_html);
// Update the meta field in the database.
update_post_meta($post_id, 'pageintro', $my_data);
}
// save the text input
if (isset($_POST['myplugin_new_field'])) {
// Sanitize user input.
$my_data = sanitize_text_field($_POST['myplugin_new_field']);
// Update the meta field in the database.
update_post_meta($post_id, 'pageintro', $my_data);
}
add_action('save_post', 'myplugin_save_meta_box_data');
?
감사합니다. HTML에 대한
'sanitize_text_field ($ _POST [ 'myplugin_new_field'], $의 allowed_html)'이에 확장 할 수있는 나는 그것을 구현할 수있는 방법이 아닌 두 .. – David