Developer guide
Print the donation form from PHP, override the templates, style the markup and work with the data both plugins store.
Architecture
| Free | Pro | |
|---|---|---|
| Namespace | Siteryn\SiterynDonations | SiterynPro\SiterynDonations |
| Boot | siteryn_donations_loaded | siteryn_donations_pro_loaded, siteryn_donations_pro_features_loaded (licensed only) |
| Settings option | siteryn_donations_settings | siteryn_donations_pro_settings |
| Admin page | admin.php?page=siteryn-donations | Adds tabs to the same page |
| Public API version | Plugin::API_VERSION = 1.0 | Requires API 1.0 |
Pro is built only on Free's documented hooks and public methods: amounts, validation, the cart, the donation box, templates and the settings engine all come from Free. Everything that isn't listed here or in the Hooks reference is internal.
Functions
<?php siteryn_donations_form(); ?> // the donation form (same as the shortcode) <?php siteryn_donations_form( 123 ); ?> // for donation product 123 siteryn_donations_is_donation_product( $product ); // bool siteryn_donations(); // the running Free Plugin, or null siteryn_donations_pro(); // the running Pro Plugin, or null siteryn_donations_pro_campaign_progress( 123 ); // raised, goal, donors, percent, closed
Public methods include DonationWidget::render( $context, $product_id = 0 ), DonationCart::add_donation( $amount, $product_id = 0, $context = 'cart', $extra = array() ) (returns the cart item key or a WP_Error), DonationCart::remove_donation(), DonationCart::get_cart_donations(), Orders::get_donation_items( $order ), Orders::get_donation_total( $order ), the Amounts helpers (parse(), validate(), format(), get_fixed_amounts(), get_limits()) and, in Pro, Campaigns\Campaign::get( $product )->progress().
Templates
| Template | Plugin | Shows |
|---|---|---|
donation-widget.php | Free | The donation box and the Donate page form |
amount-picker.php | Free | The amounts and the custom amount field |
campaign-progress.php | Pro | A campaign's progress bar |
frequency-picker.php | Pro | The recurring choice |
thank-you.php | Pro | The thank-you message (page and email) |
Copy a file to your-theme/siteryn-donations/ (Pro's too). Keep the data-siteryn-donations-* attributes, the field names and the @version header: when your copy is older than the plugin's, store managers see "Siteryn Donations template files should be updated". The cart box and the Donate page render as a <form> that also works without JavaScript; on the checkout the box is a <div> inside WooCommerce's form.
Markup and CSS
- Box:
section.siteryn-donations-widget.siteryn-donations-widget--{context}(cart,checkout,cart_block,checkout_block,shortcode), withhas-donationwhen a donation is in the cart. - Picker:
.siteryn-donations-picker; product page price:.siteryn-donations-price. - Pro:
.siteryn-donations-progress(--box,--product,--shortcode,is-closed),.siteryn-donations-frequency,.siteryn-donations-thankyou,.siteryn-donations-product-offer. - Colors are CSS custom properties on the box and picker:
--siteryn-donations-accent,--siteryn-donations-accent-text,--siteryn-donations-bg,--siteryn-donations-border,--siteryn-donations-text,--siteryn-donations-radius, plus--siteryn-donations-error,--siteryn-donations-surfaceand--siteryn-donations-control-border. Pro's bar uses--siteryn-donations-progress(default#1a7f37).
.siteryn-donations-widget { --siteryn-donations-radius: 16px; }
Sending extra fields with a donation
Name an input siteryn_donations_extra[your_key] inside the box (print it on siteryn_donations_widget_before_actions) or a donation product's add to cart form. It arrives in the $extra argument of siteryn_donations_cart_item_data on the classic pages, the blocks and product pages alike. Sanitize and whitelist what you read. Pro's frequency choice works this way.
Assets
The siteryn-donations stylesheet and script load on the cart, checkout and donation product pages, and wherever the box renders. Load them elsewhere with add_filter( 'siteryn_donations_enqueue_assets', '__return_true' ). Pro's siteryn-donations-pro stylesheet follows Free's, and loads on the order received page.
Requests and endpoints
| Endpoint | Used by |
|---|---|
?wc-ajax=siteryn_donations_update | The box on classic pages and the shortcode (nonce siteryn_donations_update): add, update or remove |
Store API extensionCartUpdate, namespace siteryn-donations | The box on Cart and Checkout block pages |
| Form post to the current page | The no-JavaScript fallback |
wp_ajax_siteryn_donations_save_settings | Save Changes in the settings |
admin_post_siteryn_donations_reset_settings / admin_post_siteryn_donations_pro_reset_settings | Reset to Defaults |
wp_ajax_siteryn_donations_pro_license_action | License activate and deactivate |
wp_ajax_siteryn_donations_pro_recalculate | Recalculate campaign totals |
admin_post_siteryn_donations_pro_export | Export CSV |
Admin actions require manage_woocommerce and a nonce; Pro's also require an active license (except license activation).
Data
| Where | Key | Holds |
|---|---|---|
| Option | siteryn_donations_settings | Free settings |
| Option | siteryn_donations_product_id / siteryn_donations_page_id | The product and page created on activation |
| Product meta | _siteryn_donation = yes | The Donation flag |
| Cart item | siteryn_donation | array( 'amount' => '10', … ) |
| Order item meta | _siteryn_donation, _siteryn_donation_amount | Marks a donation line and its amount |
| Option Pro | siteryn_donations_pro_settings | Pro settings |
| Product meta Pro | _siteryn_donations_pro_campaign, _siteryn_donations_pro_raised, _siteryn_donations_pro_donors | Campaign settings and running totals |
| Order meta Pro | _siteryn_donations_pro_tally, _siteryn_donations_pro_total | What the order last added to each campaign |
| Order item meta Pro | _siteryn_donations_recurring, _siteryn_donations_recurring_paid | The chosen frequency, and when the paid hook fired |
Order data is read and written only through WooCommerce's own APIs, so it works with HPOS. Campaign totals change by differences only, so re-processing an order never counts it twice.
WPML and Polylang
wpml-config.xml declares the translatable text settings and copies the _siteryn_donation flag to translations. The Multilingual class (object_id(), matching_ids(), with_language(), order_language()…) is public for extensions; siteryn_donations_order_language changes the language of an order's emails.