• garyoakfrompallettown

    (@garyoakfrompallettown)


    when I use this:

    <?php
        $current_user = wp_get_current_user();
        /**
         * @example Safe usage:
         * $current_user = wp_get_current_user();
         * if ( ! $current_user->exists() ) {
         *     return;
         * }
         */
        echo 'Username: ' . $current_user->user_login . '<br />';
        echo 'User email: ' . $current_user->user_email . '<br />';
        echo 'User first name: ' . $current_user->user_firstname . '<br />';
        echo 'User last name: ' . $current_user->user_lastname . '<br />';
        echo 'User display name: ' . $current_user->display_name . '<br />';
        echo 'User ID: ' . $current_user->ID . '<br />';
    ?>

    it gives me a “PHP Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /home/gary/public_html/test.php:2”

    I’m going to try on a fresh KUSANAGI instance, the error happens on my fairly modified centOS 7.

    Will post results.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter garyoakfrompallettown

    (@garyoakfrompallettown)

    I just tested a on freshly deployed / provisionned KUSANAGI instance and the issue happens also, see > https://onrkusadev.com/test.php

    Are you calling it from within WordPress, after initialization?

    Moderator bcworkz

    (@bcworkz)

    You don’t say where you placed your code. You’re probably calling it too early. The use of wp_get_current_user() should be within a filter or action callback that is called during or after the “init” action. Such code can also occur on a theme template, which is also called after “init” action.

    If you are using a filter or action hook, echoing out data may not be effective at all, or the output could occur in an undesirable place or time. If you are going to use a theme template with your code, you should create a child theme. All custom code should be in either a child theme or a plugin, unless you’ve written your own theme.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘outputing | wp_get_current_user() | to a json’ is closed to new replies.