| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin\api; |
| 4 |
|
| 5 |
use Leadin\api\Base_Api_Controller; |
| 6 |
use Leadin\data\Portal_Options; |
| 7 |
|
| 8 |
/** |
| 9 |
* Updates the Cache for the Mappings |
| 10 |
*/ |
| 11 |
class WP_Mappings_Api_Controller extends Base_Api_Controller { |
| 12 |
|
| 13 |
/** |
| 14 |
* Class constructor, register route. |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
self::register_leadin_admin_route( |
| 18 |
'/wp-mappings-cache-reset', |
| 19 |
\WP_REST_Server::CREATABLE, |
| 20 |
array( $this, 'reset_wp_mappings_cache' ) |
| 21 |
); |
| 22 |
self::register_leadin_admin_route( |
| 23 |
'/wp-mappings-proxy-enabled', |
| 24 |
\WP_REST_Server::EDITABLE, |
| 25 |
array( $this, 'set_wp_mappings_proxy_enabled' ) |
| 26 |
); |
| 27 |
self::register_leadin_admin_route( |
| 28 |
'/wp-mappings-proxy-enabled', |
| 29 |
\WP_REST_Server::READABLE, |
| 30 |
array( $this, 'get_wp_mappings_proxy_enabled' ) |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Resets the WP cache for the Mappings |
| 36 |
* |
| 37 |
* @return string OK response message. |
| 38 |
*/ |
| 39 |
public function reset_wp_mappings_cache() { |
| 40 |
do_action( 'leadin_reset_wp_mappings_cache' ); |
| 41 |
return new \WP_REST_Response( 'OK', 200 ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get proxy mappings enabled option. |
| 46 |
* |
| 47 |
* @return bool Proxy mappings enabled option value. |
| 48 |
*/ |
| 49 |
public function get_wp_mappings_proxy_enabled() { |
| 50 |
return new \WP_REST_Response( Portal_Options::get_proxy_mappings_enabled(), 200 ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Set the proxy mappings enabled option. |
| 55 |
* |
| 56 |
* @param bool $request option value. |
| 57 |
* |
| 58 |
* @return string OK response message. |
| 59 |
*/ |
| 60 |
public function set_wp_mappings_proxy_enabled( $request ) { |
| 61 |
Portal_Options::set_proxy_mappings_enabled( json_decode( $request->get_body(), true ) ); |
| 62 |
return new \WP_REST_Response( 'OK', 200 ); |
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|