2022-01-27 * @co-author Eric Schwarzer 2022-02-22 ;) TWO */ require_once(__DIR__.'/ui.php'); $options = AddonOptionQuery::create() //->filterByState('active') ->filterByOption($slug) ->orderById() ->find(); // find() returns an objectcollection, it will always be true if we check it directly. need to check count() instead. if (!$options->count()) { // not found in db \Util::Redirect('/', 307); //307 ensures search engines will try again at some point. } $addons = [ 'active' => [], 'dirty' => [], 'plugin' => [], 'theme' => [], ]; foreach ($options as $option) { // $addon = AddonQuery::create()->findOneById($option->getAddonId()); // nit: propel knows the relationship between options and their respective addon. // do it like this: $addon = $option->getAddon(); // need to key by id so we dont have duplicate addons. this also means we cant do [0] to get first element anymore - use reset(). $addons[$option->getState()][$addon->getId()] = $addon; //I think this should work, or we have to clone them? $addons[$addon->getType()][$addon->getId()] = $addon; //places the addon into two different keys so we can quickly iterate them } $activeCount = count($addons['active']); if (1 === $activeCount) { $addon = reset($addons['active']); $template->title = "Only one {$addon->getType()} saves \"{$slug}\" in wp-options: {$addon->getName()}"; } elseif ($activeCount) { $template->title = "{$activeCount} plugins/themes save an option named \"{$slug}\" in wp-options"; } else { // @todo what about the case where $activeCount = 0? } $template->assign([ // nit: why not name $addons keys activeOptions, orphanOptions etc. and just pass $addons to $template->assign? 'activeOptions' => $addons['active'], 'orphanOptions' => $addons['dirty'], 'pluginOptions' => $addons['plugin'], 'themeOptions' => $addons['theme'], ]); $template->display('reference/option.tpl');