Enable/disable comments in frontend

This topic contains 11 reply and 4 voices, and was last updated by Chris Swede 9 years, 8 months ago
Viewing 11 Posts - 1 through 11 (of 11 total)
Author Posts
July 23, 2014 at 4:48 am 23999
Chris Swede 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!
August 3, 2014 at 12:08 pm 24420
Sk Sk

Hello Chris,
WPUF has this feature already.

Thank you.

August 3, 2014 at 4:12 pm 24431
Sekander Badsha Sekander Badsha

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.

August 3, 2014 at 8:55 pm 24452
Chris Swede Chris Swede

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.

September 17, 2014 at 5:55 pm 26942
Chris Swede Chris Swede

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.

September 21, 2014 at 5:58 pm 27122
Sekander Badsha Sekander Badsha

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

October 9, 2014 at 3:54 pm 28113
Chris Swede Chris Swede

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!

October 15, 2014 at 4:40 pm 28429
Sekander Badsha Sekander Badsha

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 🙂

October 20, 2014 at 1:10 am 28694
Chris Swede Chris Swede

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.

October 22, 2014 at 11:51 am 28856
Sekander Badsha Sekander Badsha

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 🙂

February 4, 2015 at 11:33 pm 35787
Ari Ari

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

-Ari

March 8, 2015 at 7:41 am 38489
Chris Swede Chris Swede

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 11 Posts - 1 through 11 (of 11 total)