getInputs() ); return empty( $keys ) ? 'Update Booktics settings' : 'Update Booktics settings: ' . implode( ', ', $keys ); } /** * Human-readable inputs shown in the approval card table. * * @return array */ public function get_approval_inputs(): array { return $this->getInputs(); } /** * Execute the tool after human approval. * * @param string|null $currency Currency code. * @param string|null $date_format Date format. * @param string|null $time_format Time format. * @param string|null $timezone Timezone string. * @param string|null $business_name Business name. * @param string|null $business_email Business email. * @param string|null $business_address Business address. * @param string|null $primary_color Primary brand colour. * @param string|null $secondary_color Secondary brand colour. * @param bool|null $show_end_time Show end times. * @param bool|null $allow_customer_rescheduling Customers may reschedule. * @param bool|null $allow_customer_cancellation Customers may cancel. * @param bool|null $allow_customer_as_wp_user Register customers as WP users. * @return array */ public function __invoke( ?string $currency = null, ?string $date_format = null, ?string $time_format = null, ?string $timezone = null, ?string $business_name = null, ?string $business_email = null, ?string $business_address = null, ?string $primary_color = null, ?string $secondary_color = null, ?bool $show_end_time = null, ?bool $allow_customer_rescheduling = null, ?bool $allow_customer_cancellation = null, ?bool $allow_customer_as_wp_user = null ): array { $check = $this->guard_admin(); if ( $check ) { return $check; } if ( null !== $business_email && '' !== trim( $business_email ) && ! is_email( $business_email ) ) { return [ 'error' => 'business_email must be a valid email address.' ]; } $body = []; foreach ( [ 'currency' => $currency, 'date_format' => $date_format, 'time_format' => $time_format, 'timezone' => $timezone, 'business_name' => $business_name, 'business_email' => $business_email, 'business_address' => $business_address, 'primary_color' => $primary_color, 'secondary_color' => $secondary_color, ] as $key => $value ) { if ( null !== $value ) { $body[ $key ] = 'business_address' === $key ? sanitize_textarea_field( $value ) : sanitize_text_field( $value ); } } foreach ( [ 'show_end_time' => $show_end_time, 'allow_customer_rescheduling' => $allow_customer_rescheduling, 'allow_customer_cancellation' => $allow_customer_cancellation, 'allow_customer_as_wp_user' => $allow_customer_as_wp_user, ] as $key => $value ) { if ( null !== $value ) { $body[ $key ] = (bool) $value; } } if ( empty( $body ) ) { return [ 'error' => 'No settings provided to update.' ]; } try { $request = $this->build_json_request( 'POST', '/booktics/v1/settings', $body ); if ( is_array( $request ) ) { return $request; } $controller = new \Booktics\Settings\Controllers\Settings_Controller(); $data = $this->extract_response( $controller->update_item( $request ), 'Failed to update settings.' ); if ( isset( $data['error'] ) ) { return $data; } $updated = array_keys( $body ); return [ 'success' => true, 'updated_fields' => $updated, 'settings' => array_intersect_key( $data, $body ), 'message' => 'Settings updated successfully: ' . implode( ', ', $updated ) . '.', ]; } catch ( \Throwable $e ) { Log::error( 'Booktics_Update_Settings_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to update settings: ' . $e->getMessage() ]; } } }