In the ’v1.31 bugfix’ topic I started a conversation about multiple instances of WLPE, but since it’s not a bugfix I open a new topic for it.
There it turned out that my first attempt of making it was "a bit" overworked by altering the placeholders.
It also turned out that there are different needs when using multiple instances.
My idea was to list photos on the sidebar that may not disappear during the edit of a profile in the content area.
The other concept - thanks to BobRay - is to have multiple userlists with profile links, so opening a profile from either list must disable the other list.
I tried to compile these all together so here are my recommendations:
(I worked with v1.31 snippet, but may work with former versions.)
First move the service request to the very beginning of the snippet so it doesn’t do anything if it’s not necessary. In the original code find
$service = $_REQUEST['service'];
if (empty($service) || $service == '')
{
$service = $_REQUEST['serviceButtonValue'];
}
cut&paste it to the beginning, after the */ section, but before this line: [tt]$type = isset($type) ? $type : ’simple’;[/tt]
After that continue with this (still before the [tt]$type =[/tt] ... code):
$instance = isset($instance) ? $instance:'';
$postinstance = $_REQUEST['instance'] ? $_REQUEST['instance'] : '';
$shy = isset($shy) ? $shy : 0; // or 1 if you prefer 'shy' as default ;)
if ($service && $instance != $postinstance)
{
if ($shy) return; // skip this instance: 'shy' mode
$service=''; // run this instance without mess
}
if (!function_exists('AddInstance'))
{
function AddInstance($toTpl,$instance)
{
$toTpl = str_replace('</form>', '<input type="hidden" name="instance" value="'.$instance.'" /></form>', $toTpl);
$toTpl = str_replace('service=', 'instance='.$instance.'&service=', $toTpl);
return $toTpl;
}
}
With this done we have two new parameters in the snippet call:
&instance: we can give a discrete name to every appearance of the user datas on the page. It’s not necessary, however. You can combine named instances with a nameless one. So if your site already contains working WLPE without a name, don’t touch it, just add a new instance with this parameter - to say, to the sidebar.
­: (1|0) we can decide if the given instance will hide when another one shows a profile or whatever form. If it’s not set, means not shy - good for a sidebar instance.
Additionally we have a function that puts the instance’s name in the forms/templates so we can use our original Tpl’s. It’s also possible to use the same Tpl’s in different instances.
For this to take place I call this function for every Tpl’s loaded. Find this part and replace:
if ($regType == 'verify'){$wlpeRegisterTpl = AddInstance($wlpeRegisterVerifyTpl, $instance);}else{$wlpeRegisterTpl = AddInstance($wlpeRegisterInstantTpl, $instance);}
$displayLoginFormTpl = AddInstance(isset($loginFormTpl) ? $wlpe->Template($loginFormTpl) : $wlpeDefaultFormTpl, $instance);
$displaySuccessTpl = AddInstance(isset($successTpl) ? $wlpe->Template($successTpl) : $wlpeDefaultSuccessTpl, $instance);
$displayRegisterTpl = AddInstance(isset($registerTpl) ? $wlpe->Template($registerTpl) : $wlpeRegisterTpl, $instance);
$displayRegSuccessTpl = AddInstance(isset($registerSuccessTpl) ? $wlpe->Template($registerSuccessTpl) : $wlpeDefaultFormTpl, $instance);
$displayProfileTpl = AddInstance(isset($profileTpl) ? $wlpe->Template($profileTpl) : $wlpeProfileTpl, $instance);
$displayViewProfileTpl = AddInstance(isset($viewProfileTpl) ? $wlpe->Template($viewProfileTpl) : $wlpeViewProfileTpl, $instance);
$displayUsersOuterTpl = AddInstance(isset($usersOuterTpl) ? $wlpe->Template($usersOuterTpl) : $wlpeUsersOuterTpl, $instance);
$displayUsersTpl = AddInstance(isset($usersTpl) ? $wlpe->Template($usersTpl) : $wlpeUsersTpl, $instance);
$displayManageOuterTpl = AddInstance(isset($manageOuterTpl) ? $wlpe->Template($manageOuterTpl) : $wlpeUsersOuterTpl, $instance);
$displayManageTpl = AddInstance(isset($manageTpl) ? $wlpe->Template($manageTpl) : $wlpeManageTpl, $instance);
$displayManageProfileTpl = AddInstance(isset($manageProfileTpl) ? $wlpe->Template($manageProfileTpl) : $wlpeManageProfileTpl, $instance);
$displayManageDeleteTpl = AddInstance(isset($manageDeleteTpl) ? $wlpe->Template($manageDeleteTpl) : $wlpeManageDeleteTpl, $instance);
$displayProfileDeleteTpl = AddInstance(isset($profileDeleteTpl) ? $wlpe->Template($profileDeleteTpl) : $wlpeProfileDeleteTpl, $instance);
$displayActivateTpl = AddInstance(isset($activateTpl) ? $wlpe->Template($activateTpl) : $wlpeActivateTpl, $instance);
$displayResetTpl = AddInstance(isset($resetTpl) ? $wlpe->Template($resetTpl) : $wlpeResetTpl, $instance);
$notifyTpl = AddInstance(isset($notifyTpl) ? $wlpe->Template($notifyTpl) : $wlpeNotifyTpl, $instance);
$notifySubject = isset($notifySubject) ? $notifySubject : 'New Web User for '.$modx->config['site_name'].'.';
$messageTpl = isset($messageTpl) ? $wlpe->Template($messageTpl) : $wlpeMessageTpl;
$tosChunk = isset($tosChunk) ? $wlpe->Template($tosChunk) : $wlpeTos;
$modx->setPlaceholder('tos', $tosChunk);
$loadJquery = isset($loadJquery) ? $loadJquery : false;
$customJs = isset($customJs) ? $customJs : '';
I tested with three instances. Two in the content area was shy but only one of them had an instance name. The third one was not shy and sit in the sidebar.
Please test it! I attach the altered snippet code.