Skip to content

Hook reference

This file is generated from the doc blocks of the hooks the plugin fires. To change it, edit the doc block in the source and run make hook-docs. make check-hooks (part of the lint workflow) fails when this file is out of date.

Every hook is prefixed sc_wpun_. A name with a part in braces, such as sc_wpun_channel_payload_{type}, is dynamic: the part in braces is replaced when the hook fires.

Update check

sc_wpun_after_update_check

Action, since 2.0.0

Fires when an update check has finished, after the state was saved.

It fires even if nothing was sent, with an empty $results.

Parameter Type Description
$notification Notification The notification of the check, with every item that was waiting.
$results array<string, Delivery_Result> Result by channel instance id, for the instances something was sent to.

Fired in includes/class-update-checker.php.

sc_wpun_before_update_check

Action, since 2.0.0

Fires when an update check starts, before anything is looked up.

Fired in includes/class-update-checker.php.

sc_wpun_frequencies

Filter, since 2.0.0

Filters the names of the cron schedules offered as check frequencies.

Each must be a registered schedule (see the cron_schedules filter) of at least an hour.

Parameter Type Description
$names string[] Schedule names. Default hourly, twicedaily, daily and weekly.

Fired in includes/class-frequencies.php.

Items and routing

sc_wpun_channel_should_receive_item

Filter, since 2.0.0

Filters whether a channel instance receives an item, for rules of your own.

Runs after the instance's own rules, so it can veto an item the rules let through and allow one they blocked.

Example, send only plugins named "security" to the instance called "security_team":

add_filter(
    'sc_wpun_channel_should_receive_item',
    function ( $receive, $item, $instance ) {
        if ( 'security_team' === $instance->get_id() && 'plugin' === $item->get_type() ) {
            return false !== stripos( $item->get_name(), 'security' );
        }
        return $receive;
    },
    10,
    3
);
Parameter Type Description
$receive bool Whether the instance receives the item.
$item Notification_Item The item.
$instance Channel_Instance The instance.

Fired in includes/class-routing.php.

sc_wpun_core_needs_update

Filter, since 2.0.0

Filters whether a WordPress core update is reported, like the plugin and theme filters do for theirs.

The default follows the "Notify about WordPress updates?" setting: true, or with "only major releases" whether the update is a major.minor change. Returning false reports no core item. What was already notified about core is kept while the update is waiting.

Example, ignore release candidates:

add_filter(
    'sc_wpun_core_needs_update',
    function ( $needs, $new_version ) {
        return $needs && false === strpos( $new_version, '-RC' );
    },
    10,
    2
);
Parameter Type Description
$needs bool Whether to report the update. Default true, or whether it is a major release with "only major releases".
$new_version string The version WordPress offers.
$current_version string The installed version.

Fired in includes/class-update-checker.php.

sc_wpun_item_types

Filter, since 2.0.0

Filters the item types, to register types of your own.

A type is a key of lower case letters, digits and underscores, with a label. Invalid entries are dropped, and core, plugin and theme cannot be removed or renamed away.

Example, register a type for PHP end-of-life warnings:

add_filter(
    'sc_wpun_item_types',
    function ( $types ) {
        $types['php'] = __( 'PHP', 'my-addon' );
        return $types;
    }
);
Parameter Type Description
$types array<string, string> Type => label.

Fired in includes/class-item-types.php.

sc_wpun_notification

Filter, since 2.0.0

Filters the notification built by the update check, before any channel instance gets its share.

Must return a Notification; anything else is ignored. Each instance then receives the items of the returned notification that its routing allows.

Example, drop the notes of every item:

add_filter(
    'sc_wpun_notification',
    function ( $notification ) {
        return $notification->with_items( my_strip_notes( $notification->get_items() ) );
    }
);
Parameter Type Description
$notification Notification The notification, with every item that is waiting.

Fired in includes/class-update-checker.php.

sc_wpun_plugins_need_update

Filter, since 1.0.0

Filters the plugins that are waiting for an update and will be reported.

Parameter Type Description
$plugins_need_update array<string, object> Update data from WordPress by plugin file (for example hello.php).

Fired in includes/class-update-checker.php.

sc_wpun_should_notify_item

Filter, since 2.0.0

Filters whether an item is reported at all, to every channel instance.

An item that is vetoed is not sent and not recorded, but still counts as waiting for an update.

Example, never report one plugin:

add_filter(
    'sc_wpun_should_notify_item',
    function ( $notify, $item ) {
        return 'noisy/noisy.php' === $item->get_key() ? false : $notify;
    },
    10,
    2
);
Parameter Type Description
$notify bool Whether to report the item. Default true.
$item Notification_Item The item.

Fired in includes/class-update-checker.php.

sc_wpun_themes_need_update

Filter, since 1.0.0

Filters the themes that are waiting for an update and will be reported.

Parameter Type Description
$themes_need_update array<string, array<string, mixed>> Update data from WordPress by theme stylesheet.

Fired in includes/class-update-checker.php.

sc_wpun_update_items

Filter, since 2.0.0

Filters the items found by the check, to add, remove or change items.

Runs after core, plugins and themes were collected and before the global settings' routing. Only Notification_Item objects are kept. An item type other than core, plugin and theme must be registered with the sc_wpun_item_types filter for its history to be kept up to date: once no item of a registered type is returned, what was notified about it is forgotten.

Example, report an item of your own:

add_filter(
    'sc_wpun_update_items',
    function ( $items ) {
        $items[] = new \WPUN\Notification_Item(
            array(
                'type'            => 'php',
                'key'             => 'php',
                'name'            => 'PHP',
                'current_version' => PHP_VERSION,
                'new_version'     => '8.4',
            )
        );
        return $items;
    }
);
Parameter Type Description
$items Notification_Item[] The items found, in the order of the message.

Fired in includes/class-update-checker.php.

Delivery

sc_wpun_after_dispatch

Action, since 2.0.0

Fires when a round of delivery has finished: a dispatch, or an update check that sent something.

Parameter Type Description
$results array<string, Delivery_Result> Result by channel instance id.
$notification Notification The notification that was delivered.

Fired in includes/class-dispatcher.php, includes/class-update-checker.php.

sc_wpun_channel_payload

Filter, since 2.0.0

Filters the payload of any channel just before it is sent.

The shape of the payload is up to the channel; see its documentation. The email channel uses array( 'to' => string[], 'subject' => string, 'message' => string, 'headers' => string[] ).

Example, add a recipient to every email:

add_filter(
    'sc_wpun_channel_payload',
    function ( $payload, $notification, $instance ) {
        if ( 'email' === $instance->get_type() ) {
            $payload['to'][] = 'archive@example.org';
        }
        return $payload;
    },
    10,
    3
);

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$payload mixed The payload.
$notification Notification What is being delivered.
$instance Channel_Instance The instance it is delivered through.

Fired in includes/abstract-class-channel.php.

sc_wpun_channel_payload_{type}

Filter, since 2.0.0

Filters the payload of the channels of one type just before it is sent.

The dynamic part, $type, is the channel type, for example email. The arguments are the same as for sc_wpun_channel_payload.

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$payload mixed The payload.
$notification Notification What is being delivered.
$instance Channel_Instance The instance it is delivered through.

Fired in includes/abstract-class-channel.php.

sc_wpun_email_content

Filter, since 1.4.3. Since 2.0.0 also receives the notification and the instance, and is not HTML-escaped.

Filters the body of the email.

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$body string Body: plain text, or HTML if the instance is set to HTML. An HTML body is a fragment: it is wrapped in a document with the language, direction and title after this filter.
$notification Notification The notification.
$instance Channel_Instance The instance sending it.

Fired in includes/class-notifier.php, modules/email/class-email-channel.php.

sc_wpun_email_subject

Filter, since 1.4.3. Since 2.0.0 also receives the notification and the instance.

Filters the subject of the email.

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$subject string Subject, including the prefix.
$notification Notification The notification.
$instance Channel_Instance The instance sending it.

Fired in includes/class-notifier.php, modules/email/class-email-channel.php.

sc_wpun_message_text

Filter, since 2.0.0

Filters the plain text of a notification, which channels use as the message.

When a length limit is given to the renderer, the filter may run more than once for one message, and the length is measured on what the filter returns. $notification is then a copy with only the items shown when the message was shortened.

Example, add a line at the end:

add_filter(
    'sc_wpun_message_text',
    function ( $text, $notification ) {
        return $text . "\n\n-- Sent by my agency";
    },
    10,
    2
);
Parameter Type Description
$text string The plain text.
$notification Notification The notification it was made from.
$hidden int How many items were left out of the text, 0 when none.

Fired in includes/class-notification-renderer.php.

sc_wpun_more_items_text

Filter, since 2.0.0

Filters the line that says how many items were left out of a shortened message.

Return plain text: it is escaped for the format (Markdown, HTML) where needed. The line only exists when at least one item was left out.

Example, say it in another way:

add_filter(
    'sc_wpun_more_items_text',
    function ( $text, $hidden ) {
        return sprintf( '(%d more not shown)', $hidden );
    },
    10,
    2
);
Parameter Type Description
$text string The line, for example "…and 3 more".
$hidden int How many items were left out.
$notification Notification The notification, with all its items.

Fired in includes/class-notification-renderer.php.

sc_wpun_notification_failed

Action, since 2.0.0

Fires when delivering a notification through a channel instance failed.

Also fires for an instance that is switched off or whose channel is not available, when a delivery to it was asked for.

A result with a retry_after defers the instance: update checks skip it until then (at most 7 days).

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$result Delivery_Result The result, with the reason in its code and message.
$notification Notification What was to be delivered.
$instance Channel_Instance The instance.

Fired in includes/class-dispatcher.php.

sc_wpun_notification_sent

Action, since 2.0.0

Fires when a notification was delivered through a channel instance.

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$result Delivery_Result The result.
$notification Notification What was delivered.
$instance Channel_Instance The instance it was delivered through.

Fired in includes/class-dispatcher.php.

sc_wpun_pre_send

Filter, since 2.0.0

Filters a delivery before it happens, to replace it with a result of your own.

Return a Delivery_Result to skip the channel and use that result; any other value sends as normal. Runs for every instance that is switched on and whose channel is available.

Example, hold all deliveries during maintenance:

add_filter(
    'sc_wpun_pre_send',
    function ( $pre, $notification, $instance ) {
        return my_maintenance_mode()
            ? \WPUN\Delivery_Result::failure( 'Held back.', 'maintenance' )
            : $pre;
    },
    10,
    3
);

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$pre null\|Delivery_Result Null. Return a Delivery_Result to short-circuit.
$notification Notification What is being delivered.
$instance Channel_Instance The instance it is delivered through.

Fired in includes/class-dispatcher.php.

Channels and fields

sc_wpun_channel_deleted

Action, since 2.0.0

Fires after a channel instance was deleted.

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$id string Identifier of the deleted instance.
$instance Channel_Instance The deleted instance.

Fired in includes/class-channel-store.php.

sc_wpun_channel_fields

Filter, since 2.0.0

Filters the settings fields of a channel type.

The fields are drawn on the add and edit forms, checked by the default Channel::validate_settings() and can be supplied from outside the database. Same schema as Channel::get_fields().

A channel that overrides validate_settings() decides for itself what it keeps, so a field added to it here is drawn but may not be saved. The email channel is one: it keeps only its own fields. Changing the texts of existing fields is always safe.

Example, change the help text of the email channel's recipients:

add_filter(
    'sc_wpun_channel_fields',
    function ( $fields, $type ) {
        if ( 'email' === $type && isset( $fields['to'] ) ) {
            $fields['to']['description'] = 'Use the team mailing list.';
        }
        return $fields;
    },
    10,
    2
);
Parameter Type Description
$fields array<string, array<string, mixed>> The field schemas by name.
$type string The channel type.

Fired in includes/abstract-class-channel.php.

sc_wpun_channel_rejected

Action, since 2.0.0

Fires when a channel is refused because the API version of the site does not satisfy what it needs.

Example:

add_action(
    'sc_wpun_channel_rejected',
    function ( $type, $reason, $channel ) {
        error_log( sprintf( 'Channel "%s" was refused: %s', $type, $reason ) );
    },
    10,
    3
);
Parameter Type Description
$type string The channel type.
$reason string Why it was refused, as plain text.
$channel Channel The channel that was refused.

Fired in includes/class-channel-registry.php.

sc_wpun_channels

Filter, since 2.0.0

Filters the channel instances defined in code.

Starts with the instances of the SC_WPUN_CHANNELS constant. Entries are Channel_Instance objects or arrays with the keys id, type, label, enabled, settings and routing. An instance defined here replaces a stored one with the same id, is read-only in the admin and works like any other for delivery. Invalid entries are reported and skipped.

Example:

add_filter(
    'sc_wpun_channels',
    function ( $channels ) {
        $channels[] = array(
            'id'       => 'ops_email',
            'type'     => 'email',
            'label'    => 'Operations',
            'enabled'  => true,
            'settings' => array( 'to' => 'ops@example.org' ),
        );
        return $channels;
    }
);
Parameter Type Description
$channels array<int\|string, Channel_Instance\|array<string, mixed>> The instances.

Fired in includes/class-channel-store.php.

sc_wpun_channels_json

Filter, since 2.0.0

Filters the JSON text of the SC_WPUN_CHANNELS constant, which defines channel instances in code.

Null when the constant is not defined. A filter can supply the JSON itself, for example from a secrets service. The text is a JSON array of objects with the keys id, type, label, enabled, settings and routing.

Parameter Type Description
$json string\|null The JSON text, or null.

Fired in includes/class-channel-store.php.

sc_wpun_field_types

Filter, since 2.0.0

Filters the field types the settings screen can draw and settings can be checked with.

The array is keyed by type. Each entry is an array with a render and a sanitize callable. The built-in types (text, textarea, url, email_list, secret, number, boolean and enum) are in it in the same shape, so an add-on can replace one. checkbox and select are aliases of boolean and enum. An entry that is not an array of two callables is dropped, with a notice to the developer.

render( $field, $name, $id, $value, $disabled, $described_by, $error ) returns the escaped markup of the control. $field is the field schema, $name the name attribute, $id the id, $value the current value, $disabled whether the control is read-only and $described_by the ids of the elements that describe it. $error is the message of an error to show, or an empty string; the error text itself is drawn by the caller, so the control only needs to be marked invalid.

For a field with secret set, $value is '1' when a value is saved and '' when not: the real value is never passed to the callable.

sanitize( $value, $field ) returns the clean value, or a WP_Error when the value is not valid. $field is the field schema, with its name added. The error is reported against the field.

Example, add a colour type:

add_filter(
    'sc_wpun_field_types',
    function ( $types ) {
        $types['colour'] = array(
            'render'   => function ( $field, $name, $id, $value ) {
                return '<input type="color" id="' . esc_attr( $id ) . '" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" />';
            },
            'sanitize' => function ( $value ) {
                return sanitize_hex_color( $value ) ? sanitize_hex_color( $value ) : new WP_Error( 'invalid_colour', 'Enter a colour.' );
            },
        );
        return $types;
    }
);
Parameter Type Description
$types array<string, array{render: callable, sanitize: callable}> Field types by name.

Fired in includes/class-field-types.php.

sc_wpun_register_channels

Action, since 2.0.0

Fires when the notification channels are first needed, for modules and add-ons to register theirs.

Example:

add_action(
    'sc_wpun_register_channels',
    function ( \WPUN\Channel_Registry $registry ) {
        $registry->register( new My_Channel() );
    }
);
Parameter Type Description
$registry Channel_Registry The registry to register channels with.

Fired in includes/class-channel-registry.php.

Configuration

sc_wpun_config_sources

Filter, since 2.0.0

Filters the configuration sources, in the order they are asked.

The first source to return a value wins. By default constants come first, then environment variables if enabled. Add your own to read from a secrets service, or reorder the list. Entries that are not Config_Source objects are dropped.

Example, ask a source of your own after the constants:

add_filter(
    'sc_wpun_config_sources',
    function ( $sources ) {
        $sources[] = new My_Vault_Source();
        return $sources;
    }
);
Parameter Type Description
$sources Config_Source[] The sources.

Fired in includes/class-config.php.

sc_wpun_config_value

Filter, since 2.0.0

Filters the value of a setting or channel field, the last word before the database is used.

Receives what the configuration sources supplied, or null if none did. Return a value to override it, or null to use the saved value from the database. Values are scalars and are cast to the type of the setting or field. Do not log the value: it can be a secret.

Example, take the check frequency from a site option of your own:

add_filter(
    'sc_wpun_config_value',
    function ( $value, $context, $source ) {
        if ( 'frequency' === $context->get_setting() ) {
            return get_site_option( 'my_frequency', $value );
        }
        return $value;
    },
    10,
    3
);
Parameter Type Description
$value string\|bool\|int\|float\|null The value the sources supplied, or null.
$context Config_Context What is asked for, and the site.
$source string\|null Where the value came from, or null.

Fired in includes/class-config.php.

sc_wpun_default_settings

Filter, since 2.0.0

Filters the settings a new install starts with, and the values used for settings that are missing.

Only the keys below are used, and values are cast to the type shown. Anything else is ignored, as is a return value that is not an array. A notify setting that is not one of its keys falls back to the built-in default.

Example, check daily by default:

add_filter(
    'sc_wpun_default_settings',
    function ( $defaults ) {
        $defaults['frequency'] = 'daily';
        return $defaults;
    }
);
Parameter Type Description
$defaults array<string, mixed> The default settings.
- string $frequency Name of a cron schedule.
- string $notify_core none, all or major (major releases only).
- string $notify_plugins none, all or active (active plugins only).
- string $notify_themes none, all or active (active themes only).
- bool $hide_updates True to hide the WordPress update notice from users who cannot update.

Fired in includes/class-settings.php.

sc_wpun_get_options_filter

Filter, since 1.4.0

Filters a setting option of the plugin after it is read.

Parameter Type Description
$value mixed The stored value.
$field string The name of the option.

Fired in includes/class-channel-store.php, includes/class-settings.php, includes/class-state.php.

sc_wpun_load_from_env

Filter, since 2.0.0

Filters whether configuration is also read from environment variables.

Off unless the environment variable SC_WPUN_LOAD_FROM_ENV is set to an "on" value (1, true, yes or on), so variables a host happens to set never change the plugin's behaviour by surprise.

Parameter Type Description
$load_from_env bool Whether to read environment variables.

Fired in includes/class-config.php.

sc_wpun_put_options_filter

Filter, since 1.4.0

Filters a setting option of the plugin before it is stored.

Parameter Type Description
$value mixed The value about to be stored.
$field string The name of the option.

Fired in includes/class-channel-store.php, includes/class-settings.php, includes/class-state.php.

Settings screen

sc_wpun_after_channel_form

Action, since 2.0.0

Fires inside the add and edit form of a channel, after its last section and before the buttons.

On the form of a new channel the instance is a provisional, unsaved one: the id it would get from the prefilled label, the type, the label of the module, switched off, with the default settings.

Example, add a note:

add_action(
    'sc_wpun_after_channel_form',
    function ( $instance, $channel ) {
        echo '<p>' . esc_html( $instance->get_id() ) . '</p>';
    },
    10,
    2
);

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$instance Channel_Instance The instance being edited, or the provisional one of a new channel.
$channel Channel The module of the instance.

Fired in includes/admin/class-channel-form.php.

sc_wpun_before_channel_form

Action, since 2.0.0

Fires inside the add and edit form of a channel, before its first section.

Output extra markup here. The plugin does not save extra inputs. On the form of a new channel the instance is a provisional, unsaved one: the id it would get from the prefilled label, the type, the label of the module, switched off, with the default settings.

Example, add a note:

add_action(
    'sc_wpun_before_channel_form',
    function ( $instance, $channel ) {
        echo '<p>' . esc_html( $channel->get_label() ) . '</p>';
    },
    10,
    2
);

$instance holds the resolved settings, secrets included: don't log or dump its settings.

Parameter Type Description
$instance Channel_Instance The instance being edited, or the provisional one of a new channel.
$channel Channel The module of the instance.

Fired in includes/admin/class-channel-form.php.

sc_wpun_capability

Filter, since 2.0.0

Filters the capability needed to use the plugin's settings page.

It decides who sees the settings page, saves the settings, sends a test message and dismisses the plugin's notice. An empty or non-string value is ignored.

Lowering it hands every user with the capability control over where the plugin's notifications go. Such a user can:

  • send the update notifications, a list of the site's outdated and possibly vulnerable plugins and themes, to any address;
  • send test messages to any address;
  • change the From and Reply-To addresses;
  • add, edit, switch off, duplicate and delete channels;
  • hide the core update notice and run the update check on demand;
  • see the values of channel settings set in wp-config.php or by the environment when the field is not secret and its schema sets show_external.

Example, let editors manage the plugin:

add_filter( 'sc_wpun_capability', fn() => 'edit_pages' );
Parameter Type Description
$capability string Capability. Default manage_options.

Fired in includes/admin/class-settings-page.php.

sc_wpun_settings_tab_{tab}

Action, since 2.0.0

Draws a tab of the settings screen.

The dynamic part, $tab, is the tab's slug. Add the tab with the sc_wpun_settings_tabs filter; it is listed only while something is hooked here. Output inside the screen's wrapper.

Fired in includes/admin/class-settings-page.php.

sc_wpun_settings_tabs

Filter, since 2.0.0

Filters the tabs of the settings screen.

A tab is shown only if something is hooked on sc_wpun_settings_tab_{$tab} to draw it. Entries whose slug is not a string equal to its sanitize_key() form, or whose label is not a string, are ignored. The General tab cannot be removed.

Example, add a tab:

add_filter( 'sc_wpun_settings_tabs', fn( $tabs ) => $tabs + array( 'mine' => 'Mine' ) );
add_action( 'sc_wpun_settings_tab_mine', fn() => print '<p>Hello</p>' );
Parameter Type Description
$tabs array<string, string> Tab labels keyed by slug. Default general, channels and about. The About tab is always moved last, and is hidden by the show_about setting (code only).

Fired in includes/admin/class-settings-page.php.

Lifecycle and legacy

sc_wpun_disable_cron

Action, since 1.0.0

Fires when the plugin is deactivated, to turn the scheduled check off.

Fired in includes/class-plugin.php, includes/class-scheduler.php.

sc_wpun_loaded

Action, since 2.0.0

Fires when the plugin has loaded and its hooks are registered.

Add-ons can use it as the moment to start talking to the plugin's API.

Fired in includes/class-plugin.php.

Actions you can fire

The plugin listens to these actions but does not fire them itself. Call them with do_action().

sc_wpun_enable_cron

Action, since 1.0.0

Schedules the update check. Handled by the Scheduler class.

Kept from 1.x. Schedules the check at the saved frequency, unless it is already scheduled at it. The plugin does this itself on every request (on init), so there is rarely a reason to call it. Pass a frequency to schedule at it instead of the saved one; manual stops the checks, as sc_wpun_disable_cron does.

do_action( 'sc_wpun_enable_cron' );
do_action( 'sc_wpun_enable_cron', 'daily' );
Parameter Type Description
$frequency string Optional. A frequency key from sc_wpun_frequencies, such as daily, or manual. Default is the saved frequency.

Handled in includes/class-plugin.php.

sc_wpun_run_check

Action, since 2.0.0

Runs the update check now.

It works as a scheduled run does: same routing, per-instance dedupe, delivery state and hooks, so items an instance was already told about are not sent again. The notification source is manual and the schedule is not changed. Use it from a deploy script, or from a system cron when DISABLE_WP_CRON is set, for example wp eval "do_action( 'sc_wpun_run_check' );".

There is no lock: a run that overlaps another check, scheduled or manual, can send an update the other is also sending, so it may arrive twice. A channel that must never deliver twice can keep its own record of what it sent.

do_action( 'sc_wpun_run_check' );

There is no capability check. Before firing it from anything a user can reach, check current_user_can() with the capability from the sc_wpun_capability filter.

Handled in includes/class-plugin.php.