From 0c0bba5d159ea791f01a44bccc49ec16c75c8e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sun, 15 Dec 2024 17:01:15 +0100 Subject: [PATCH] fix custom summary admin UI, faulty merge with main --- .../js/event-bridge-for-activitypub-admin.js | 20 ++++++++++++ event-bridge-for-activitypub.php | 2 +- includes/class-setup.php | 31 +++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/assets/js/event-bridge-for-activitypub-admin.js b/assets/js/event-bridge-for-activitypub-admin.js index d2eb9ea..3715707 100644 --- a/assets/js/event-bridge-for-activitypub-admin.js +++ b/assets/js/event-bridge-for-activitypub-admin.js @@ -11,4 +11,24 @@ jQuery( function( $ ) { $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false ); } } ); + + // Function to toggle visibility of custom details based on selected radio button. + function toggleCustomDetailsForSummary() { + if ($("#event_bridge_for_activitypub_summary_type_custom").is(':checked')) { + $("#event_bridge_for_activitypub_summary_type_custom-details").show(); + } else { + $("#event_bridge_for_activitypub_summary_type_custom-details").hide(); + } + } + + // Run the toggle function on page load. + $(document).ready(function() { + toggleCustomDetailsForSummary(); // Set the correct state on load. + + // Listen for changes on the radio buttons + $("input[name=event_bridge_for_activitypub_summary_type]").change(function() { + toggleCustomDetailsForSummary(); // Update visibility on change. + }); + }); + } ); diff --git a/event-bridge-for-activitypub.php b/event-bridge-for-activitypub.php index e3f4219..ac44073 100644 --- a/event-bridge-for-activitypub.php +++ b/event-bridge-for-activitypub.php @@ -3,7 +3,7 @@ * Plugin Name: Event Bridge for ActivityPub * Description: Integrating popular event plugins with the ActivityPub plugin. * Plugin URI: https://event-federation.eu/ - * Version: 0.3.2.6 + * Version: 0.3.2.7 * Author: André Menrath * Author URI: https://graz.social/@linos * Text Domain: event-bridge-for-activitypub diff --git a/includes/class-setup.php b/includes/class-setup.php index 84b69e9..b2cd172 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -414,22 +414,41 @@ class Setup { } /** - * Get the transmogrifier. + * Get the transmogrifier class. + * + * Retrieves the appropriate transmogrifier class based on the active event plugin. + * + * @return string|null The transmogrifier class name or null if not available. */ public static function get_transmogrifier() { + // Retrieve singleton instance. $setup = self::get_instance(); - $event_sources_active = get_option( 'event_bridge_for_activitypub_event_sources_active', false ); + // Get plugin options. + $event_sources_active = (bool) get_option( 'event_bridge_for_activitypub_event_sources_active', false ); $event_plugin = get_option( 'event_bridge_for_activitypub_plugin_used_for_event_source_feature', '' ); - if ( ! $event_sources_active || ! $event_plugin ) { - return; + // Bail out if event sources are not active or no plugin is specified. + if ( ! $event_sources_active || empty( $event_plugin ) ) { + return null; } + + // Get the list of active event plugins. $active_event_plugins = $setup->get_active_event_plugins(); + + // Loop through active plugins to find a match. foreach ( $active_event_plugins as $active_event_plugin ) { - if ( strrpos( $active_event_plugin::class, $event_plugin ) ) { - return $active_event_plugin::get_transmogrifier_class(); + // Retrieve the class name of the active plugin. + $active_plugin_class = get_class( $active_event_plugin ); + + // Check if the active plugin class name contains the specified event plugin name. + if ( false !== strpos( $active_plugin_class, $event_plugin ) ) { + // Return the transmogrifier class provided by the plugin. + return $active_event_plugin->get_transmogrifier_class(); } } + + // Return null if no matching plugin is found. + return null; } }