| @@ -150,19 +150,12 @@ | ||
| 150 | 150 | 'methods' => WP_REST_Server::EDITABLE, |
| 151 | 151 | 'callback' => [ $this, 'update_donor_settings' ], |
| 152 | 152 | 'permission_callback' => [ $this, 'check_permissions' ], |
| 153 | 153 | 'args' => [ |
| 154 | - 'create_wp_user' => [ | |
| 154 | + 'create_wp_user' => [ | |
| 155 | 155 | 'type' => 'boolean', |
| 156 | 156 | 'sanitize_callback' => 'rest_sanitize_boolean', |
| 157 | 157 | ], |
| 158 | - // Registered so the handler's (bool) cast receives a real | |
| 159 | - // boolean: a form-encoded "false" would otherwise cast to true | |
| 160 | - // and switch moderation ON when the admin asked for OFF. | |
| 161 | - 'hold_donor_comments' => [ | |
| 162 | - 'type' => 'boolean', | |
| 163 | - 'sanitize_callback' => 'rest_sanitize_boolean', | |
| 164 | - ], | |
| 165 | 158 | ], |
| 166 | 159 | ], |
| 167 | 160 | ], |
| 168 | 161 | |
| @@ -179,22 +172,8 @@ | ||
| 179 | 172 | 'permission_callback' => [ $this, 'check_permissions' ], |
| 180 | 173 | ], |
| 181 | 174 | ], |
| 182 | 175 | |
| 183 | - // Privacy settings (data retention, consent, privacy/terms fields). | |
| 184 | - '/settings/privacy' => [ | |
| 185 | - [ | |
| 186 | - 'methods' => WP_REST_Server::READABLE, | |
| 187 | - 'callback' => [ $this, 'get_privacy_settings' ], | |
| 188 | - 'permission_callback' => [ $this, 'check_permissions' ], | |
| 189 | - ], | |
| 190 | - [ | |
| 191 | - 'methods' => WP_REST_Server::EDITABLE, | |
| 192 | - 'callback' => [ $this, 'update_privacy_settings' ], | |
| 193 | - 'permission_callback' => [ $this, 'check_permissions' ], | |
| 194 | - ], | |
| 195 | - ], | |
| 196 | - | |
| 197 | 176 | // Send test email. |
| 198 | 177 | '/settings/email/test' => [ |
| 199 | 178 | 'methods' => WP_REST_Server::CREATABLE, |
| 200 | 179 | 'callback' => [ $this, 'send_test_email' ], |
| @@ -203,49 +182,8 @@ | ||
| 203 | 182 | ]; |
| 204 | 183 | } |
| 205 | 184 | |
| 206 | 185 | /** |
| 207 | - * Get the Privacy settings (stored values merged over the defaults). | |
| 208 | - * | |
| 209 | - * @param WP_REST_Request $request Request object. | |
| 210 | - * @return WP_REST_Response | |
| 211 | - * @since 1.2.0 | |
| 212 | - */ | |
| 213 | - public function get_privacy_settings( $request ) { | |
| 214 | - unset( $request ); // Unused parameter. | |
| 215 | - | |
| 216 | - return new WP_REST_Response( | |
| 217 | - [ | |
| 218 | - 'success' => true, | |
| 219 | - 'settings' => \SureDonation\Inc\Privacy\Privacy_Settings::get_settings(), | |
| 220 | - ], | |
| 221 | - 200 | |
| 222 | - ); | |
| 223 | - } | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * Update the Privacy settings. | |
| 227 | - * | |
| 228 | - * @param WP_REST_Request $request Request object. | |
| 229 | - * @return WP_REST_Response | |
| 230 | - * @since 1.2.0 | |
| 231 | - */ | |
| 232 | - public function update_privacy_settings( $request ) { | |
| 233 | - $params = $request->get_json_params(); | |
| 234 | - $sanitized = \SureDonation\Inc\Privacy\Privacy_Settings::sanitize( is_array( $params ) ? $params : [] ); | |
| 235 | - | |
| 236 | - Helper::update_suredonation_option( \SureDonation\Inc\Privacy\Privacy_Settings::OPTION_KEY, $sanitized ); | |
| 237 | - | |
| 238 | - return new WP_REST_Response( | |
| 239 | - [ | |
| 240 | - 'success' => true, | |
| 241 | - 'settings' => $sanitized, | |
| 242 | - ], | |
| 243 | - 200 | |
| 244 | - ); | |
| 245 | - } | |
| 246 | - | |
| 247 | - /** | |
| 248 | 186 | * Get the form-validation default messages. |
| 249 | 187 | * |
| 250 | 188 | * Returns the stored admin overrides merged over the translatable defaults |
| 251 | 189 | * so every configurable message always has a value in the editor. |
| @@ -361,11 +299,10 @@ | ||
| 361 | 299 | return new WP_REST_Response( |
| 362 | 300 | [ |
| 363 | 301 | 'success' => true, |
| 364 | 302 | 'settings' => [ |
| 365 | - 'currency' => $settings['currency'] ?? 'USD', | |
| 366 | - 'payment_mode' => $settings['payment_mode'] ?? 'test', | |
| 367 | - 'currency_sign_position' => Payment_Helper::get_currency_sign_position(), | |
| 303 | + 'currency' => $settings['currency'] ?? 'USD', | |
| 304 | + 'payment_mode' => $settings['payment_mode'] ?? 'test', | |
| 368 | 305 | ], |
| 369 | 306 | ], |
| 370 | 307 | 200 |
| 371 | 308 | ); |
| @@ -409,16 +346,8 @@ | ||
| 409 | 346 | $current_settings['payment_mode'] = $mode; |
| 410 | 347 | } |
| 411 | 348 | } |
| 412 | 349 | |
| 413 | - // Update currency sign position if provided. | |
| 414 | - if ( isset( $params['currency_sign_position'] ) ) { | |
| 415 | - $position = sanitize_text_field( $params['currency_sign_position'] ); | |
| 416 | - if ( in_array( $position, Payment_Helper::ALLOWED_SIGN_POSITIONS, true ) ) { | |
| 417 | - $current_settings['currency_sign_position'] = $position; | |
| 418 | - } | |
| 419 | - } | |
| 420 | - | |
| 421 | 350 | $success = Payment_Helper::update_all_payment_settings( $current_settings ); |
| 422 | 351 | |
| 423 | 352 | if ( ! $success ) { |
| 424 | 353 | return new WP_Error( |
| @@ -653,13 +582,9 @@ | ||
| 653 | 582 | [ |
| 654 | 583 | 'success' => true, |
| 655 | 584 | 'settings' => [ |
| 656 | 585 | // Off by default: guest donations never auto-create WP user accounts. |
| 657 | - 'create_wp_user' => ! empty( $donor_settings['create_wp_user'] ), | |
| 658 | - // Off by default: donor comments publish as soon as the donation | |
| 659 | - // completes, matching GiveWP and Charitable out of the box. Turning | |
| 660 | - // it on holds new comments as `pending` for review instead. | |
| 661 | - 'hold_donor_comments' => ! empty( $donor_settings['hold_donor_comments'] ), | |
| 586 | + 'create_wp_user' => ! empty( $donor_settings['create_wp_user'] ), | |
| 662 | 587 | ], |
| 663 | 588 | ], |
| 664 | 589 | 200 |
| 665 | 590 | ); |
| @@ -672,25 +597,17 @@ | ||
| 672 | 597 | * @return WP_REST_Response Response object. |
| 673 | 598 | * @since 1.0.0 |
| 674 | 599 | */ |
| 675 | 600 | public function update_donor_settings( $request ) { |
| 676 | - $donor_settings = Helper::get_suredonation_option( self::DONOR_OPTION_KEY, [] ); | |
| 677 | - if ( ! is_array( $donor_settings ) ) { | |
| 678 | - $donor_settings = []; | |
| 679 | - } | |
| 601 | + $create_wp_user = $request->get_param( 'create_wp_user' ); | |
| 680 | 602 | |
| 681 | - // Read each setting via get_param() so the endpoint accepts JSON, body, | |
| 682 | - // or query params (matches the sibling /settings/* update handlers). | |
| 683 | - $changed = false; | |
| 684 | - foreach ( [ 'create_wp_user', 'hold_donor_comments' ] as $key ) { | |
| 685 | - $value = $request->get_param( $key ); | |
| 686 | - if ( null !== $value ) { | |
| 687 | - $donor_settings[ $key ] = (bool) $value; | |
| 688 | - $changed = true; | |
| 603 | + if ( null !== $create_wp_user ) { | |
| 604 | + $donor_settings = Helper::get_suredonation_option( self::DONOR_OPTION_KEY, [] ); | |
| 605 | + if ( ! is_array( $donor_settings ) ) { | |
| 606 | + $donor_settings = []; | |
| 689 | 607 | } |
| 690 | - } | |
| 691 | 608 | |
| 692 | - if ( $changed ) { | |
| 609 | + $donor_settings['create_wp_user'] = (bool) $create_wp_user; | |
| 693 | 610 | Helper::update_suredonation_option( self::DONOR_OPTION_KEY, $donor_settings ); |
| 694 | 611 | } |
| 695 | 612 | |
| 696 | 613 | return new WP_REST_Response( |