skip to Main Content

I am getting error while running a function get_users() in my custom plugin

PHP Fatal error: Uncaught Error: Call to undefined function cache_users() in /Users/priyankgohil/sites/upw-new/wp-includes/class-wp-user-query.php:843

Stack trace:
#0 /Users/priyankgohil/sites/upw-new/wp-includes/class-wp-user-query.php(79): WP_User_Query->query()
#1 /Users/priyankgohil/sites/upw-new/wp-includes/user.php(763): WP_User_Query->__construct(Array)
#2 /Users/priyankgohil/sites/upw-new/wp-content/plugins/my-plugin/Inc/BaseController.php(214): get_users(Array)

is anyone have solution or facing same issue after upgrade to wordpress 6.1

4

Answers


  1. Until this gets fixed, you can add the following above line 843 of wp-includes/class-wp-user-query.php:

    if ( ! function_exists( 'cache_users' ) ) {
        require_once ABSPATH . WPINC . '/pluggable.php';
    }
    

    This function looks like it was introduced in the new version, and the code (in other areas) appears to check for functions within pluggable.php before requiring the file.

    Login or Signup to reply.
  2. I solved this problem in the following way:

    1. Download latest wordpress file from https://wordpress.org/download/
    2. Zip all files & folders except wp-content folder and wp-config.php file selected files & folder to be zipped
    3. upload zipped file created at step 2 to root directory of site
    4. Unzip and replace all files and folders

    I made a video on Youtube hope it can help: https://www.youtube.com/watch?v=uTs0WBOOMew

    Login or Signup to reply.
  3. It can be patched from a must-use plugin. Add a new file at /wp-content/mu-plugins/cache-users.php and add this to it:

    <?php
    /**
     * cache_users() Polyfill
     *
     * Patch for issues with WP_User_Query in WP 6.1
     */
    if ( ! function_exists( 'cache_users' ) ) {
      function cache_users( $results ) {
        return $results;
      }
    }
    

    That will safely patch the issue without modifying the WordPress core files until it’s resolved in a follow-up release. It’s bypassing the cache which isn’t ideal, but it resolves any fatal errors reliably.

    Login or Signup to reply.
  4. To include the fix in your own plugin code, try this (worked for me)

    add_action('pre_get_users','fix_cache_users_bug');
    
    function fix_cache_users_bug($query) {
        if ( ! function_exists( 'cache_users' ) ) {
            require_once ABSPATH . WPINC . '/pluggable.php';
        }   
    }
    
    

    I’d suggests that’s better than hacking core files.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search