Fatal error undefined function get_current_user()

Got fatal error on dpge.ch wordpress site as soon as launching the backend (wp-admin).
Identified to be due to Groups plugin. Bypass possible while deactivating the plugin through ftp by renaming the plugin folder, leaving the site without group access security controls.
Hereby the debug.log extract (site_ID# replaced by mysite) :
[28-Jan-2023 17:36:25 UTC] PHP Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /home/clients/mysite/dpge/wp-includes/capabilities.php:693


Stack trace:
#0 /home/clients/mysite/dpge/wp-content/plugins/groups/lib/access/class-groups-post-access.php(232): current_user_can(‘groups_admin_gr…’)
#1 /home/clients/mysite/dpge/wp-includes/class-wp-hook.php(307): Groups_Post_Access::posts_where(‘ AND dpge_posts…’, Object(WP_Query))
#2 /home/clients/mysite/dpge/wp-includes/plugin.php(235): WP_Hook->apply_filters(‘ AND dpge_posts…’, Array)
#3 /home/clients/mysite/dpge/wp-includes/class-wp-query.php(2653): apply_filters_ref_array(‘posts_where’, Array)
#4 /home/clients/mysite/dpge/wp-includes/class-wp-query.php(3613): WP_Query->get_posts()
#5 /home/clients/mysite/dpge/wp-includes/post.php(2410): WP_Query->query(Array)
#6 /home/clients/mysite in /home/clients/mysite/dpge/wp-includes/capabilities.php on line 693

Updating all relevant plugins did not help. Groups is at level Version 2.17.0 |.
Possibly related to backlevel php still at 7.3.33 and WP 6.0.3. since on a up to date test site 8.2. 1and 6.1.1 the error does not occur. However still a lot of work is pending to upgrade the production site.

Please help.


Comments

9 responses to “Fatal error undefined function get_current_user()”

  1. Hi Dario,

    Obviously as you already know this is not recommended and should be avoided. Personally I wouldn’t recommend it but the final choice is yours.
    What you can do to examine this further is by creating a local clone and then start debugging it. This way you can find when and why is this check being called, and also when does it fail.

    Another thing you should try is to make a new install using the version combinations that have the issue but most importantly, download a WP copy from the official source and not using your hosts any possible software installation features. This way you can be sure that the installations you used are the default ones. The reason I’m mentioning this is because the code line in capabilities.php producing the error, doesn’t match my own installation’s location.

    Kind regards,
    George

  2. Hi Dario,

    FYI, I was unable to reproduce the error you get using the latest versions of
    – WP, Groups, Clone
    on a server running PHP7.3.33.
    This either means that the error is elsewhere or that your host is using a customised PHP version.
    Furthermore, and since version 7.3.33 is below the minimum requirement for WP installations, I think the best option would be to update to at least PHP7.4.

    Kind regards,
    George

    1. Well George. Still puzzling. I updated to PHP 7.4 . No change same crash on CLONE activation. So we upgraded to PHP 8.0.25 and guess what, nothing changes either. In the mean time I could eliminate all notices, warnings and deprecation from the frontend under 8.0. So I am really desperate by now to be able to trace who is the culprit, since you could not reproduce the bug and it does not occur on the test system, and it persists while I desactivate theme mods. Somehow it must be related to filter activation timings.
      Anyhow thanks for your support, it is not your fault if it does not solve the issue.

    2. Finally solved !
      The error is not in DPGE themes, nor in any plugins mods, but in WP CLONE. I was driven crazy until I desactivated all plugins and DPGE themes except GROUPS and CLONE and got the crash, so I concluded there is something wrong with capabilities.php which is part of WP Core. Searching the Web about undefined get_current_user() and capabilites.php I stepped onto an old 2018 forum about anoher plugin recommending the following quick fix I tried by despair putting the following line on top of wp-includes\capabilities.php
      /* D. Ciprut in the hope of catching the fatal error on line 693 according to https://bit.ly/3wOQS7a */
      include_once(ABSPATH . ‘wp-includes/pluggable.php’);
      /**** */
      Surprise, it solves the question and I could backup the site as usual with CLONE keeping GROUPS active. Of course, it needs a dirty patch in a WP-Core php file.

      What do you think ? I checked capabilites.php and pluggable.php from both the prod and test site and they match perfectly ! Any explanation why then the added statement about pluggable.php avoids the crash ? I could only imagine that some other plugin than CLONE (the WP core being at the same level) must include the pluggable.php before capabilities.php does.

      Btw, using CLONE for backup leads to an advertisement to try out the successor product.

      Thanks in advance for any clue.

      Regards

  3. Hey Dario,

    Thanks for the follow-up and your finding.

    I’ll need to run a few tests with Groups, WP Clone and PHP8.2.1 to check if I can replicate the case. Once I have an update, will follow-up here.

    Kind regards,
    George

    1. Very kind of you, George, trying to reproduce the problem. Waiting then for an expected update.

      Fyi however: The theme used in production is a child theme of “pilcrow”. It contains a bunch of GROUPS plugin related php modifications in functions.php including a class in an included WP-Coremods.php. Therefore I suspected this user theme being the culprit. Since the exact same theme is used without impact in the test site, I doubted of my own suspicion. Just to be sure, I tried this morning to activate the parent theme and got exactly the same fatal error in the same code line of the same module than with the user theme. So I can be really sure that the child theme does not pay a role.

      Many regards and thanks in advance,

    2. As an additional information to you I posted a related support request on Clone support forum here: https://bit.ly/3Rrvlej

      Regards

  4. Hello. Thanks for the clue.
    In fact after several trials and errors enabling/disabling plugins and swapping themes in maintenance mode, the offending plugin reveals to be WP Clone being somehow incompatible with Groups Plugin, while both are at the latest known update level, and both coexist well on a test site under PHP8.2.1 and WP6.1.1. but obviously not under PHP7.3.33 and WP6.0.3 in the production site.
    Somehow activating WP Clone makes Groups using get_current_user() at backend page opening time while the function is yet undefined and Groups is checking that the user is in the admin group ! How could I ensure the priority of those two plugins to see if making one of them at earliest priority solves the problem.

    Could you help to solve the issue so I can enable the WP Clone plugin again ? Would be nice.

    Regards

  5. Hi Dario,

    Welcome to our support forum and thanks for sharing your debug.log.

    The error itself relates to a WP Core function which happens to be called by Groups plugin and therefore it should be defined, otherwise there is an issue in your installation or most probably a conflict. Apart from this error, I’m expecting you to have further errors related to that function because it is widely used by WP system.

    The first thing that comes to mind is a priority conflict. Make sure to check your installation for any addons that can alter the way and priority which installed plugins are loaded in general. It is possible that Groups is calling a function that is still not loaded.
    In general, I would recommend you to create a staging clone and disable all plugins but Groups and switch to a default theme after installing it. Then start activating your plugins one-by-one till you reach the one that is responsible.

    Kind regards,
    George

Share