Skip to content

Commit

Permalink
feat: add API route to clear caches
Browse files Browse the repository at this point in the history
implements #1507
  • Loading branch information
eteubert authored Nov 28, 2024
1 parent 767dc21 commit edd5819
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
require_once \Podlove\PLUGIN_DIR.'includes/api/episodes/contributions.php';
require_once \Podlove\PLUGIN_DIR.'includes/api/episodes/related_episodes.php';
require_once \Podlove\PLUGIN_DIR.'includes/api/chapters.php';
require_once \Podlove\PLUGIN_DIR.'includes/api/tools.php';
45 changes: 45 additions & 0 deletions includes/api/tools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Podlove\Api\Tools;

add_action('rest_api_init', function () {
$controller = new WP_REST_Podlove_Tools_Controller();
$controller->register_routes();
});

class WP_REST_Podlove_Tools_Controller extends \WP_REST_Controller
{
public function __construct()
{
$this->namespace = 'podlove/v2';
$this->rest_base = 'tools';
}

public function register_routes()
{
register_rest_route($this->namespace, '/'.$this->rest_base.'/clear-caches', [
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [$this, 'clear_caches'],
'permission_callback' => [$this, 'clear_caches_permission_check']
]);
}

public function clear_caches($request)
{
\Podlove\Repair::clear_podlove_cache();
\Podlove\Repair::clear_podlove_image_cache();

return new \Podlove\Api\Response\OkResponse([
'status' => 'ok'
]);
}

public function clear_caches_permission_check()
{
if (!current_user_can('administrator')) {
return new \Podlove\Api\Error\ForbiddenAccess();
}

return true;
}
}
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ This product includes GeoLite2 data created by MaxMind, available from http://ww

== Changelog ==

* feat: add API route to clear caches: `DELETE podlove/v2/tools/clear-caches`

= 4.1.23 =

* new: Auphonic file uploads display their upload progress
Expand Down

0 comments on commit edd5819

Please sign in to comment.