Developer guide
How the plugins are built, what they store, and how to extend them.
Architecture
- Free boots on
plugins_loadedafter checking PHP, WordPress and WooCommerce, then firessiteryn_ssm_loaded. Pro starts on that action and firessiteryn_ssm_pro_loaded; Free only usesdid_action( 'siteryn_ssm_pro_loaded' )to hide its upsell. - Pro never writes subscription data directly: it saves through
SubscriptionRepositoryand changes statuses throughLifecycle::update_status(), so Free's transition rules, notes and hooks always apply. - Prefixes: PHP
siteryn_ssm_, constantsSITERYN_SSM_, CSSsiteryn-ssm-. NamespacesSiteryn\SiterynSubscriptionManager(Free) andSiterynPro\SiterynSubscriptionManager(Pro). SITERYN_SSM_API_VERSION(1.0.0) changes only when a documented hook, template contract or public method changes.
Data stored
A subscription is a private siteryn_subscription post: the customer is the post author, the status is the post status (ssm-active, ssm-on-hold…), and each property is post meta prefixed _siteryn_ssm_. Add-on data uses SubscriptionRepository::update_meta() (stored as _siteryn_ssm_x_{key}).
| Where | Key | Meaning |
|---|---|---|
| Option | siteryn_ssm_settings | Free settings (with a _schema version) |
| Option | siteryn_ssm_version, siteryn_ssm_flush_rewrite_rules | Installed version; one-time flag to rebuild links after the address changes |
| Option | siteryn_ssm_pro_settings, siteryn_ssm_pro_version | Pro settings and version |
| Options | siteryn_license_subscription-manager_key, _status, _update | Pro license state |
| Transients | siteryn_ssm_outdated_templates, siteryn_ssm_pro_mrr | Outdated template check (1 day); dashboard revenue (1 hour) |
| Product meta | _siteryn_ssm_subscription, _period, _interval, _length; Pro _siteryn_ssm_pro_switch_to | Subscription settings; plans a product can switch to |
| Order line meta | _siteryn_ssm_period, _interval, _length, _siteryn_ssm_subscription_id | Schedule snapshot; the subscription the line created or renews |
| Order meta | _siteryn_ssm_renewal_of, _siteryn_ssm_renewal_applied | On renewal orders |
| Order meta (Pro) | _siteryn_ssm_pro_switch_of, _switch_to, _switch_applied | On prorated plan switch orders |
| Subscription data (Pro) | pro_paused_at, pro_resume_at, pro_payment_method, pro_pending_switch, pro_switch_history, pro_reminded_for, pro_original_end | Pause dates, payment method, switching, reminders, cancellation |
| Subscription meta | _siteryn_ssm_language, _siteryn_ssm_locale | Multilingual sites only: the language the subscription was bought in |
Functions
| Function | Returns |
|---|---|
siteryn_ssm_is_loaded() | Whether Free booted (bool) |
siteryn_ssm() | The running plugin instance, or null |
siteryn_ssm_get_subscription( $id ) | A Subscription, or null |
siteryn_ssm_get_customer_subscriptions( $customer_id ) | The customer's subscriptions, newest first (at most 100) |
siteryn_ssm_customer_has_active_subscription( $customer_id, $product_id = 0 ) | Whether the customer has a Pending, Active or On hold subscription, optionally to one product |
siteryn_ssm_is_subscription_product( $product ) | Whether a product (ID or object) is sold as a subscription |
// Give members a discount when they have a live subscription.
$user_id = get_current_user_id();
if ( function_exists( 'siteryn_ssm_customer_has_active_subscription' )
&& siteryn_ssm_customer_has_active_subscription( $user_id ) ) {
// Pending, Active or On hold subscription found.
}
Public classes: Subscription (value object: getters, has_status(), get_schedule_text()), SubscriptionRepository (get(), save(), get_for_customer(), get_for_order(), query(), count_by_status()…), Lifecycle (update_status(), create_renewal_order(), add_note()…), SubscriptionStatus, ProductSubscription, Period, Display, Settings and Templates.
Templates
Copy a template to yourtheme/siteryn-subscription-manager/{template} to override it. Every template has an @version; System Status and an admin notice flag theme copies older than the plugin's.
| Template | Variables |
|---|---|
myaccount/subscriptions.php | $subscriptions, $current_page, $total_pages, $settings |
myaccount/view-subscription.php | $subscription, $actions, $orders, $settings |
order/related-subscriptions.php | $subscriptions, $order, $can_view, $settings |
parts/status-badge.php | $subscription |
parts/subscription-actions.php | $subscription, $actions, $context (list or view) |
Pro's email template emails/subscription-notice.php (and emails/plain/subscription-notice.php) is overridden the WooCommerce way, in yourtheme/woocommerce/emails/.
CSS
Every template's wrapper has .siteryn-ssm plus .siteryn-ssm--list, --view, --order and .siteryn-ssm--badge-filled or --badge-outline. Status colors are custom properties on .siteryn-ssm: --siteryn-ssm-status-active, -on-hold, -pending, -cancelled, -expired. Badges are .siteryn-ssm-status.siteryn-ssm-status--{status}. The stylesheet loads only on My Account and order confirmation pages (filter siteryn_ssm_load_assets); the storefront loads no JavaScript.
Scheduled events and endpoints
| Event / action | What it is |
|---|---|
siteryn_ssm_process_subscriptions | Hourly WP-Cron event: renewals, expiries, overdue cancellations; Pro adds auto-resume, pending cancellations and reminders |
siteryn_ssm_pro_license_check | Daily Pro license refresh |
wp_ajax_siteryn_ssm_save_settings | Saves a settings tab (manage_woocommerce, nonce) |
wp_ajax_siteryn_ssm_pro_license_action | License activate, deactivate, refresh |
admin_post_siteryn_ssm_reset_settings, admin_post_siteryn_ssm_pro_reset_settings | Reset to Defaults |
admin_post_siteryn_ssm_pro_save_subscription, admin_post_siteryn_ssm_pro_recurring_action | Subscription editor save and renewal actions |
Customer actions (Pro) are plain requests to the subscription's page with siteryn_ssm_do, subscription and a nonce; confirmations use ?siteryn_ssm_confirm=cancel|switch|payment_method. There is no REST API.
Constants
| Constant | Value |
|---|---|
SITERYN_SSM_VERSION, SITERYN_SSM_PRO_VERSION | Plugin versions |
SITERYN_SSM_API_VERSION | Extension API version |
SITERYN_SSM_MIN_PHP_VERSION, _MIN_WP_VERSION, _MIN_WC_VERSION | 7.4, 6.4, 8.0 |
SITERYN_SSM_REMOVE_ALL_DATA | Define as true before deleting the plugin to delete every subscription |
SITERYN_SSM_PRO_LICENSE_API_BASE | License server, overridable in wp-config.php (for example for staging) |