wordpress plugin -> Call to undefined function wp_get_current_user()

后端 未结 9 1872
忘掉有多难
忘掉有多难 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:12

    As crazy as this might sound, the problem in my application was happening because I had a FILE called menu.php where I had a class to create Wordpress menus.

    Literally, simply changing the name of the FILE from menu.php to nav-menu.php, fixed the issue. I replicated the issue 3 times because I could not believe the name of the FILE could be the problem.

    Just in case somebody would like to now what was inside that file, here it is:

    class OwNavMenu extends OwCpnt 
    {
        function __construct( $location, $args ) {
            $show = $args['show'];
            $span = $args['span'];   
    
            if ( $show ) {
                $this->menu( $location, $span );
            }     
        }
    
        function menu( $location, $span ) {
            if ( $location ) {
                echo '
    '; wp_nav_menu( array( 'theme_location' => $location, 'link_before' => ( $span ) ? '' : '', 'link_after' => ( $span ) ? '' : '' ) ); echo '
    '; } } }

提交回复
热议问题