Enable/Disable Comments In Frontend

Question

I’m using the WPUF plugin so every user can post articles from the front-end with a form provided from the plugin.

I would like to make a feature for the optional choice to let the post author disable or enable comments in frontend post creation and editing forms on a per post basis (like is standard functionality in the backend post edit screen).

What is the best way to achieve this?

I noticed that there is ACF support so my initial idea was to make a check box in the WPUF form and enter the same meta like in the ACF check box which I made.

After that in single.php page to run a check if the check mark is checked like this.

if( get_field('post_comments_control') ) {
    echo '<div class="alert alert-warning" role="alert">Comments are closed from the Author!</div>';
} else {
    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || get_comments_number() ) :
        comments_template();
    endif;
}

This method close the comments but I can’t open them after that. It’s uncheck the "Allow comments" in the admin panel single post edit page.

0
Yordan Kostadinov 2 months 0 Answers 6 views 0

Leave an answer