Home Forums Plugin Support WP User Frontend Pro Enable/disable comments in frontend

This topic is: resolved

This topic contains 11 replies, has 4 voices, and was last updated by  Chris Swede 4 years, 2 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #23999

    Chris Swede
    Member
    Post count: 56

    I would like to make a feature request for the optional choice to let post author disable or enable comments in frontend post creation and editing forms on a per post basis (like is standard in the backend post edit screen), or is this already possible in WPUF?

    Thanks for the great plugin WPUF you have provided us with. Excellent work and great new features!

    #24420

    Sk
    Moderator
    Post count: 371

    Hello Chris,
    WPUF has this feature already.

    Thank you.

    #24431

    Sekander Badsha
    Member
    Post count: 2067

    Hello Chris,
    You can easily pass a function in user frontend. Here we have previously demonstrated how to turn off or on a comment http://wedevs.com/support/topic/comments-are-turned-off-after-edit/ and here we have discussed about adding a feature in User Frontend http://docs.wedevs.com/password-protect-post/.

    So combining the two thread above, I've come up with the solution for you.
    1. Make a dropdown field and name it “Comment Status”. So the meta key would be ‘comment_status'.
    2. Enter two values Open and Closed.
    3. Open your themes functions.php and paste the code below:
    [php]
    /**
    * Set comment status on a post
    *
    * @param array $args
    * @return array
    */
    function wpufe_comment_status( $args ) {
    if ( isset( $_POST[‘comment_status'] ) ) {
    $args[‘comment_status'] = strtolower( $_POST[‘comment_status'][0] );
    }

    return $args;
    }

    add_filter( ‘wpuf_add_post_args', ‘wpufe_comment_status' );
    add_filter( ‘wpuf_update_post_args', ‘wpufe_comment_status' );
    [/php]

    Save the file and make a post. See what happens and let me know.

    #24452

    Chris Swede
    Member
    Post count: 56

    Hi Sekander,

    Thanks a lot for this. It is really useful. It works with one exception. If you turn off the comments on the wpuf frontend edit post page and save, then you can't turn them back on again. In the wpuf frontend create new post it works.

    The ideal solution would be to have a checkbox just like WordPress does in the backend, where you can check/uncheck to enable comments since a dropdown is not meant when the selection is between only two alternatives. When the wpuf wpuf_add_post_args are filtered an empty checkbox (comments disabled) won't save as a meta key.

    #26942

    Chris Swede
    Member
    Post count: 56

    Hi again,

    I mark this as unresolved since it is not working correctly. It would be a very useful and appreciated feature to include this option in the WPUF form builder. Preferably displayed as a single checkbox in the front-end add post and edit post forms, like its done in the WP-admin post edit area. At the moment it works but in a clumsy way due to the dropdown in the add new post form, whereas in the edit post form it does not work at all.

    #27122

    Sekander Badsha
    Member
    Post count: 2067

    Are you saying that the comment status is not working when a post is edited?

    #28113

    Chris Swede
    Member
    Post count: 56

    Hi Sekander,
    sorry for my late reply. Yes, that's correct, changing the comment status when editing a post doesn't get updated when edits are saved. If the comment status can be selected with a single checkbox “enable comments” like in WP-admin back-end post edit screen it would be great!

    #28429

    Sekander Badsha
    Member
    Post count: 2067

    Hello Chris,

    I have tested this but failed to reproduce the issue.

    Please check if you have the latest version of the plugin installed. If the issue is happening in 2.2.6 then check for your theme or plugin conflicts. You can disable all your plugins except User Frontend and switch to a default theme of WordPress like- Twenty Twelve and let me know the results.

    Thank you ๐Ÿ™‚

    #28694

    Chris Swede
    Member
    Post count: 56

    Hi Sekander,

    Thank you for your patience with this. I have updated to 2.2.6 and the same problem persists. If comment status is set on a new post I can't change it in post edit and comments will never display. In fact, what is saved in the post's comment_status in the database is neither “open” nor “closed” but instead “o” or “c”. In both cases “o” and “c” the comments do not display since those are not a valid comment_status.

    #28856

    Sekander Badsha
    Member
    Post count: 2067

    Hello Chris,

    I will test this again to find out the issue.

    Meanwhile you can check for theme or plugin conflict. Because from the code, you can clearly see that we have passed the same string we got from the dropdown field. So there is no chance to store the first letter.

    You can check by disabling all your plugins except WP User Frontend Pro and switch to a default theme of WordPress like – “Twenty Fourteen” (don't forget to paste the above code) and check and let me know.

    Thank you ๐Ÿ™‚

    #35787

    Ari
    Participant
    Post count: 30

    I have a same problem.
    If i disable commenting i can't enable it anymore?

    -Ari

    #38489

    Chris Swede
    Member
    Post count: 56

    Hi Sekander and Ari. This is a late reply and I am sorry for that, but I only had the opportunity to sort this out recently. The culprit in my case was a hidden field being added by WPUF, which sets comment status to “c” or “o” for reasons I have not researched. So by simply commenting out the line of code I got this to work with Sekander's function above. The line of code is in render-form.php, line 545:

    <input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>">

    Hope this helps!

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Enable/disable comments in frontend’ is closed to new replies.