[RFC] add_post_filter hook

These event requests have either been rejected by the community or have become redundant because of code changes or other events requests.
Post Reply
copperblade
Registered User
Posts: 2
Joined: Thu Jan 06, 2011 7:43 pm

[RFC] add_post_filter hook

Post by 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
}
}

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] add_post_filter hook

Post by Oleg » Fri Jan 14, 2011 4:38 am

Moved to hook location requests since none of them have been implemented yet.

Tomba
Registered User
Posts: 13
Joined: Sat Apr 12, 2003 1:59 pm

Re: [RFC] add_post_filter hook

Post by Tomba » Sat Nov 16, 2013 1:38 pm

+1 for this.

I'm currently using a similar private code modification for spam checks, and depending on the outcome I'm currently doing

Code: Select all

$data['force_approved_state']) = 1;
Obviously we'd need all post data for this event, while I'm also using the $user and $auth objects.

User avatar
VSE
Extension Customisations
Extension Customisations
Posts: 670
Joined: Mon Mar 08, 2010 9:18 am

Re: [RFC] add_post_filter hook

Post by VSE » Sat Nov 16, 2013 5:23 pm

There already is an event to process a post before it is stored in the database: core.modify_text_for_storage_before and core.modify_text_for_storage_after in functions_content.php
Has an irascible disposition.

Post Reply