• I’m getting the following error when enabling this plugin:

    AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /var/www/vhosts/domain.com/httpdocs/wp-includes/capabilities.php:590\nStack trace:\n#0 /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/hwp-utility-plugin/hwp-utility.php(121): current_user_can('administrator')\n#1 /var/www/vhosts/domain.com/httpdocs/wp-includes/class-wp-hook.php(286): hwp_pre_user_query(Object(WP_User_Query))\n#2 /var/www/vhosts/domain.com/httpdocs/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)\n#3 /var/www/vhosts/domain.com/httpdocs/wp-includes/plugin.php(515): WP_Hook->do_action(Array)\n#4 /var/www/vhosts/domain.com/httpdocs/wp-includes/class-wp-user-query.php(576): do_action_ref_array('pre_user_query', Array)\n#5 /var/www/vhosts/domain.com/httpdocs/wp-includes/class-wp-user-query.php(77): WP_User_Query->prepare_query(Array)\n#6 /var/www/vhosts/domain.com/httpdocs/wp-includes/user.php(561): WP_User_Query->__construct(Arr...\n'

    Here is the relevant plugin code that uses ‘current_user_can’ – causes a white screen when WPFC is enabled and user is logged out:

    /**
      * Hide Administrator from User list
      */
    add_action( 'pre_user_query', 'hwp_pre_user_query' );
    function hwp_pre_user_query( $user_search ) {
        if ( !current_user_can( 'administrator' ) ) { // Is Not Administrator - Remove Administrator
            global $wpdb;
    
            $user_search->query_where = str_replace(
                'WHERE 1=1', 
                "WHERE 1=1 AND {$wpdb->users}.ID IN (
                  SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta 
                  WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
                  AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%' )", 
                $user_search->query_where
            );
        }
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP Fatal error: Uncaught Error: Call to undefined function wp_get_current_user(’ is closed to new replies.