*/ protected $modules = array(); /** * Returns (and creates) the plugin instance. * * @since 0.1.0 * * @return Plugin */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); self::$instance->boot(); } return self::$instance; } /** * Constructor (used privately via instance()). * * @since 0.1.0 */ protected function boot() { Options::register(); Install::maybe_upgrade(); // Always active. $this->load( 'assets', new Assets() ); $this->load( 'login_protection', new Login_Protection() ); $this->load( 'tracker', new Tracker() ); $this->load( 'support', new Support() ); $this->load( 'rest', new Rest_Api() ); $this->load( 'privacy', new Privacy() ); // Also runs on the frontend: admin bar toggle (Ghost Mode). $this->load( 'menu', new Menu_Filter() ); $this->load( 'ghost', new Ghost_Mode() ); // Only relevant in the admin area. if ( is_admin() ) { $this->load( 'notices', new Notices_Nuker() ); $this->load( 'dashboard', new Dashboard() ); if ( current_user_can( 'qa_view_reports' ) || current_user_can( 'qa_manage_settings' ) ) { $this->load( 'settings', new Settings_Page() ); $this->load( 'pro_notice', new Pro_Notice() ); } } // Cron: daily maintenance (status check, clean up log). add_action( Reports::CRON_DAILY, array( Reports::class, 'cron_daily' ) ); // Admin bar: help node and Ghost Mode notice. add_action( 'admin_bar_menu', array( $this, 'admin_bar_help_node' ), 998 ); add_filter( 'show_admin_bar', array( $this, 'maybe_hide_admin_bar' ) ); /** * Plugin is loaded - attach your own hooks here. * * @since 0.1.0 * * @param Plugin $plugin Instance. */ do_action( 'quietadmin_loaded', $this ); } /** * Registers a module. * * @since 0.1.0 * * @param string $key Module key. * @param object $module Module instance with register(). * @return void */ protected function load( $key, $module ) { $this->modules[ $key ] = $module; if ( method_exists( $module, 'register' ) ) { $module->register(); } } /** * Returns a module (e.g. for tests or extensions). * * @since 0.1.0 * * @param string $key Module key. * @return object|null */ public function module( $key ) { return isset( $this->modules[ $key ] ) ? $this->modules[ $key ] : null; } /** * Help node in the admin bar (clients and Ghost Mode). * * @since 0.1.0 * * @param \WP_Admin_Bar $wp_admin_bar Admin bar. * @return void */ public function admin_bar_help_node( $wp_admin_bar ) { if ( ! ClientMode::is_active() || ! Options::get( 'show_help_button' ) ) { return; } $target = Support::target(); // The modal exists only in the admin area - fall back to mailto on the frontend. if ( ! is_admin() && 'modal' === $target['type'] ) { $email = (string) Options::get( 'support_email' ); if ( '' === $email ) { return; } $target = array( 'type' => 'mailto', 'url' => 'mailto:' . $email . '?subject=' . rawurlencode( (string) Options::get( 'support_email_subject' ) ), 'label' => $target['label'], ); } if ( ! current_user_can( 'qa_request_support' ) ) { return; } if ( 'none' === $target['type'] ) { return; } $wp_admin_bar->add_node( array( 'id' => 'quietadmin-help', 'title' => ' ' . esc_html( $target['label'] ), 'href' => esc_url( $target['url'] ), 'meta' => array( 'class' => 'qa-help-node', 'target' => 'modal' === $target['type'] ? '' : '_blank', ), ) ); } /** * Hides the admin bar on the frontend for clients (option). * * @since 0.1.0 * * @param bool $show Previous value. * @return bool */ public function maybe_hide_admin_bar( $show ) { if ( ! ClientMode::is_active() || ! Options::get( 'hide_admin_bar' ) ) { return $show; } // Agencies need the admin bar for Ghost Mode / Magic Login. if ( ClientMode::is_ghost_mode() || ClientMode::is_impersonating() ) { return $show; } return false; } }