Roswell Studios

139 Fulton Street, Ste 132
New York, NY 10038

Forum Review: Sabai

— May 22, 2016

WordPress Stack Exchange style forum.

I’d never heard of it, and the cheap looking website doesn’t seem to have been updated since 2013, and English is clearly not his native language, but it seems quite extensible, the product itself was updated recently, and the author is quite active in the support forum. I was worried that because it was not free, the source would require ioncube or something, but it is open and quite readable. A lot of stuff is in theme files and easily edited. It’s only $25 so it would be worth experimenting with if the weirdness with BBPress is too much. (Like what did happen to the moderation options? The hook is gone, too, so even the plugin designed to put that back doesn’t work any more.)

My only issue is while the code is readable, it is not exactly comprehensible, without a map. The issue: we wanted the shorcode [sabai-discuss-answers] to be sorted by date, but the actual answers pages sorted by votes. The Answers sort order is configurable, but only one order for both pages. I thought it would be easy to follow the other shortcode settings and just drop it in. I was mistaken. It is a bit of a maze in there. The shortcode settings are used in the view, but nowhere else. The attribute hash is used a couple places, but only in the shortcode code, not anywhere in the framework that manages the entities. Any object has great-grandparents, and a function might be defined and overridden in any of them, so just looking at a stack trace and trying to read it was useless. It is particularly irritating that the shortcode has a user configurable, ajax driven sort option, so it responds to parameter input and to manually putting to sort=newest in the url of the page the shortcode lives in, but will not respond to a shortcode attribute. In retrospect it would have been easier to ignore the shortcode and manually drop the ajax data directly in to the Visual Composer div. The ajax thing is not documented, while the shortcodes are, so it was the obvious place to start. It might also be possible to get Visual Composer’s custom query to pull up Answers on its own, which would have meant not editing a theme file to match VC’s styles.

By that point, it had been an hour wasted and I was emotionally invested in it, so I stepped through it with a debugger. Edit sabai/lib/Sabai/Addon/Entity/Controller/ListEntities.php and find the

$current_sort = $context->getRequest()->asStr('sort', $default_sort, $sort_keys);

and append

if (isset($context->getAttributes()['sort'])) {
$current_sort = $context->getAttributes()['sort'];
}

Then you can put [sabai-discuss-answers sort=”newest”]. Ideally it could have a single hierarchical settings including the shortcode attributes/url parameters > configurable defaults > hardcoded defaults, or possibly just put the shortcode attribute the same place in puts url parameters, given that the whole thing runs on a web response framework. Which would make the ajax thing all that much more obvious, if any of that had been documented.

I also wanted to be able to restrict the count of entities returned to 5, which also has a configurable option we didn’t want to apply to the page view, but does not have an obvious url parameter, but that’s yet another file I can’t be bothered to find. It was easy enough to edit the theme to array_slice it down. A waste of 15 object loads, but when I noticed

if (!$query = $this->_createQuery($context, $bundle)) {

which is

protected function _createQuery(Sabai_Context $context, Sabai_Addon_Entity_Model_Bundle $bundle = null)
{
}

Defined in another file? There’s a surprise. I gave up. You could load an extra 15 entities for centuries before wasting the amount of power I’d waste finding where the limit gets set.

Back to all