phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

[RFC] add_post_filter hook

Request hook events and what data needs to be sent for the new hook system.

[RFC] add_post_filter hook

Postby copperblade » Thu Jan 06, 2011 8:03 pm

3.1 is closed (right?) so I thought I'd mention this here. Sorry if this has already been suggested.

I don't know if this belongs as a hook, but I think it would be particularly useful functionality for a variety of plugins that want to extend how posts are made.

  • Name: hook_add_post_filter
  • Rationale: Allows posts to be filtered and modified before inserted into the database, for example could handle URLs in a special way, censor words, and even check for spam.
  • Placement: functions_posting.php
  • Input arguments: the name of the added function to call (string)
  • Output format: true or false based on if the function exists
  • Output semantics: (see below) if the return code is false for the hook itself, it should just ignore the filter.

So obviously this hook requires you to add other functions, and multiple such functions could be added. The functions added need a standard interface taking the post text which will be changed by the function, and returning a true/false code that can halt the posting if needed. It's possible to specify other fields such as username, email address, etc. that belong with the post, but they should be optional and have ignorable defaults. In the simplest example, you could have a spam checker:

Code: Select all
hook_add_post_filter("my_spamcheck");


Then define your function:

Code: Select all
function my_spamcheck(&$post_text) {

// No modifications to $post_text
// Check if $post_text is spam
if ($is_spam) {
return false;  // Don't allow the post
} else {
return true; // Go ahead and post
}
}
copperblade
Registered User
 
Posts: 2
Joined: Thu Jan 06, 2011 7:43 pm

Re: [RFC] add_post_filter hook

Postby Oleg » Fri Jan 14, 2011 4:38 am

Moved to hook location requests since none of them have been implemented yet.
Oleg
3.1 Release Manager
3.1 Release Manager
 
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am


Return to [3.x] Event Requests

Who is online

Users browsing this forum: No registered users and 6 guests