Support » Plugins » wp_delete_user() fails during a wordpress scheduled job

  • I have a plugin that deletes all users from a WordPress installation. The plugin registers a new menu page and when a button is clicked it deletes the users. Here is my code:

    $blogusers = get_users('blog_id=' . $GLOBALS['blog_id'] . '&orderby=nicename');
    foreach ($blogusers as $userToDelete) {

    The above deletes all of the users (except admin) no problem. However, when I put the code into a hook and schedule it, if fails on the first wp_delete_user() code.

    wp_schedule_single_event( time() + 1, 'hook_name' );

    Any reason why you can’t make that call within a scheduled job but it runs fine outside of one?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Please feel free to call me an idiot. Found this in the documentation of the function and now all is good.

    If you wish to use this function in a plugin then you must include the ./wp-admin/includes/user.php file in your plugin function, else it will throw a ‘call to undefined function’ error.

    Just a note that the error isn’t actually thrown for some reason.

    No name-calling here! Thanks for sharing the solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_delete_user() fails during a wordpress scheduled job’ is closed to new replies.