Skip to content

REST API Reference

WB Member Wiki exposes two REST API endpoints under the wbmw/v1 namespace. These endpoints power the live search autocomplete and image upload features used by the frontend editor.

wbmw/v1

Base URL: https://yourdomain.com/wp-json/wbmw/v1/

Both endpoints use standard WordPress REST API authentication: cookie-based authentication with the X-WP-Nonce header containing a wp_rest nonce. The JavaScript frontend sends this automatically via the wbmw_ajax localized object.

Members never need to call admin-ajax.php - all frontend interactions use these REST endpoints.


Returns autocomplete suggestions for the live wiki search field.

Authentication: None required (public endpoint)

Parameters:

Parameter Type Default Description
term string "" Search term. Must be at least 2 characters to return results

Response: JSON array of suggestion objects. Returns an empty array if term is shorter than 2 characters.

Example request:

GET /wp-json/wbmw/v1/search?term=quantum

Example response:

[
{
"ID": 42,
"post_title": "Quantum Computing",
"permalink": "https://example.com/wiki/quantum-computing/"
},
{
"ID": 87,
"post_title": "Quantum Mechanics Overview",
"permalink": "https://example.com/wiki/quantum-mechanics-overview/"
}
]

The suggestion list is generated by WBMW_Search::suggest(). Results can be customized using the wbmw_search_args filter (see Hooks & Filters).


Uploads an image file and creates a WordPress media attachment. Used by the wiki editor’s image upload button.

Authentication: Required. User must be logged in and have wiki create permission (wbmw_access()->can_create()).

Request format: multipart/form-data with a file field containing the image.

Allowed MIME types: image/jpeg, image/gif, image/png, image/webp

Response on success:

{
"id": 123,
"url": "https://example.com/wp-content/uploads/2026/03/image.jpg"
}

Error responses:

HTTP Status Error Code Cause
401 rest_forbidden User is not logged in
403 rest_forbidden User does not have wiki create permission
400 no_file No file was included in the request
500 upload_failed WordPress media upload error

Example using fetch:

const formData = new FormData();
formData.append( 'file', fileInput.files[0] );
fetch( wpApiSettings.root + 'wbmw/v1/upload-image', {
method: 'POST',
headers: {
'X-WP-Nonce': wpApiSettings.nonce,
},
body: formData,
} )
.then( res => res.json() )
.then( data => {
console.log( 'Uploaded:', data.url );
} );

The search endpoint has permission_callback: '__return_true' - it is fully public and requires no authentication. It returns only published wiki pages.

The upload endpoint calls wbmw_access()->can_create() which checks:

  1. User must be logged in
  2. User must be an administrator (manage_options), or their role must be in the configured Create roles (WB Plugins > Member Wiki > Permissions > Create Pages)

The endpoint enforces image-only uploads by temporarily replacing the upload_mimes filter to allow only JPEG, GIF, PNG, and WebP.


Routes are registered on the rest_api_init hook by WBMW_REST_API::register_routes(). The class is instantiated by the core WB_Member_Wiki plugin singleton.

To verify routes are registered:

GET /wp-json/

Look for wbmw/v1 in the namespaces array of the index response.