wordpress plugin -> Call to undefined function wp_get_current_user()

后端 未结 9 1822
忘掉有多难
忘掉有多难 2020-12-01 07:58

I\'m trying to get the current user info in my plugin using the func wp_get_current_user(). But am getting Call to undefined function wp_get_current_user()

相关标签:
9条回答
  • 2020-12-01 08:22

    I got the same error message after updating WP. The fix that worked for me is quick and easy:

    Locate capabilities.php in the wp-includes directory (WP 3.8.x). Add the following at the top, after the opening php tag:

    require_once('pluggable.php');
    
    0 讨论(0)
  • 2020-12-01 08:26

    NOT wp-includes but :

    include_once(ABSPATH . "wp-admin/includes/plugin.php");
    
    0 讨论(0)
  • 2020-12-01 08:31

    You can use this,

    <?php
    if(!function_exists('wp_get_current_user')) {
        include(ABSPATH . "wp-includes/pluggable.php"); 
    }
    ?>
    

    this should fix your problem :)

    0 讨论(0)
提交回复
热议问题