Cleanup with WP REST API

SweepPress, both Lite/Free and Pro versions, includes support for running sweeping tasks via WP REST API. The plugin registers a new namespace inside the REST API and several new endpoints to list sweepers and tasks and run sweeping.

SweepPress currently registers namespace: sweeppress/v1. All endpoints registered by the plugin are added under that main namespace. If, in the future, some of the endpoints need to be changed, they will go into different namespaces.

Also, make sure to understand which request method you need to use, because some endpoints work with DELETE request, and will return error if you attempt to run it under GET or POST request.


To learn more about WP REST API, check out the official handbook for WP REST API, including information about accessing the API, authentication, and more. If you are unsure how to use REST API already, this article is not for you!

Access to the SweepPress namespace

SweepPress namespace and all the endpoints can be accessed only by the website administrator (the plugin checks for activate_plugins capability). So, the only way to access any endpoints is by authentication of the administrative account with this capability. Again, more about this is available in the official handbook, and it is irrelevant for this article.



The basic endpoint lists all the sweepers and individual tasks for each sweeper. These are actually two endoints, with second version returning individual sweeper tasks.

This endpoint is registered with WP_REST_Server::READABLE or GET method.

If you run the first one, you will get results like this:

List Endpoint Results

Results are returned as objects, with each sweeper showing a number of tasks, an estimated number of records for removal, and an estimated size that will be recovered. This image shows only few results as opened, but all available sweepers will be listed.

List Endpoint Single Sweeper Results


This endpoint will initiate the auto-sweeping process and run all the sweepers available for Auto sweeping. No arguments or anything else is needed to adjust things for this endpoint.

This endpoint is registered with WP_REST_Server::DELETABLE or DELETE method.

This endpoint also returns the result, and it looks like this:

Auto Endpoint Auto Sweep Results


With this endpoint, you can run a single sweeper only. Right now, in this implementation, it will run all available tasks for a single sweeper; there is no way only to specify some tasks.

This endpoint is registered with WP_REST_Server::DELETABLE or DELETE method.

This endpoint also returns the result; it looks the same as for the AUTO endpoint.

Rate this article

You are not allowed to rate this post.

Leave a Comment