如果这不是一个一般的php问题,就不要问舒尔。。。
使用WP_Error
班
// http://php.net/manual/de/function.is-float.php
// http://php.net/manual/de/function.is-int.php
// inside your save_post/update_post hooks callback function,
// just type cast to float. You could also do a check if it contains non numeric chars
// and then simply return;
$check = ! is_float( $value ) OR ! is_int( $value ) ? new WP_Error( \'wrong value\', __(" I\'ve fallen and can\'t get up", \'YOUR_TEXTDOMAIN_STRING\' ), $value ) : $value;
在函数结束时,检查是否有错误。要提供有意义的错误消息,请使用jQuery:
if ( is_wp_error( $check ) )
{
$code = $check->get_error_code();
$msg = $check->get_error_message();
// Maybe multiple? You\'ll have to loop through them
$msgs = $check->get_error_messages();
echo "<script type=\'text/javascript\'>
var error = \'<div id=\\"message\\" class=\\"updated below-h2\\"><p><strong>{$code}</strong> {$msg}</p></div>\';
// Append the error
jQuery( \'#icon-edit\' ).after( error );
</script>";
}