event_plugin = $event_plugin; if ( $this->event_post_type_is_not_activitypub_enabled() ) { add_action( 'admin_notices', array( $this, 'admin_notice_activitypub_not_enabled_for_post_type' ), 10, 1 ); } } /** * Check if ActivityPub is enabled for the custom post type of the event plugin. * * @return bool */ private function event_post_type_is_not_activitypub_enabled() { return ! in_array( $this->event_plugin['post_type'], get_option( 'activitypub_support_post_types', array() ), true ); } /** * Display the admin notices for the plugins. */ public function admin_notice_activitypub_not_enabled_for_post_type() { // Get the current page. $screen = get_current_screen(); // Check if we are on a edit page for the event, or on the settings page of the event plugin. $is_event_plugins_edit_page = 'edit' === $screen->base && $this->event_plugin['post_type'] === $screen->post_type; $is_event_plugins_settings_page = $this->event_plugin['settings_page_id'] === $screen->id; if ( $is_event_plugins_edit_page || $is_event_plugins_settings_page ) { $this->do_admin_notice_post_type_not_activitypub_enabled( $this->event_plugin['plugin_file'] ); } } /** * Print admin notice that the current post type is not enabled in the ActivityPub plugin. * * @param string $event_plugin_file The event plugin file path. */ private function do_admin_notice_post_type_not_activitypub_enabled( $event_plugin_file ) { $event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $event_plugin_file ); $activitypub_plugin_data = get_plugin_data( ACTIVITYPUB_PLUGIN_FILE ); $notice = sprintf( /* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */ _x( 'You have installed the %1$s plugin, but the event post type of the plugin %2$s is not enabled in the %1$s settings.', 'admin notice', 'activitypub-event-extensions' ), esc_html( $activitypub_plugin_data['Name'] ), esc_html( $event_plugin_data['Name'] ), admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); $allowed_html = array( 'a' => array( 'href' => true, 'title' => true, ), 'b' => array(), 'i' => array(), ); echo '

' . \wp_kses( $notice, $allowed_html ) . '

'; } }