Skip to content

getCurrentUser() REST API request #35599

@truchot

Description

@truchot

Description

Hi,

I'm using WordPress JavaScript packages to get current user infos from a custom settings page with the code below.
All scripts are loaded with the right dependencies and settings by default.
For example wp-api-fetch :

Capture d’écran 2021-10-05 à 20 44 52

Issue identified :
The sent request to the REST API does'nt contain the Root URL mentioned in those settings.

Capture d’écran 2021-10-05 à 20 44 59

Image shows the request sent to the Settings API but I have the same error with User API, it uses care.local/wp/… instead of care.local/wp-json/wp/… at the Root URL level.

Any idea where this problem comes from ?

Step-by-step reproduction instructions

Example of code to get Current User infos :

import { store as coreStore } from "@wordpress/core-data";
import { useSelect } from "@wordpress/data";

function MySettingsPage() {
    const currentUser = useSelect( ( select ) => select( coreStore ).getCurrentUser(), [] );
    console.log( { currentUser } );
    return ( <p>Example page</p> );
}
export default MySettingsPage;

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions