wp-api-console
wp-api-console copied to clipboard
Allow using the console with cookie authentication
This is useful for local REST API development or for embedding the console as a plugin into an existing wordpress installation.
- introduces a new auth provider
- introduces a new api creator (core with autodiscovery)
It requires a predefined JavaScript global object is available on the page.
The name of that global is defined in config.json under globalObjectName
example config:
{
"wordpress.org": [
{
"name": "localDev",
"authType": "local_dev",
"globalObjectName": "wpApiSettings",
"url": "http://no-need-for-url.com"
}
]
}
The JS object can be obtained like this (in this case the
globalObjectName in the config should be named wpApiSettings)
wp_localize_script( 'wp-api', 'wpApiSettings', array(
'nonce' => wp_create_nonce( 'wp_rest' ),
'url' => esc_url_raw( site_url() ),
'baseUrl' => esc_url_raw( trailingslashit( rest_url() ) ),
'loggedInUserId' => get_current_user_id()
) );