get(Notify\Notifier::class)->finished($job); if (!empty($job->restore_point['files']) && empty($job->restore_point['files']['archive'])) { Files\PointArchive::schedule(); // the items it replaced are packed into an archive } }); add_action(Files\PointArchive::HOOK, static fn () => self::container()->get(Files\PointArchive::class)->run()); add_action('relay_daily', static function (): void { self::container()->get(Files\PointArchive::class)->run(); // in case the scheduled packing never ran self::container()->get(Jobs\JobService::class)->sweep(); self::container()->get(Backups\BackupService::class)->sweep(); self::container()->get(Security\ReplayGuard::class)->prune(); }); if (!wp_next_scheduled('relay_daily')) { wp_schedule_event(time() + HOUR_IN_SECONDS, 'daily', 'relay_daily'); } add_action('rest_api_init', static function (): void { self::container()->get(Rest\RestApi::class)->register(); self::container()->get(Remote\Endpoint::class)->register_rest(); }); add_action('wp_ajax_nopriv_relay_remote', static fn () => self::container()->get(Remote\Endpoint::class)->ajax()); add_action('wp_ajax_relay_remote', static fn () => self::container()->get(Remote\Endpoint::class)->ajax()); if (!empty($_SERVER['HTTP_X_RELAY_SIGNATURE'])) { // Relay requests authenticate by signature; a basic-auth header meant for a staging server must // not be taken for an application password (which would fail the request). add_filter('wp_is_application_passwords_available', '__return_false'); } if (defined('WP_CLI') && WP_CLI) { Cli\Registrar::register(); } if (\Relay\Security\SiteMode::constant_state() === 'invalid') { add_action(is_multisite() ? 'network_admin_notices' : 'admin_notices', [self::class, 'mode_notice']); } if (is_admin()) { Install\CompatPlugin::remove(); // the must-use helper an earlier version may have written add_action(is_multisite() ? 'network_admin_notices' : 'admin_notices', [self::class, 'old_relay_notice']); self::container()->get(Admin\Menu::class)->register(); $links = static function (array $links): array { if (Support\Capability::check()) { array_unshift($links, '' . esc_html__('Open SiteRelay', 'siterelay') . ''); } return $links; }; add_filter((is_multisite() ? 'network_admin_plugin_action_links_' : 'plugin_action_links_') . plugin_basename(RELAY_FILE), $links); } } /** * Translations shipped in Relay's languages folder, for the language the current person uses. Loaded from Relay's * own folder (wherever it is installed); WordPress.org language packs still load on their own when there is none. */ public static function load_translations(): void { load_textdomain('siterelay', RELAY_DIR . 'languages/siterelay-' . determine_locale() . '.mo'); } /** Relay 0.9.x is still installed next to SiteRelay: it can go, and deleting it is safe (see Uninstaller). */ public static function old_relay_notice(): void { if (!Support\Capability::check() || !file_exists(WP_PLUGIN_DIR . '/relay-migrate/relay-migrate.php')) { return; } echo '

' . esc_html__('SiteRelay is the new name of Relay. You can delete the old Relay plugin on the Plugins screen: SiteRelay keeps your settings, access keys, history and backups.', 'siterelay') . '

'; } public static function multisite_notice(): void { if (!current_user_can('manage_network_options')) { return; } echo '

' . esc_html__('SiteRelay runs on a multisite network only when it is network-activated. Network-activate it under Network Admin → Plugins; until then it does nothing.', 'siterelay') . '

'; } public static function mode_notice(): void { if (!Support\Capability::check()) { return; } echo '

' . esc_html__('RELAY_MODE in wp-config.php has an unknown value, so SiteRelay treats this site as locked. Use locked, pull-only, push-only or open.', 'siterelay') . '

'; } public static function container(): Container { if (self::$container === null) { self::boot(); } return self::$container; } }