DEV: Add `add_controller_callback` server side plugin api.

DEV: Add add_controller_callback server side plugin api.

diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index 5f218ab..d8bc0b4 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -235,6 +235,16 @@ class Plugin::Instance
+  def add_controller_callback(klass_name, callback, &block)
+    reloadable_patch do |plugin|
+      klass = klass_name.to_s.classify.constantize rescue klass_name.to_s.constantize
+      klass.public_send(callback) do |controller, action|
+, action) if plugin.enabled?
+      end
+    end
+  end
   # Add a post_custom_fields_whitelister block to the TopicView, respecting if the plugin is enabled
   def topic_view_post_custom_fields_whitelister(&block)
     reloadable_patch do |plugin|

GitHub sha: 8233610d

Question: Why not use add_class_method for this?

This is not trying to add a method to the class but rather add a callback on the class. This is similar to add_model_callback but it only takes a block because the controller and action params are not passed if the callback calls a method.