Thanks for the heads up on this thread.
Regarding code snippets like the one you see below, throughout many areas of s2Member’s source code.
eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before", get_defined_vars ());
unset ($__refs, $__v); /* Unset defined __refs, __v. */
The first line of code where eval
is used, is simply to compress all of this repetitious code into a single line that can pass IDE auto-formatting. The purpose of this repetitious code is as follows.
The first line collects all defined variables in the current scope, and creates PHP “references” to each of those variables, forcing the future call to get_defined_vars()
in the next line, to include $__refs
, which is a temporary array now containing PHP references to the current variables in scope.
In this way, it makes it possible for site owners/developers to hook into s2Member’s routines, and actually change the value of certain variables inline, by reference. This increases flexibility for developers that wish to customize s2Member-driven routines in more advanced ways.