| @@ -85,53 +85,25 @@ | ||
| 85 | 85 | [ 'wp-components' ], |
| 86 | 86 | $editor_asset['version'] |
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | - // The OttoKit embed script (defines window.SureTriggers) is NOT enqueued | |
| 90 | - // here — it is remote executable JS and would load on every form-editor | |
| 91 | - // session even when OttoKit is absent. It is lazy-injected from the | |
| 92 | - // OttoKit tab only when the builder opens (see OttoKitSettings.js), using | |
| 93 | - // the URL passed below. | |
| 94 | - | |
| 95 | 89 | // Localized data. |
| 96 | 90 | $global_currency = Payment_Helper::get_global_setting( 'currency', 'USD' ); |
| 97 | 91 | $global_currency = is_string( $global_currency ) ? $global_currency : 'USD'; |
| 98 | 92 | |
| 99 | - $editor_data = [ | |
| 100 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 101 | - 'nonce' => wp_create_nonce( 'suredonation_editor_nonce' ), | |
| 102 | - 'postType' => Donation_Form::POST_TYPE, | |
| 103 | - 'smartTags' => Helper::get_smart_tags()['confirmation'], | |
| 104 | - 'emailSmartTags' => Helper::get_smart_tags()['email_grouped'], | |
| 105 | - 'defaultEmailNotifications' => $this->get_default_email_notifications(), | |
| 106 | - // The recurring payment type is a Pro control, but the block attribute | |
| 107 | - // it sets is registered in free and persists in post content. Without | |
| 108 | - // this, deactivating Pro leaves the recurring notifications on screen | |
| 109 | - // and editable while nothing can send them. | |
| 110 | - 'isProActive' => defined( 'SUREDONATION_PRO_VER' ), | |
| 111 | - 'currency' => $global_currency, | |
| 112 | - 'currencySymbol' => Payment_Helper::get_currency_symbol( $global_currency ), | |
| 113 | - // OttoKit integration: embed config + lazy-loaded builder script. | |
| 114 | - 'suretriggersNonce' => wp_create_nonce( 'suredonation_suretriggers_nonce' ), | |
| 115 | - 'embedScriptUrl' => SUREDONATION_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', | |
| 116 | - 'integrations' => [ | |
| 117 | - 'sure_triggers' => Helper::get_ottokit_integration(), | |
| 118 | - ], | |
| 119 | - ]; | |
| 120 | - | |
| 121 | - // Plugin install/activate nonces are a plugin-management capability; | |
| 122 | - // only expose them to users who can actually install plugins. The AJAX | |
| 123 | - // handlers enforce this server-side too — this keeps the nonces out of | |
| 124 | - // the page source for sub-admins who reach the editor via post.php. | |
| 125 | - if ( current_user_can( 'install_plugins' ) ) { | |
| 126 | - $editor_data['pluginInstallerNonce'] = wp_create_nonce( 'updates' ); | |
| 127 | - $editor_data['pluginManagerNonce'] = wp_create_nonce( 'suredonation_plugin_manager' ); | |
| 128 | - } | |
| 129 | - | |
| 130 | 93 | wp_localize_script( |
| 131 | 94 | 'suredonation-form-editor', |
| 132 | 95 | 'suredonationFormEditor', |
| 133 | - $editor_data | |
| 96 | + [ | |
| 97 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 98 | + 'nonce' => wp_create_nonce( 'suredonation_editor_nonce' ), | |
| 99 | + 'postType' => Donation_Form::POST_TYPE, | |
| 100 | + 'smartTags' => Helper::get_smart_tags()['confirmation'], | |
| 101 | + 'emailSmartTags' => Helper::get_smart_tags()['email_grouped'], | |
| 102 | + 'defaultEmailNotifications' => $this->get_default_email_notifications(), | |
| 103 | + 'currency' => $global_currency, | |
| 104 | + 'currencySymbol' => Payment_Helper::get_currency_symbol( $global_currency ), | |
| 105 | + ] | |
| 134 | 106 | ); |
| 135 | 107 | |
| 136 | 108 | // Set script translations. |
| 137 | 109 | wp_set_script_translations( 'suredonation-form-editor', 'suredonation' ); |
| @@ -211,9 +183,8 @@ | ||
| 211 | 183 | // phpcs:disable Generic.Strings.UnnecessaryStringConcat.Found -- Readability. |
| 212 | 184 | $defaults = [ |
| 213 | 185 | // --- Donor Emails --- |
| 214 | 186 | [ |
| 215 | - 'key' => 'donation_receipt', | |
| 216 | 187 | 'id' => 1, |
| 217 | 188 | 'status' => true, |
| 218 | 189 | 'name' => __( 'Donation Receipt', 'suredonation' ), |
| 219 | 190 | 'email_to' => '{donor_email}', |
| @@ -232,9 +203,8 @@ | ||
| 232 | 203 | 'reply_to' => '', |
| 233 | 204 | 'trigger' => 'donation_completed', |
| 234 | 205 | ], |
| 235 | 206 | [ |
| 236 | - 'key' => 'donation_processing', | |
| 237 | 207 | 'id' => 2, |
| 238 | 208 | 'status' => true, |
| 239 | 209 | 'name' => __( 'Donation Processing', 'suredonation' ), |
| 240 | 210 | 'email_to' => '{donor_email}', |
| @@ -252,9 +222,8 @@ | ||
| 252 | 222 | 'reply_to' => '', |
| 253 | 223 | 'trigger' => 'donation_processing', |
| 254 | 224 | ], |
| 255 | 225 | [ |
| 256 | - 'key' => 'donation_failed', | |
| 257 | 226 | 'id' => 3, |
| 258 | 227 | 'status' => true, |
| 259 | 228 | 'name' => __( 'Donation Failed', 'suredonation' ), |
| 260 | 229 | 'email_to' => '{donor_email}', |
| @@ -268,9 +237,8 @@ | ||
| 268 | 237 | 'reply_to' => '', |
| 269 | 238 | 'trigger' => 'donation_failed', |
| 270 | 239 | ], |
| 271 | 240 | [ |
| 272 | - 'key' => 'refund_processed', | |
| 273 | 241 | 'id' => 4, |
| 274 | 242 | 'status' => true, |
| 275 | 243 | 'name' => __( 'Refund Processed', 'suredonation' ), |
| 276 | 244 | 'email_to' => '{donor_email}', |
| @@ -290,9 +258,8 @@ | ||
| 290 | 258 | ], |
| 291 | 259 | |
| 292 | 260 | // --- Admin Emails --- |
| 293 | 261 | [ |
| 294 | - 'key' => 'donation_receipt_admin', | |
| 295 | 262 | 'id' => 9, |
| 296 | 263 | 'status' => true, |
| 297 | 264 | 'name' => __( 'New Donation (Admin)', 'suredonation' ), |
| 298 | 265 | 'email_to' => '{admin_email}', |
| @@ -311,9 +278,8 @@ | ||
| 311 | 278 | 'reply_to' => '', |
| 312 | 279 | 'trigger' => 'donation_completed', |
| 313 | 280 | ], |
| 314 | 281 | [ |
| 315 | - 'key' => 'donation_failed_admin', | |
| 316 | 282 | 'id' => 10, |
| 317 | 283 | 'status' => true, |
| 318 | 284 | 'name' => __( 'Donation Failed (Admin)', 'suredonation' ), |
| 319 | 285 | 'email_to' => '{admin_email}', |
| @@ -331,9 +297,8 @@ | ||
| 331 | 297 | 'reply_to' => '', |
| 332 | 298 | 'trigger' => 'donation_failed', |
| 333 | 299 | ], |
| 334 | 300 | [ |
| 335 | - 'key' => 'refund_processed_admin', | |
| 336 | 301 | 'id' => 11, |
| 337 | 302 | 'status' => true, |
| 338 | 303 | 'name' => __( 'Refund Processed (Admin)', 'suredonation' ), |
| 339 | 304 | 'email_to' => '{admin_email}', |
| @@ -417,30 +382,9 @@ | ||
| 417 | 382 | if ( ! is_array( $notification ) ) { |
| 418 | 383 | continue; |
| 419 | 384 | } |
| 420 | 385 | |
| 421 | - $trigger = isset( $notification['trigger'] ) && is_string( $notification['trigger'] ) ? $notification['trigger'] : ''; | |
| 422 | - | |
| 423 | - // Preserve the trigger verbatim rather than validating against the | |
| 424 | - // registered list. 'all' means "send on every event", so coercing an | |
| 425 | - // unrecognised trigger to it silently rewires that notification to | |
| 426 | - // fire on every donation event. Saving a form while Pro is inactive | |
| 427 | - // did exactly that to the recurring templates: the trigger was not | |
| 428 | - // registered, so a customised "Subscription Created" became a message | |
| 429 | - // sent on completed, failed, processing and refunded donations, and | |
| 430 | - // the editor stopped recognising it as recurring and appended a | |
| 431 | - // duplicate set. | |
| 432 | - // | |
| 433 | - // An unregistered trigger is already inert: dispatch is an equality | |
| 434 | - // match against an event name, and the code that fires the recurring | |
| 435 | - // events does not load while Pro is inactive. Preserving the value | |
| 436 | - // costs nothing and lets the notification resume working, with its | |
| 437 | - // customisations, as soon as Pro is active again. | |
| 438 | 386 | $sanitized[] = [ |
| 439 | - // Stable machine identity. `id` is reassigned when a set is | |
| 440 | - // re-seeded and `name` is user-editable and translated, so neither | |
| 441 | - // survives as a way to recognise a notification later. | |
| 442 | - 'key' => isset( $notification['key'] ) && is_string( $notification['key'] ) ? sanitize_key( $notification['key'] ) : '', | |
| 443 | 387 | 'id' => isset( $notification['id'] ) ? absint( $notification['id'] ) : 0, |
| 444 | 388 | 'status' => isset( $notification['status'] ) ? (bool) $notification['status'] : true, |
| 445 | 389 | 'name' => isset( $notification['name'] ) ? sanitize_text_field( $notification['name'] ) : '', |
| 446 | 390 | 'email_to' => isset( $notification['email_to'] ) ? sanitize_text_field( $notification['email_to'] ) : '', |
| @@ -448,13 +392,16 @@ | ||
| 448 | 392 | 'email_body' => isset( $notification['email_body'] ) ? wp_kses_post( $notification['email_body'] ) : '', |
| 449 | 393 | 'from_name' => isset( $notification['from_name'] ) ? sanitize_text_field( $notification['from_name'] ) : '', |
| 450 | 394 | 'from_email' => isset( $notification['from_email'] ) ? sanitize_text_field( $notification['from_email'] ) : '', |
| 451 | 395 | 'reply_to' => isset( $notification['reply_to'] ) ? sanitize_text_field( $notification['reply_to'] ) : '', |
| 452 | - // A missing trigger must stay inert. Dispatch skips an empty | |
| 453 | - // trigger but treats 'all' as "fire on every event", so falling | |
| 454 | - // back to 'all' routes the unknown case to the most permissive | |
| 455 | - // outcome — the opposite of what a missing value should mean. | |
| 456 | - 'trigger' => '' !== $trigger ? sanitize_key( $trigger ) : '', | |
| 396 | + 'trigger' => isset( $notification['trigger'] ) && in_array( | |
| 397 | + $notification['trigger'], | |
| 398 | + apply_filters( | |
| 399 | + 'suredonation_email_notification_triggers', | |
| 400 | + [ 'all', 'donation_completed', 'donation_processing', 'donation_failed', 'refund_processed' ] | |
| 401 | + ), | |
| 402 | + true | |
| 403 | + ) ? $notification['trigger'] : 'all', | |
| 457 | 404 | ]; |
| 458 | 405 | } |
| 459 | 406 | |
| 460 | 407 | $encoded = wp_json_encode( $sanitized ); |
| @@ -459,9 +406,8 @@ | ||
| 459 | 406 | |
| 460 | 407 | $encoded = wp_json_encode( $sanitized ); |
| 461 | 408 | return is_string( $encoded ) ? $encoded : ''; |
| 462 | 409 | } |
| 463 | - | |
| 464 | 410 | |
| 465 | 411 | /** |
| 466 | 412 | * Sanitize form confirmation settings. |
| 467 | 413 | * |