Site logo

[Support request] Disable comments for media attachments

Home Forums Support [Support request] Disable comments for media attachments

Home Forums Support Disable comments for media attachments

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2110362
    Matthew

    I added the below to Snippets plug-in to disable comments for all media attachments on my site.
    Without it, I would be required to go to each media item at Discussion > Allow comments and uncheck the checkbox.
    But it isn’t working.

    FUNCTION FILTER_MEDIA_COMMENT_STATUS( $OPEN, $POST_ID ) {
    
        $POST = GET_POST( $POST_ID );
    
        IF( $POST->POST_TYPE == 'ATTACHMENT' ) {
    
            RETURN FALSE;
    
        }
    
        RETURN $OPEN;
    
    }
    
    ADD_FILTER( 'COMMENTS_OPEN', 'FILTER_MEDIA_COMMENT_STATUS', 10 , 2 );

    Any pointers?

    #2110405
    Fernando
    Customer Support

    Hi Matthew,

    Can you try replacing you PHP snippet with this one?:

    function filter_media_comment_status( $open, $post_id ) {
        $post = get_post( $post_id );
        if( $post->post_type == 'attachment' ) {
            return false;
        }
        return $open;
    }
    add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 );

    The issue may be occurring because your current code is in uppercase. Kindly let us know if this resolves the issue. 🙂

    #2110421
    Matthew

    Hi Fernando,

    Great, this does now cause the removal the comments on the media item front webpage.

    However the checkbox in the media edit screen i.e. ‘Allow comments’ remains checked. Shouldn’t it be unchecked?

    #2110489
    Fernando
    Customer Support

    The PHP snippet you added doesn’t alter the checkbox’s attributes, and I can’t see a filter to control this.

    However, more importantly, the PHP you added effectively overrides the checkbox ‘Allow comments’. This means that checked or unchecked, because of the php snippet you added, the comments for attachment will be closed.

    Hope this clarifies your inquiry! Feel free to reach out anytime if any further assistance is needed. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.