Skip to main content

Keep a log of every add-on install, update and refused download

Free Beginner

For an agency looking after many podcasters’ sites: a record of what the Benecaster Add-on Manager installed and updated, and of every download it refused. A refused download is the one event worth an alert, because it means a zip did not carry Benecaster’s signature.

These are side effects only: nothing an action returns is read, and none of them can undo a refusal. No argument carries the site token and $package carries no credential, so logging them is safe. The Add-on Manager’s own update fires only the package actions, not the add-on ones.

Code

<?php
add_action( 'benecaster_manager_addon_installed', function ( string $slug, string $plugin, bool $activated ): void {
    error_log( sprintf( 'Benecaster add-on installed: %s (%s)%s', $slug, $plugin, $activated ? '' : ' — not activated' ) );
}, 10, 3 );

add_action( 'benecaster_manager_addon_updated', function ( string $slug, string $plugin, string $version ): void {
    error_log( sprintf( 'Benecaster add-on updated: %s to %s', $slug, $version ) );
}, 10, 3 );

add_action( 'benecaster_manager_package_rejected', function ( string $package, WP_Error $error, array $context ): void {
    wp_mail( get_option( 'admin_email' ), 'A Benecaster download was refused', sprintf(
        "%s (%s)\n%s\n%s",
        $context['slug'] ?: 'unknown product',
        $context['action'] ?: 'download',
        $error->get_error_code(),
        $package
    ) );
}, 10, 3 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →