loader = new Razorbooking_Loader(); $this->credentials = new Razorbooking_Credentials(); $this->api = new Razorbooking_Api( $this->credentials ); $this->copies = new Razorbooking_Copies(); // Reading and writing RazorBooking data. $this->connection = new Razorbooking_Connection_Repository( $this->credentials, $this->copies, $this->api ); $this->settings = new Razorbooking_Settings_Repository(); $this->sync = new Razorbooking_Sync( $this->api, $this->copies, $this->connection ); $this->business = new Razorbooking_Business_Repository( $this->copies ); $this->services = new Razorbooking_Service_Repository( $this->api, $this->copies, $this->business ); $this->categories = new Razorbooking_Category_Repository( $this->api, $this->copies ); $this->resources = new Razorbooking_Resource_Repository( $this->api, $this->copies ); $this->team = new Razorbooking_Team_Repository( $this->api, $this->copies, $this->connection ); $this->design = new Razorbooking_Design_Repository( $this->api, $this->copies, $this->connection ); $this->confirmation = new Razorbooking_Confirmation_Repository( $this->api ); $this->catalog = new Razorbooking_Editor_Catalog( $this->connection, $this->services, $this->categories, $this->team ); // Pages: what visitors see. $this->embed = new Razorbooking_Embed( $this->connection, $this->settings, $this->services, $this->design ); $this->public = new Razorbooking_Public( $this->connection, $this->settings, $this->design, $this->embed ); $this->seo = new Razorbooking_Seo( $this->connection, $this->business, $this->services, $this->team, $this->embed, $this->public ); $this->pages = new Razorbooking_Pages( $this->settings, $this->confirmation, $this->connection, $this->embed ); $this->shortcodes = new Razorbooking_Shortcodes( $this->embed ); $this->blocks = new Razorbooking_Blocks( $this->connection, $this->catalog, $this->embed, $this->public ); $this->elementor = new Razorbooking_Elementor( $this->connection, $this->catalog, $this->embed, $this->public ); // wp-admin. $this->screens = new Razorbooking_Admin_Data( $this->api, $this->copies, $this->connection, $this->resources, $this->business, $this->team ); $this->connect = new Razorbooking_Connect( $this->connection ); $this->cache_notice = new Razorbooking_Cache_Notice(); $this->activation_notice = new Razorbooking_Activation_Notice( $this->credentials ); $this->admin = new Razorbooking_Admin( $this->connection, $this->credentials, $this->cache_notice ); $this->privacy = new Razorbooking_Privacy( $this->embed ); $this->health = new Razorbooking_Health( $this->connection ); $this->activator = new Razorbooking_Activator( $this->connection, $this->settings, $this->activation_notice ); $this->deactivator = new Razorbooking_Deactivator( $this->copies ); // The admin app's REST routes. $this->controllers = array( new Razorbooking_Connection_Controller( $this->connection, $this->credentials, $this->api, $this->sync, $this->connect ), new Razorbooking_Catalog_Controller( $this->services, $this->categories, $this->resources, $this->business, $this->screens, $this->catalog, $this->shortcodes ), new Razorbooking_Team_Controller( $this->team, $this->screens ), new Razorbooking_Home_Controller( $this->screens, $this->connection, $this->settings, $this->services ), new Razorbooking_Settings_Controller( $this->settings, $this->design, $this->seo, $this->embed ), new Razorbooking_Content_Controller( $this->business, $this->api ), new Razorbooking_Pages_Controller( $this->pages, $this->settings ), ); } /** Hook everything into WordPress. */ public function run(): void { $this->admin_hooks(); $this->public_hooks(); $this->shared_hooks(); $this->loader->run(); } private function admin_hooks(): void { $this->loader->add_action( 'admin_menu', $this->admin, 'register_menu' ); $this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'menu_icon_style' ); $this->loader->add_filter( 'admin_body_class', $this->admin, 'add_body_class' ); $this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_init', $this->privacy, 'add_policy_content' ); $this->loader->add_action( 'admin_enqueue_scripts', $this->activation_notice, 'enqueue' ); $this->loader->add_action( 'admin_notices', $this->activation_notice, 'render' ); $this->loader->add_action( 'admin_post_' . Razorbooking_Activation_Notice::ACTION, $this->activation_notice, 'start_setup' ); $this->loader->add_action( 'admin_notices', $this->admin, 'render_notices' ); $this->loader->add_filter( 'admin_footer_text', $this->admin, 'footer_text' ); $this->loader->add_filter( 'plugin_action_links_' . RAZORBOOKING_BASENAME, $this->admin, 'action_links' ); $this->loader->add_filter( 'parent_file', $this->admin, 'fix_submenu_highlight' ); } private function public_hooks(): void { $this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_scripts' ); $this->loader->add_action( 'init', $this->public, 'register_shortcodes' ); $this->loader->add_filter( 'wp_resource_hints', $this->public, 'resource_hints', 10, 2 ); $this->loader->add_filter( 'script_loader_tag', 'Razorbooking_Embed', 'script_tag', 10, 2 ); // Late, after everything on the page has rendered. $this->loader->add_action( 'wp_footer', $this->public, 'render_floating_button', 100 ); $this->loader->add_action( 'wp', $this->public, 'preview_mode' ); $this->loader->add_action( 'template_redirect', $this->public, 'no_cache_confirmation' ); } private function shared_hooks(): void { $this->cache_notice->register( $this->loader ); // RazorBooking refused the stored key. $this->loader->add_action( Razorbooking_Hook::KEY_REFUSED, $this->connection, 'key_refused' ); foreach ( $this->controllers as $controller ) { $this->loader->add_action( 'rest_api_init', $controller, 'register_routes' ); } // The connect hand-off: RazorBooking posts the key from the merchant's // browser (signed in or not, depending on the browser's cookie rules), // and wp-admin saves it once an administrator is looking. $this->loader->add_action( 'admin_post_razorbooking_connect', $this->connect, 'receive_browser_handoff' ); $this->loader->add_action( 'admin_post_nopriv_razorbooking_connect', $this->connect, 'receive_browser_handoff' ); $this->loader->add_action( 'admin_init', $this->connect, 'finish_handoff' ); $this->loader->add_action( 'init', $this->blocks, 'register_blocks' ); $this->loader->add_filter( 'block_categories_all', $this->blocks, 'register_category' ); $this->loader->add_action( 'enqueue_block_editor_assets', $this->blocks, 'enqueue_editor_assets' ); $this->loader->add_filter( 'site_status_tests', $this->health, 'register' ); // In the footer, once it is known what the page shows. $this->loader->add_action( 'wp_footer', $this->seo, 'render', 5 ); $this->loader->add_action( 'post_updated', $this->pages, 'confirmation_page_updated', 10, 3 ); // These fire only when Elementor is active. $this->loader->add_action( 'elementor/elements/categories_registered', $this->elementor, 'register_category' ); $this->loader->add_action( 'elementor/widgets/register', $this->elementor, 'register_widgets' ); } /* --------------------------------------------------------------------- * For code WordPress or Elementor create themselves (see the top) * ------------------------------------------------------------------ */ public function activator(): Razorbooking_Activator { return $this->activator; } public function deactivator(): Razorbooking_Deactivator { return $this->deactivator; } public function elementor(): Razorbooking_Elementor { return $this->elementor; } /** Uninstalling: the key, the saved copies, and the settings. */ public function uninstaller(): Razorbooking_Uninstaller { return new Razorbooking_Uninstaller( $this->credentials, $this->api, $this->copies, $this->settings ); } }