How can I set ap_user_can_answer to false conditionally?

3.73K viewsGeneral

I want to add some conditions in functions.php to limit some functionality. One thing I want to do is hide answer form if a condition is met. I found function ap_user_can_answer() but having a hard time making it work in functions.php. Any help would be appreciated.

Tell us what you are trying to achieve.

Hey Rahul, we use membership plugin. There are several types of membership. Membership plugin has a function ms_has_membership(X) and it returns true if user has membership and false if he doesn’t. What I want to do is disable answer box if user does not have proper membership level. I was successful at disabling comments and ask page. But I can’t figure out answer box.

Disable AnswerBox? you really mean disable theme?

No, sorry for not clarifying. WYSIWYG editor that is used to submit answer. I want to disable it, that’s why I was trying to use ap_user_can_answer() function.


Added a filter in ap_user_can_answer, use it to override the function.

Thanks Rahul. I updated the file from Github, but I can’t get it to work. Am I missing something?

function membershipAnsBox() {
return false;
}else{ return true; }
add_filter( ‘ap_user_can_answer’, ‘membershipAnsBox’ );

The !ms_has_membership(459) condition works, if I simply echo something it does show. But I can’t get false to work.Thanks.

Hey Rahul, just wanted to follow up on this.