I'm having a little problem with a Wordpress function, and although in principle everything is correct, the action is not executed.
What I need
For custom entry types, disable the add comments feature. If possible, I would like to have to edit the minimum number of templates, since this could be done by modifying the course template and adding the condition there, but I would like to make the minimum possible editions on the template, and be able to do it with the API itself of WP to avoid possible future incompatibilities.
Environment
- Wordpress 4.8.3
- StoreFront template
- LearnDash LMS
- Local server with Windows 10 and WAMP server.
What I have
$lvCursePostTypes = array('sfwd-courses','sfwd-lessons','sfwd-topic','sfwd-quiz', 'sfwd-certificates');
function remove_courses_post_comment(){
global $lvCursePostTypes;
foreach($lvCursePostTypes as $postType){
remove_post_type_support($postType, 'comments');
}
}
add_action('init', 'remove_courses_post_comment');
I've also tried (in case it was an array / loop problem)
function remove_courses_post_comment(){
remove_post_type_support('sfwd-courses', 'comments');
}
add_action('init', 'remove_courses_post_comment');
References
Conclusions
Is it possible that after disabling with remove_post_type_support, the template will be forced again ?, I have not found any code about it.
Through post_type_supports ('sfwd-courses', 'comments') I verify that in theory that Post Type does not have permission for comments, it still shows the form to leave a comment.