在更新元信息之前,在wordpress仪表板的edit-user.php中,我正在检查一种情况,一旦发生这种情况,我想显示一条错误消息。我试图用更新的类来回显div,还尝试了WP admin_notices钩子,但是没有运气
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
global $wpdb;
if(CONDITION TRUE) {
update_usermeta( ........... );
}
else {
WANT TO DISPLAY ERROR MESSAGE
}
}
有一个钩子用于验证用户多余的字段。此挂钩将在更新用户详细信息之前调用。
您可以显示以下错误消息:-
add_action( 'user_profile_update_errors', 'validate_extra' );
function validate_extra(&$errors, $update = null, &$user = null)
{
if (!$_POST['YOUR_FIELD'])
{
$errors->add('YOUR_FIELD', "<strong>ERROR</strong>: YOUR ERROR MESSAGE.");
}
}
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id )
{
global $wpdb;
update_usermeta( ........... );
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句