| @@ -21,24 +21,24 @@ | ||
| 21 | 21 | { |
| 22 | 22 | public function __construct() |
| 23 | 23 | { |
| 24 | 24 | } |
| 25 | - public function get_prefix() : string | |
| 25 | + public function get_prefix(): string | |
| 26 | 26 | { |
| 27 | 27 | return 'admin/settings/options'; |
| 28 | 28 | } |
| 29 | - public function register_custom_endpoints() : void | |
| 29 | + public function register_custom_endpoints(): void | |
| 30 | 30 | { |
| 31 | - \register_rest_route(self::API_NAMESPACE, $this->get_prefix() . '/index', ['methods' => WP_REST_Server::READABLE, 'callback' => fn(\WP_REST_Request $wprestRequest): \WP_REST_Response => $this->index($wprestRequest), 'permission_callback' => fn(\WP_REST_Request $wprestRequest): bool => $this->permission_callback($wprestRequest)]); | |
| 32 | - \register_rest_route(self::API_NAMESPACE, $this->get_prefix() . '/store', ['methods' => WP_REST_Server::CREATABLE, 'callback' => fn(\WP_REST_Request $wprestRequest): \WP_REST_Response => $this->store($wprestRequest), 'permission_callback' => fn(\WP_REST_Request $wprestRequest): bool => $this->permission_callback($wprestRequest)]); | |
| 31 | + register_rest_route(self::API_NAMESPACE, $this->get_prefix() . '/index', ['methods' => WP_REST_Server::READABLE, 'callback' => fn(\WP_REST_Request $wprestRequest): \WP_REST_Response => $this->index($wprestRequest), 'permission_callback' => fn(\WP_REST_Request $wprestRequest): bool => $this->permission_callback($wprestRequest)]); | |
| 32 | + register_rest_route(self::API_NAMESPACE, $this->get_prefix() . '/store', ['methods' => WP_REST_Server::CREATABLE, 'callback' => fn(\WP_REST_Request $wprestRequest): \WP_REST_Response => $this->store($wprestRequest), 'permission_callback' => fn(\WP_REST_Request $wprestRequest): bool => $this->permission_callback($wprestRequest)]); | |
| 33 | 33 | } |
| 34 | - public function index(WP_REST_Request $wprestRequest) : WP_REST_Response | |
| 34 | + public function index(WP_REST_Request $wprestRequest): WP_REST_Response | |
| 35 | 35 | { |
| 36 | - $options = \json_decode(\get_option(WIND_PRESS::WP_OPTION . '_options', '{}'), null, 512, \JSON_THROW_ON_ERROR); | |
| 37 | - $options = \apply_filters('f!windpress/api/admin/settings/options:index', $options); | |
| 36 | + $options = json_decode(get_option(WIND_PRESS::WP_OPTION . '_options', '{}'), null, 512, \JSON_THROW_ON_ERROR); | |
| 37 | + $options = apply_filters('f!windpress/api/admin/settings/options:index', $options); | |
| 38 | 38 | return new WP_REST_Response(['options' => $options]); |
| 39 | 39 | } |
| 40 | - public function store(WP_REST_Request $wprestRequest) : WP_REST_Response | |
| 40 | + public function store(WP_REST_Request $wprestRequest): WP_REST_Response | |
| 41 | 41 | { |
| 42 | 42 | $payload = $wprestRequest->get_json_params(); |
| 43 | 43 | $options = $payload['options']; |
| 44 | 44 | if (empty($options)) { |
| @@ -43,10 +43,10 @@ | ||
| 43 | 43 | $options = $payload['options']; |
| 44 | 44 | if (empty($options)) { |
| 45 | 45 | $options = (object) $options; |
| 46 | 46 | } |
| 47 | - $options = \apply_filters('f!windpress/api/admin/settings/options:store.before', $options); | |
| 48 | - \update_option(WIND_PRESS::WP_OPTION . '_options', \wp_json_encode($options, \JSON_THROW_ON_ERROR)); | |
| 49 | - \do_action('f!windpress/api/admin/settings/options:store.after', $options); | |
| 50 | - return new WP_REST_Response(['message' => 'Settings updated']); | |
| 47 | + $options = apply_filters('f!windpress/api/admin/settings/options:store.before', $options); | |
| 48 | + update_option(WIND_PRESS::WP_OPTION . '_options', wp_json_encode($options, \JSON_THROW_ON_ERROR)); | |
| 49 | + do_action('a!windpress/api/admin/settings/options:store.after', $options); | |
| 50 | + return new WP_REST_Response(['message' => __('Settings updated', 'windpress')]); | |
| 51 | 51 | } |
| 52 | 52 | } |