你试过吗http://www.wproots.com/ultimate-guide-to-meta-boxes-in-wordpress/ ? 创建metabox是一个很好的类。但我对验证有问题。
我试过了sanitize_callback
参数来清理URL,所以我使用esc_url
但该字段仍然接受所有值。这里有什么问题?
这是我的密码
add_smart_meta_box( \'themename_slides_url\', array(
\'title\' => __( \'Slides Options\', \'themename\' ),
\'pages\' => array( \'slides\' ),
\'context\' => \'normal\',
\'priority\' => \'high\',
\'fields\' => array(
array(
\'name\' => __( \'Slides URL\', \'themename\' ),
\'id\' => \'slide_url\',
\'default\' => \'\',
\'desc\' => __( \'Type the URL of the slide\', \'themename\' ),
\'type\' => \'text\',
\'sanitize_callback\' => \'themename_sanitize_url\'
),
)
)
)
function themename_sanitize_url( $new, $meta_key, $id ) {
if( esc_url( $new ) )
return $new;
}
有什么想法吗?