• Resolved loopforever

    (@loopforever)


    Hi everyone,
    I want comments to always be turned off on media uploads (for example, an image with png extension). For new media, for example a photo, the comment should always be turned off. However, I couldn’t find a solution to this.
    Basically the following SQL code will work when any media is uploaded but of course this is not a sensible solution:

    UPDATEwp_postsSETcomment_status= ‘closed’ WHEREpost_type= ‘attachment’;

    I wrote a code like below but this code does not fulfill its function. I also reviewed many sources. None of these work: 1, 2

    So it’s not working. I would be glad if you guide me.
    Thank you.

    add_filter('comments_open', 'turn_off_comments_media', 10 , 2 );
    function turn_off_comments_media( $open, $post_id ) {
        $post_variable = get_post( $post_id );
        if( $post_variable->post_type == 'attachment' ){ 
            return false;
        }
        
        return $open;
    }
    • This topic was modified 2 years, 5 months ago by loopforever. Reason: added code
    • This topic was modified 2 years, 5 months ago by loopforever.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I like using the plugin “disable comments” for this.

    Thread Starter loopforever

    (@loopforever)

    Thank you. The same cannot be said for me.
    Also, I think the purpose of the
    “Developing with WordPress” forum is to provide solutions rather than suggest plugins.

    • This reply was modified 2 years, 5 months ago by loopforever.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    The plugin *is* a solution. If you want a “tutorial” on how to disable comments on media pages, I suggest looking through its code.

    Thread Starter loopforever

    (@loopforever)

    The plugin is not a solution for this problem; alternative. I’m talking about resources, Mr. Steven, they are limited.
    Problem solved. Good luck.

    add_filter('comments_open', 'turn_off_comments_media', 10 , 2 );
    function turn_off_comments_media( $open, $post_id = null ) {
        $post_variable = get_post( $post_id );
        if( $post_variable->post_type == 'attachment' ){ 
            return false;
        }
        
        return $open;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I turn off comments on media uploads?’ is closed to new replies.