libreform / wp-libre-form

Easy native HTML5 forms for WordPress. Version 1.5 is unmaintained, but works without issue. 2.0 has been rewritten from the ground, and can be found at https://github.com/libreform/libreform
https://wordpress.org/plugins/wp-libre-form
GNU General Public License v3.0
67 stars 27 forks source link

Form specific actions and filters #52

Closed k1sul1 closed 7 years ago

k1sul1 commented 7 years ago

There's no way to set actions or filters on invidual forms.

Easily solvable though:

apply_filters( 'wplf_email_copy_to', $to )

=>

if ( has_filter( "wplf_{$form_id}_email_copy_to" ) ) {
  apply_filters( "wplf_{$form_id}_email_copy_to", $to );
} else {
  apply_filters( "wplf_email_copy_to", $to );
}
timiwahalahti commented 7 years ago

You can use wplf_email_copy_to and in function that gets driven just $_POST['_form_id'] to determine if we're in some form that needs to be handled differently.

Maybe a own filter for every form would be more clear, but then you can't use dynamic options to select forms where some action needs to run. It can become a problem in some use cases.

anttiviljami commented 7 years ago

I agree. ID within filter seems like it's a pretty standard way of doing stuff. I like having both options. @k1sul1 can you implement ? :)

k1sul1 commented 7 years ago

Yeah I'm a bit busy at the moment, but I can look into it in the near future.

anttiviljami commented 7 years ago

Just make sure you get paid for your libre forms work :)