Settings', ) ); } /** * Receive the event categories (terms) used by the event plugin. * * @param Event_Plugin $event_plugin Contains info about a certain event plugin. * * @return array An array of Terms. */ private static function get_event_terms( $event_plugin ): array { $taxonomy = $event_plugin::get_event_category_taxonomy(); if ( $taxonomy ) { $event_terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => true, ) ); return ! is_wp_error( $event_terms ) ? $event_terms : array(); } else { return array(); } } /** * Preparing the data and loading the template for the settings page. * * @return void */ public static function settings_page(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_GET['tab'] ) ) { $tab = 'welcome'; } else { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tab = sanitize_key( $_GET['tab'] ); } // Fallback to always re-scan active event plugins, when user visits admin area of this plugin. $plugin_setup = Setup::get_instance(); $plugin_setup->redetect_active_event_plugins(); $event_plugins = $plugin_setup->get_active_event_plugins(); switch ( $tab ) { case 'settings': $event_terms = array(); foreach ( $event_plugins as $event_plugin_integration ) { $event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin_integration ) ); } $supports_event_sources = array(); foreach ( $event_plugins as $event_plugin_integration ) { if ( $event_plugin_integration instanceof Feature_Event_Sources && $event_plugin_integration instanceof Event_Plugin_Integration ) { $supports_event_sources[ $event_plugin_integration::class ] = $event_plugin_integration::get_plugin_name(); } } $args = array( 'slug' => self::SETTINGS_SLUG, 'event_terms' => $event_terms, 'supports_event_sources' => $supports_event_sources, ); \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', true, $args ); break; case 'event-sources': wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/event-sources.php', true ); break; case 'welcome': default: wp_enqueue_script( 'plugin-install' ); add_thickbox(); wp_enqueue_script( 'updates' ); \load_template( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php', true ); break; } } }