Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've hit the issue described in '11:

"Enable comments for post with comments meta box removed" and I'd like to ask for your help to adapt the mentioned there code to the current wordpress version.

I have a custom post type that must have comments enabled and contributors must not be able to disable comments.

I've enabled comments in Settings->Discussion and removed the commentstatusdiv meta box with remove_meta_box(). After that I've figured out that comments is unset when the meta box is disabled.

I am looking for the way to enforce the comments now.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Filter the 'comments_open' check. It happens inside of the function with the same name, and that function is called in a theme usually like this:

comments_open() and comment_form(
    array (
        'comment_notes_after' => ''
    )
);

This is how the filter works:

add_filter( 'comments_open', 'wpse_98775_comment_check', 10, 2 ); 

function wpse_98775_comment_check( $open, $post_id )
{
    if ( $open )
        return $open;

    if ( 'my_post_type' === get_post_type( $post_id ) )
        return TRUE;

    return $open;
}

You could create a custom plugin with this snippet.

share|improve this answer
    
toscho, if not difficult, could you give a hint. 1. should this work with disabled commentstatusdiv meta box? 2. at what moment comments_open() fires? 3. code doesn't work for me. (I did change my_post_type to the desirable value) –  Anton May 9 '13 at 18:03
    
@anton See my update. –  toscho May 9 '13 at 18:05
    
I have no problems with installation/setup, I've tried your snippet in functions.php, would it really make difference if I put it as a plugin? –  Anton May 9 '13 at 20:23
    
The comments_open() check happens in your theme. I have added an example. Make sure you are using a properly written theme. –  toscho May 9 '13 at 22:48
1  
thanks a lot for a theme hint. It was indeed an issue in the theme. Fixed now. And your snippet works flawlessly. THANKS. –  Anton May 13 '13 at 14:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.