How to use apiFetch to get author information in Gutenberg properly?

Finally, I found out how to do it. Just call fetchApi in componentDidMount and then create a new state in your component and add the response to this state when the request is done: constructor(props) { super(props); this.state = { data: {}, }; } componentDidMount() { apiFetch( { path: ‘/wp/v2/users/1’ } ) .then(data => this.setState({ … Read more

Styles don’t load correctly. Insecure content

__DIR__ returns the current file system path, not a URL. So the resulting stylesheet will not be a valid URL, and will not have https://, causing the insecure content warning. To get the URL for a stylesheet in your plugin, you need to use plugins_url(): wp_register_style( ‘estilo’, plugins_url( ‘assets/css/estilo.css’, __FILE__ ) ); The use of … Read more

Add_rewrite_endpoint doesn’t work with post name permalink structure

I would avoid using add_rewrite_endpoint() directly to register account page endpoints in WooCommerce. WooCommerce has a filter that you can use that make sure everything else works properly, like the endpoint title filter and calls to is_wc_endpoint_url(). So add the endpoint with the woocommerce_get_query_vars filter: add_filter( ‘woocommerce_get_query_vars’, function( $query_vars ) { $query_vars[‘conversations’] = ‘conversations’; return … Read more

Cant register rest routs from class instance

There’s several things wrong here, none really related to OOP. Firstly, you seem to be attempting to register the REST routes on plugin activation. This is incorrect. Routes need to be registered for every request, so BusinessCustomersApiController->register_routes() needs to run on every request. You do this by hooking that function to the rest_api_init. The problem … Read more