也许使用textarea
而不是input
领域当然还有$allowed
不包含iframe
标签当然,您将无法删除保存的video_1
...
这段代码中有太多不太好的地方。
(1)
$values = get_post_custom( $post->ID );
$video1 = isset( $values[\'video_1\'] ) ? esc_attr( $values[\'video_1\'][0] ) : \'\';
替换为
$video1 = get_post_meta($post->ID, \'video_1\', true);
2)
<input type="text" name="video_1" placeholder="Youtube Embed Code" size="75" id="video_1" value="<?php echo $video1; ?>" />
替换为
<textarea name="video_1" placeholder="Youtube Embed Code" style="width:100%" id="video_1"> <?php echo esc_html($video1); ?></textarea>
3)
if( isset( $_POST[\'video_1\'] ) )
替换为
if( isset( $_POST[\'video_1\'] ) && !empty($_POST[\'video_1\']) )
update_post_meta( $post_id, \'video_1\', wp_kses( $_POST[\'video_1\'], $allowed ) );
else
delete_post_meta( $post_id, \'video_1\');
4)
// now we can actually save the data
$allowed = array(
\'a\' => array( // on allow a tags
\'href\' => array() // and those anchords can only have href attribute
)
);
替换为
// now we can actually save the data
$allowed = array(
\'iframe\' => array( // on allow a iframe
)
);