admin管理员组文章数量:1023782
Trying to delete users from the frontend - which I currently have working. Previously, I was manually deleting the metadata when it was completed.
I was looking to see if it was possible to delete all associated to the now non-existent user ID.
I tried finding anything about looping the delete_user_meta($user_id, *)
but couldn't with how to match the key.
I found this:
DELETE FROM wp_usermeta WHERE NOT EXISTS ( SELECT * FROM wp_users WHERE wp_usermeta.user_id = wp_users.ID )
But is there then a way to have it get the wp_
table prefix.
This is the way I am deleting from the frontend after the $_POST and validation:
if( $mb_user_delete ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$user_delete_id = wp_delete_user( $user_id );
if( !is_wp_error($user_delete_id) ) {
delete_user_meta( $user_id, '' );
die( 'User has been successfully deleted' );
} else {
die( $user_delete_id->get_error_message() );
}
}
Trying to delete users from the frontend - which I currently have working. Previously, I was manually deleting the metadata when it was completed.
I was looking to see if it was possible to delete all associated to the now non-existent user ID.
I tried finding anything about looping the delete_user_meta($user_id, *)
but couldn't with how to match the key.
I found this:
DELETE FROM wp_usermeta WHERE NOT EXISTS ( SELECT * FROM wp_users WHERE wp_usermeta.user_id = wp_users.ID )
But is there then a way to have it get the wp_
table prefix.
This is the way I am deleting from the frontend after the $_POST and validation:
if( $mb_user_delete ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$user_delete_id = wp_delete_user( $user_id );
if( !is_wp_error($user_delete_id) ) {
delete_user_meta( $user_id, '' );
die( 'User has been successfully deleted' );
} else {
die( $user_delete_id->get_error_message() );
}
}
Share
Improve this question
asked Apr 10, 2019 at 10:03
markbmarkb
2996 silver badges18 bronze badges
2
|
1 Answer
Reset to default 2No need to find and delete user meta explicitly, because when you remove a WordPress user using wp_delete_user()
, it deletes user and, Posts and all meta is also be deleted that are for that User ID..
Documentation
Trying to delete users from the frontend - which I currently have working. Previously, I was manually deleting the metadata when it was completed.
I was looking to see if it was possible to delete all associated to the now non-existent user ID.
I tried finding anything about looping the delete_user_meta($user_id, *)
but couldn't with how to match the key.
I found this:
DELETE FROM wp_usermeta WHERE NOT EXISTS ( SELECT * FROM wp_users WHERE wp_usermeta.user_id = wp_users.ID )
But is there then a way to have it get the wp_
table prefix.
This is the way I am deleting from the frontend after the $_POST and validation:
if( $mb_user_delete ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$user_delete_id = wp_delete_user( $user_id );
if( !is_wp_error($user_delete_id) ) {
delete_user_meta( $user_id, '' );
die( 'User has been successfully deleted' );
} else {
die( $user_delete_id->get_error_message() );
}
}
Trying to delete users from the frontend - which I currently have working. Previously, I was manually deleting the metadata when it was completed.
I was looking to see if it was possible to delete all associated to the now non-existent user ID.
I tried finding anything about looping the delete_user_meta($user_id, *)
but couldn't with how to match the key.
I found this:
DELETE FROM wp_usermeta WHERE NOT EXISTS ( SELECT * FROM wp_users WHERE wp_usermeta.user_id = wp_users.ID )
But is there then a way to have it get the wp_
table prefix.
This is the way I am deleting from the frontend after the $_POST and validation:
if( $mb_user_delete ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$user_delete_id = wp_delete_user( $user_id );
if( !is_wp_error($user_delete_id) ) {
delete_user_meta( $user_id, '' );
die( 'User has been successfully deleted' );
} else {
die( $user_delete_id->get_error_message() );
}
}
Share
Improve this question
asked Apr 10, 2019 at 10:03
markbmarkb
2996 silver badges18 bronze badges
2
- "But is there then a way to have it get the wp_ table prefix." - yes, you can get the prefix or the complete table names from the $wpdb object. – Rup Commented Apr 10, 2019 at 10:06
-
You can get all metadata keys that exist for a user with
get_metadata
. But I'd be surprised if you needed to: I'd have expected wp_usermeta to FKR back to the user table. If the user still exists there but is flagged deleted why do you need to delete the metadata? – Rup Commented Apr 10, 2019 at 10:08
1 Answer
Reset to default 2No need to find and delete user meta explicitly, because when you remove a WordPress user using wp_delete_user()
, it deletes user and, Posts and all meta is also be deleted that are for that User ID..
Documentation
本文标签: multisiteDelete all user39s meta without knowing all the 39key39
版权声明:本文标题:multisite - Delete all user's meta without knowing all the 'key' 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745605866a2158724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_metadata
. But I'd be surprised if you needed to: I'd have expected wp_usermeta to FKR back to the user table. If the user still exists there but is flagged deleted why do you need to delete the metadata? – Rup Commented Apr 10, 2019 at 10:08