*/ private $services = array(); public static function instance(): Plugin { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } private function __construct() {} /** * Register services and hooks. */ public function boot(): void { Installer::register_tables(); add_action( 'switch_blog', array( Installer::class, 'register_tables' ) ); Installer::maybe_upgrade(); $settings = new Settings(); $vault = new KeyVault(); $api = new Client( $vault ); Languages::init( $settings ); PostTypes::init( $settings ); Logger::register(); $router = new Router( $settings ); $translator = new Translator( $api ); $terms = new TermTranslator( $translator ); $posts = new PostTranslator( $translator, $settings, $terms, static function () use ( $settings ) { return array( new Fields\MetaFields( $settings ), new Fields\Elementor(), new Fields\Bricks(), new Fields\WooProduct(), ); } ); $jobs = new Jobs( $posts ); $strings = new Strings( $settings, $translator ); $this->services = compact( 'settings', 'vault', 'api', 'router', 'translator', 'terms', 'posts', 'jobs', 'strings' ); $router->register(); ( new Query( $router ) )->register(); ( new Switcher( $settings, $router ) )->register(); ( new \TranslatePlus\Frontend\Links( $router ) )->register(); ( new Hooks( $settings, $vault, $posts ) )->register(); $jobs->register(); ( new \TranslatePlus\Core\LanguagePacks() )->register(); $strings->register(); ( new FileJobs( $api, $strings ) )->register(); ( new Menus( $router, $strings ) )->register(); ( new Seo( $router ) )->register(); ( new AcfIntegration() )->register(); ( new WooCommerce( $settings, $posts, $translator ) )->register(); ( new Email( $settings, $api ) )->register(); ( new Roles() )->register(); ( new VisualEditor( $settings, $posts ) )->register(); add_action( 'rest_api_init', array( $this, 'register_rest' ) ); if ( is_admin() ) { ( new Menu() )->register(); ( new Assets( $settings ) )->register(); ( new PostList( $settings ) )->register(); ( new EditorIntegration() )->register(); } if ( defined( 'WP_CLI' ) && WP_CLI ) { \WP_CLI::add_command( 'translateplus', new Cli\Command( $this ) ); } /** * Fires after TranslatePlus has booted its core services. * * @param Plugin $plugin Plugin instance. */ do_action( 'translateplus_loaded', $this ); } public function register_rest(): void { $controllers = array( new Rest\SettingsController( $this->settings(), $this->vault(), $this->api() ), new Rest\AccountController( $this->api() ), new Rest\TranslationsController( $this->posts() ), new Rest\JobsController( $this->jobs() ), new Rest\GlossaryController(), new Rest\StringsController( $this->strings() ), new Rest\ToolsController( $this->posts(), $this->settings() ), new Rest\WebhookController(), ); foreach ( $controllers as $controller ) { $controller->register_routes(); } } public function settings(): Settings { return $this->services['settings']; } public function vault(): KeyVault { return $this->services['vault']; } public function api(): Client { return $this->services['api']; } public function router(): Router { return $this->services['router']; } public function translator(): Translator { return $this->services['translator']; } public function posts(): PostTranslator { return $this->services['posts']; } public function terms(): TermTranslator { return $this->services['terms']; } public function jobs(): Jobs { return $this->services['jobs']; } public function strings(): Strings { return $this->services['strings']; } }