Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Send
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 init
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
6
 uninstall
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Jetpack Send bootstrap.
4 *
5 * @package automattic/jetpack-send
6 */
7
8namespace Automattic\Jetpack\Send;
9
10if ( ! defined( 'ABSPATH' ) ) {
11    exit( 0 );
12}
13
14/**
15 * Wires Jetpack Send's hooks.
16 */
17class Send {
18
19    /**
20     * Package version, bumped at release through composer.json `version-constants`.
21     *
22     * @var string
23     */
24    const PACKAGE_VERSION = '0.1.0-alpha';
25
26    /**
27     * Whether init() already ran.
28     *
29     * @var bool
30     */
31    private static $initialized = false;
32
33    /**
34     * Wire the hooks once.
35     *
36     * @return void
37     */
38    public static function init() {
39        if ( self::$initialized ) {
40            return;
41        }
42        self::$initialized = true;
43
44        Admin_Page::init();
45        Email_Log::init();
46        Dns_Watch::init();
47        Ready_Notice::init();
48        add_action( 'rest_api_init', array( REST_Controller::class, 'register_routes' ) );
49        add_action( 'rest_api_init', array( Dns_REST_Controller::class, 'register_routes' ) );
50        add_action( 'rest_api_init', array( Cloudflare_REST_Controller::class, 'register_routes' ) );
51        add_action( 'rest_api_init', array( Debug_REST_Controller::class, 'register_routes' ) );
52        add_filter( 'pre_wp_mail', array( Mailer::class, 'pre_wp_mail' ), 10, 2 );
53        // What the host's mail did with an email Send handed it.
54        add_action( 'wp_mail_succeeded', array( Mailer::class, 'host_succeeded' ) );
55        add_action( 'wp_mail_failed', array( Mailer::class, 'host_failed' ) );
56        add_action( 'shutdown', array( Mailer::class, 'clear_pending' ) );
57        // Background work that only adds, on admin pages; deleting is left to the hourly job.
58        add_action( 'admin_init', array( Stats::class, 'backfill_batch' ), 10, 0 );
59        add_action( 'admin_init', array( Email_Log::class, 'backfill_batch' ), 10, 0 );
60        add_action( 'admin_init', array( Debug_Log::class, 'expire_if_due' ), 10, 0 );
61    }
62
63    /**
64     * Remove everything Send stored on the site: the log, counts and debug tables and their options too.
65     *
66     * @return void
67     */
68    public static function uninstall() {
69        Dns_Watch::stop();
70        Onboarding::delete();
71        Onboarding::delete_test_history();
72        Email_Log::drop_table();
73        Settings::delete();
74        Account::delete();
75        delete_transient( REST_Controller::CHECK_DNS_THROTTLE );
76    }
77}