I want to require my forum members to enter at least one word into the “tags”-line, when they are creating a new topic.
As regards plugins and solutions, what I found so far is the WyPiekacz-plugin which works well for posts: You can define rules for the data entered. It did not work for the creation of forum posts.
What I also found is the answer to “require one tag for each post” here in WordPress Answers which contains the code for a small plugin.
While exploring the php-files of bbPress, I added the last two lines to the following snippet within bb_post.php
:
$topic = trim( $_POST['topic'] );
$tags = trim( $_POST['tags'] );
if ('' == $topic)
bb_die(__('Please enter a topic title'));
if ('' == $tags)
bb_die(__('Please enter tags'));
In my understanding, that should do the trick – but still it doesn’t. Or am I using the wrong file? My installation uses bbPress within BuddyPress.
In the back end, it’s a matter of using the hook
save_post
, astopic
is a Custom Post Type.If no Tags are filled, saving is cancelled and a link is presented so the user can go back to the editing screen.
But, there’s one caveat: the title is not preserved, if it is a new topic it comes back blank and if it is an existing topic any changes are lost. The content and topic attributes are preserved.
I’m not quite sure there is a solution for this…
And in the front end, a couple of bbPress action hooks and a simple check
are enough(when posting multiple replies, a Javascript workaround is necessary, check comments):