Wildcat Media
Well-known member
I'm trying to build an add-on that will allow me to set permissions on who can create article and question threads. My knowledge of this stuff is at a "...For Dummies" level, so I'm flying solo here trying to figure out how to get this to work.
So far I have "borrowed" code from @Idhae here which is saved in /src/addons/WMG/ArticleCreatePermission/XF/Entity/Forum.php :
I created this in Permission Definitions:
And I added this to Class Extensions (execution order 10):
I have a test forum with all four thread types enabled. With a registered user (non-staff) account, I can create all four thread types.
Result: With the add-on enabled, and setting permission to Inherit, No or Never, it is removing the Poll thread type, but leaving the Article thread type. With permission set to Yes, the Poll thread type reappears.
I created an almost identical add-on that will add a permission for the Question thread type. Same result--it removes the Poll thread type.
Am I missing a step, or is the logic in the PHP code doing something unintended?
So far I have "borrowed" code from @Idhae here which is saved in /src/addons/WMG/ArticleCreatePermission/XF/Entity/Forum.php :
PHP:
<?php
namespace WMG\ArticleCreatePermission\XF\Entity;
class Forum extends XFCP_Forum
{
public function getCreatableThreadTypes(){
$parent = parent::getCreatableThreadTypes();
if(\XF::visitor()->hasNodePermission($this->node_id, 'wmg_articleCreate')){
return $parent;
}
else {
if($key = array_search('article' ,$parent) !== false){
unset($parent[$key]);
}
return $parent;
}
}
}
I created this in Permission Definitions:
And I added this to Class Extensions (execution order 10):
I have a test forum with all four thread types enabled. With a registered user (non-staff) account, I can create all four thread types.
Result: With the add-on enabled, and setting permission to Inherit, No or Never, it is removing the Poll thread type, but leaving the Article thread type. With permission set to Yes, the Poll thread type reappears.
I created an almost identical add-on that will add a permission for the Question thread type. Same result--it removes the Poll thread type.
Am I missing a step, or is the logic in the PHP code doing something unintended?