How can I define a selection rule to use for Panels variants in code? I have some custom PHP code that I would like to use as a selection rule for about 30 different variants.  In the future, I may need to update this code, so rather than add the code 30 times, once for each variant, I would rather add it in code via a custom module so that I can more easily maintain it.

Is there a hook, etc. for adding Panels selection rules?
You can add Panels selection rules.

However, in your case, have you tried just calling a module function instead in your PHP code for the selection rule?

e.g, call a function defined in a module:

return my_module_selection_rule('foo');


instead of all the raw code there.

That way, it can be updated once in the module codebase.

I use that technique a lot for views php contextual filter handling code.

If so inclined, see 


panels/plugins/task_handlers/panel_context.inc 


for the default selection rules plugin definition. and


ctools_context_handler_edit_criteria


for the default form builder function for the selection rules.