bbPress Report Abuse Plugin

I’m using bbPress for a project under development, and the client requested there be a “Report Abuse” link in the replies. I’ve wrapped this functionality up in a simple plugin called bbPress Report Abuse.

When a user clicks “Report Abuse” on a reply, it takes them to a Report Abuse form to fill out. There’s a form field for “Reported URL” which is auto-populated, so the administrator knows exactly which message is being reported.

This plugin has not been added to the WordPress.org repo due to its dependency on a premium plugin (Gravity Forms) and the installation instructions will likely result in a lot of questions there (it’s not as simple as clicking Activate).

If you’re new to plugin development, this simple plugin models many good practices for building WordPress plugins:

  • Built as a class. Keeps the plugin file clean and minimizes namespace issues (don’t have to worry about theme or plugins using the same function names as you).
  • Uses context-specific hooks/filters to limit where the code runs. For instance, hooking bbPress code to a bbPress filter so that it only runs if bbPress is also running.
  • Provides filters in areas where others might want to modify the plugin (the link text and url). Typically you’d use a textdomain for translatable text, but since there’s only one string used and people will likely want to change that string regardless of the language (ex: change it to “Report Inappropriate Content”), I felt a filter was most appropriate.

Download bbPress Report Abuse from GitHub. | View All of My Plugins

Installation

  1. Download and install plugin.
  2. Create a page called “Report Abuse” (URL = /report-abuse). See customization notes below for how to change this.
  3. Create a Gravity Form. Add whatever fields you’d like users to fill out. One of them should be “Reported URL”. Click the “Advanced” tab, check “Allow field to be populated dynamically”, and specify bbp_report_abuse as the parameter name.
  4. Add your new form to the Report Abuse page.

Customization Filters

  • bbpress_report_abuse_label – change the phrase “Report Abuse” to something else
  • bbpress_report_abuse_url  – change the URL of the form (defaults to /report-abuse)

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments are closed. Continue the conversation with me on Twitter: @billerickson

Comments

  1. Richard Buff says

    That’s some nice, concise code.
    I have a question about the logic: If you had left out the abuse_link_in_form() method, then the form would have been populated (by Gravity Form’s “Allow field to be populated dynamically” feature) simply with the numeric ID of the post, but instead you jump in and alter the value and replace the ID with the permalink before the form is rendered?

    Also, if you don’t mind my asking (I’d never seen this done before until I looked at your plugin), if you specify a GF field as being allowed to populate dynamically, is $field[‘inputName’] automatically assigned the value of the parameter you’re populating it with (‘bbp_report_abuse’ in this case)?

    • Bill Erickson says

      Technically the field wouldn’t be populated with anything if you left out the abuse_link_in_form() method. The URL has a query argument of ‘bbp_report_topic’ and the gravity form field is looking for a query argument of ‘bbp_report_abuse’.

      But if you set your form field to look for ‘bbp_report_topic’ then yes, it would show the ID of the comment. The client will find the URL more useful though, which is why I’m displaying that in the form.

      When you mark a GF field as populating dynamically, you have to specify the input name. Ex: http://cl.ly/image/3S3D3X3e2G1o

      • Richard Buff says

        Oh, duh, I overlooked the fact that the actual query argument is named differently than what GF is looking for, but you did answer my question.

        Regarding my second question, which I didn’t phrase all that well.. I had always assumed that the “parameter name” just meant it would get that parameter value from the querystring and automatically populate the form field with it (which was the only way I had ever used it). I had never realized until looking at your code that “the value you enter here will act as a reference to this field so Gravity Forms knows which field to populate” (from http://www.gravityhelp.com/documentation/index.php?title=Using_Dynamic_Population&diff=921&oldid=920) . So not only can it be directly populated from the querystring, but in addition to that option, you also have a way of accessing the form field directly and can populate it with ANYthing you want. It was a ‘gear clicking into place’ moment for me, lol.

        • Bill Erickson says

          Yep! I often use that to populate the field with data not in the URL query string. The query string part is just a bonus feature 🙂

          • Alex says

            Thanks Bill. I have a question on BBPress and spam.
            We have installed Akismet and active it.
            Under settings we clicked both “A comment is held for moderation” and “Comment author must have a previously approved comment”.
            Mot of the spam gets caught but the person in charge of the notifications for the replies still gets some spam (about a dozen spam messages per week) and she needs to decide which replies is spam and which is not.
            Is there any way to decrease the number of spam messages?
            Thanks in advance.
            Alex

  2. Takanori says

    Hello Bill

    Thank you very much for providing the wonderful plugin.
    It is very helpful.

    I would like to ask you a question if you don’t mind.
    Is it possible to make a plugin which has a mechanism for users to block abusive users directly from a post?

    • Bill Erickson says

      Yes, it may be possible. I haven’t worked with bbPress in a few years so there may already be a plugin that does this. If not, you could post this as a project on Codeable.