← All changes
|
core/settings/controllers/settings-controller.php
+71
-3
1.0.11
→
1.0.29
View file →
| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Booktics\Settings\Controllers; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | use Booktics\Abstracts\Base_Rest_Controller; |
| 6 | 10 | use Booktics\Services\Schedule_Manager; |
| 7 | 11 | use Booktics\Settings\Settings; |
| 8 | 12 | use WP_Error; |
| @@ -47,9 +51,9 @@ | ||
| 47 | 51 | array( |
| 48 | 52 | 'methods' => WP_REST_Server::READABLE, |
| 49 | 53 | 'callback' => array( $this, 'get_item' ), |
| 50 | 54 | 'args' => array(), |
| 51 | - 'permission_callback' => '__return_true', | |
| 55 | + 'permission_callback' => array( $this, 'get_item_permissions_check' ), | |
| 52 | 56 | ), |
| 53 | 57 | array( |
| 54 | 58 | 'methods' => WP_REST_Server::EDITABLE, |
| 55 | 59 | 'callback' => array( $this, 'update_item' ), |
| @@ -120,8 +124,9 @@ | ||
| 120 | 124 | $settings['reschedule_restriction'] = empty( $settings['reschedule_restriction'] ) ? (object) array() : $settings['reschedule_restriction']; |
| 121 | 125 | $settings['custom_reschedule_status'] = empty( $settings['custom_reschedule_status'] ) ? (object) array() : $settings['custom_reschedule_status']; |
| 122 | 126 | $settings['cancellation_restriction'] = empty( $settings['cancellation_restriction'] ) ? (object) array() : $settings['cancellation_restriction']; |
| 123 | 127 | $settings['stripe_addon_install_status'] = 0; |
| 128 | + $settings['woocommerce_install_status'] = 0; | |
| 124 | 129 | |
| 125 | 130 | $settings = apply_filters( 'booktics_format_setting_response', $settings ); |
| 126 | 131 | |
| 127 | 132 | return $settings; |
| @@ -158,8 +163,45 @@ | ||
| 158 | 163 | $schedule_manager->save(); |
| 159 | 164 | unset( $params['schedule'], $params['custom'], $params['holiday'] ); |
| 160 | 165 | } |
| 161 | 166 | |
| 167 | + // Enforce an integer minute value for the reservation hold timeout. | |
| 168 | + if ( isset( $params['pending_reservation_timeout'] ) ) { | |
| 169 | + $minutes = absint( $params['pending_reservation_timeout'] ); | |
| 170 | + $params['pending_reservation_timeout'] = $minutes > 0 ? $minutes : 10; | |
| 171 | + } | |
| 172 | + | |
| 173 | + // Only the two known destinations are accepted for the post-checkout page. | |
| 174 | + if ( isset( $params['wc_thankyou_page'] ) ) { | |
| 175 | + $params['wc_thankyou_page'] = in_array( $params['wc_thankyou_page'], array( 'woocommerce', 'booktics' ), true ) | |
| 176 | + ? $params['wc_thankyou_page'] | |
| 177 | + : 'woocommerce'; | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Last chance to clean the settings payload before it is stored. | |
| 182 | + * | |
| 183 | + * Settings::update() writes what it is handed, so a feature adding a | |
| 184 | + * structured key of its own sanitizes it here. schedule, custom and | |
| 185 | + * holiday are not in $params: Schedule_Manager has already saved them. | |
| 186 | + * | |
| 187 | + * @since 1.0.26 | |
| 188 | + * | |
| 189 | + * @param array $params Settings payload from the request. | |
| 190 | + */ | |
| 191 | + $filtered = apply_filters( 'booktics_settings_update_params', $params ); | |
| 192 | + | |
| 193 | + if ( ! is_array( $filtered ) ) { | |
| 194 | + _doing_it_wrong( | |
| 195 | + __METHOD__, | |
| 196 | + esc_html__( 'The booktics_settings_update_params filter must return an array.', 'booktics' ), | |
| 197 | + '1.0.26' | |
| 198 | + ); | |
| 199 | + $filtered = $params; | |
| 200 | + } | |
| 201 | + | |
| 202 | + $params = $filtered; | |
| 203 | + | |
| 162 | 204 | Settings::update( $params ); |
| 163 | 205 | |
| 164 | 206 | $settings = Settings::get(); |
| 165 | 207 | $settings = apply_filters( 'booktics_rest_settings', $settings ); |
| @@ -170,10 +212,36 @@ | ||
| 170 | 212 | |
| 171 | 213 | /** |
| 172 | 214 | * Get public settings |
| 173 | 215 | */ |
| 174 | - public function get_public_item( $request ): array { | |
| 175 | - return array(); | |
| 216 | + public function get_public_item( $request ) { | |
| 217 | + $all = Settings::get(); | |
| 218 | + $allowed = [ | |
| 219 | + 'primary_color', | |
| 220 | + 'secondary_color', | |
| 221 | + 'currency', | |
| 222 | + 'currency_symbol_position', | |
| 223 | + 'currency_decimals', | |
| 224 | + 'currency_price_separator', | |
| 225 | + 'enable_stripe_payment', | |
| 226 | + 'enable_paypal_payment', | |
| 227 | + 'enable_local_payment', | |
| 228 | + 'enable_woocommerce_payment', | |
| 229 | + 'wc_show_billing_fields', | |
| 230 | + 'wc_thankyou_page', | |
| 231 | + 'stripe_publishable_key', | |
| 232 | + 'show_end_time', | |
| 233 | + 'calendar_locale', | |
| 234 | + 'allow_customer_rescheduling', | |
| 235 | + 'allow_customer_cancellation', | |
| 236 | + 'reschedule_restriction', | |
| 237 | + 'cancellation_restriction', | |
| 238 | + ]; | |
| 239 | + | |
| 240 | + $public = array_intersect_key( $all, array_flip( $allowed ) ); | |
| 241 | + $public = apply_filters( 'booktics_rest_public_settings', $public ); | |
| 242 | + | |
| 243 | + return $this->response( $public, __( 'Public settings fetched successfully.', 'booktics' ) ); | |
| 176 | 244 | } |
| 177 | 245 | |
| 178 | 246 | /** |
| 179 | 247 | * Check if a given request has access to get items. |