settings = $settings; } /** * Register integration. * * @param object $integration Integration following the contract above. * @return void */ public function register_integration( $integration ) { $this->integrations[ $integration->slug() ] = $integration; } /** * Boots every integration that is active and enabled in settings. * * @return void */ public function boot() { foreach ( $this->active_integrations() as $integration ) { $integration->boot(); } } /** * Active integrations. * * @return object[] Active, enabled integrations keyed by slug. */ public function active_integrations() { $active = array(); foreach ( $this->integrations as $slug => $integration ) { if ( $this->settings->get( $slug . '_support' ) && $integration->is_active() ) { $active[ $slug ] = $integration; } } return $active; } /** * Integration status for the admin app. * * @return array[] */ public function status() { $status = array(); foreach ( $this->integrations as $slug => $integration ) { $status[] = array( 'slug' => $slug, 'label' => $integration->label(), 'active' => (bool) $integration->is_active(), 'enabled' => (bool) $this->settings->get( $slug . '_support' ), ); } return $status; } /** * True on requests that load a visual editor or preview, where swapping * pages with ajax would break the editor. * * @return bool */ public function is_editing_request() { foreach ( $this->editor_query_args as $arg ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only presence check. if ( isset( $_GET[ $arg ] ) ) { return true; } } if ( is_customize_preview() ) { return true; } foreach ( $this->integrations as $integration ) { if ( $integration->is_active() && $integration->is_editing_request() ) { return true; } } return false; } }