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


