init(); } /** * Build services. */ private function __construct() { $this->settings = new Settings(); $this->database = new Database(); $this->calculators = new Calculator( $this->database ); $this->pricing = new Pricing_Repository( $this->database ); $this->engine = new Pricing_Engine( $this->settings, $this->pricing ); $this->validator = new Lead_Validator( $this->settings, $this->engine ); $this->leads = new Lead_Manager( $this->database ); $this->security = new Security( $this->settings ); $this->notifications = new Notifications( $this->settings, $this->leads ); $this->rest = new Rest_Api( $this ); $this->privacy = new Privacy( $this->leads ); $this->frontend = new Frontend( $this ); } /** * Register hooks. */ private function init(): void { add_action( 'init', array( $this->frontend, 'register_assets' ) ); add_action( 'init', array( new Shortcode( $this ), 'register' ) ); add_action( 'wp_enqueue_scripts', array( $this->frontend, 'maybe_enqueue_early' ) ); add_action( 'rest_api_init', array( $this->rest, 'register_routes' ) ); add_action( 'thinroof_lead_created', array( $this->notifications, 'on_lead_created' ), 10, 2 ); add_action( 'wp_mail_failed', array( $this->notifications, 'capture_mail_error' ) ); add_action( Activator::CRON_HOOK, array( $this->leads, 'purge_expired' ) ); add_action( 'admin_init', array( Activator::class, 'maybe_install' ) ); add_action( 'wp_initialize_site', array( Activator::class, 'on_new_site' ), 200 ); $this->privacy->register(); if ( is_admin() ) { $this->admin = new Admin( $this ); $this->admin->register(); } /** * Fires when ThinRoof is fully loaded. Premium modules hook in here. * * @param Plugin $plugin Plugin instance. */ do_action( 'thinroof_loaded', $this ); } /** * Whether a premium add-on has declared itself active. */ public function is_premium_active(): bool { return (bool) apply_filters( 'thinroof_is_premium_active', false ); } }