I am trying to use some wordpress function in a script located in the wordpress root directory, just that some of the wordpress functions work others don't: get_users
function works well but wp_delete_user
doesn't. What am I missing? PLugin is out of discussion.
require($_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php");
global $wpdb;
$args = array(
'role' => 'test_taker'
);
$users = get_users( $args ); // This works
//var_dump($users);
foreach ($users as $user) {
//var_dump($user->ID);
wp_delete_user( $user->ID ); // This doesn't work
}
Managed to find the solution. When you get undefined function, that means you need to copy the function into the external file. For example in my case wp_delete_user
needed to copy it from here https://developer.wordpress.org/reference/functions/wp_delete_user/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.