everpress-co / mailster-block-forms

Create Mailster forms with the block editor
https://wordpress.org/plugins/mailster-block-forms/
3 stars 0 forks source link

Just One Block Forms for many different pairs of category=>list (use of shortcodes) = Saving Time, Adding Flexibility #17

Open bastian-ar79 opened 9 months ago

bastian-ar79 commented 9 months ago

Is your enhancement related to a problem? Please describe.

The possibility of defining conditions for the appearance is formidable. I can decide that a block form will appear only in posts with an specific category, to subscribe the visitor to a list associated with that category, BUT ...

when you have more that a hundred categories, which is the case of my website, is kinda a hassle to create them one by one. And what if tomorrow I want to change the template for all of them? makes me have to decide beforehand very well what template to use. I would love the possibility of something way more flexible. The possibility of creating just one block form and apply it in the post or page with added parameters that define the list the visitor will subscribe accordingly to the category of the post.

In php I would use very well a shortcode of the form with parameter 'list' that I would fill via php. I would use a function list_of_category($category), taking the category of the post and returning the list(s) id(s) associated to it, that will fill the parameter 'list'

Designs

No response

Describe alternatives you've considered

The other alternative doesn't need the use of coding in php. I would love to create the block form and within its configuration define a list of pairs "category"-"list", creating the association between them. That way, the block form will appear in the post of the categories selected, and the visitor will be subscribed to the list associated with the category of the post, accordingly to the pairs of association, when he fill the form.

Again, when you have hundreds of categories, this solution would be so much appreciated. Thanks for reading!

Code of Conduct

evrpress commented 8 months ago

Hi Bastian!

Thanks for the feedback!

There's a check_validity function where I can add a filter

https://github.com/everpress-co/mailster-block-forms/blob/8a7798cfb273bb5d0a2d2b9961b97bfcaa95fd9f/classes/block-forms.class.php#L293-L335

The filter would look like this:

/**
 * Filter the validity of the form. If false the form will not be displayed if true it will be displayed.
 *
 * @param bool $validity true if valid
 * @param int $form_id the form id
 * @param array $options the options
 *
 */
$pre = apply_filters( 'mailster_block_form_check_validity', null, $form_id, $options );
if ( null !== $pre ) {
    return $pre;
}

So you can intercept the check and return either true or false to decide if the form gets displayed.

Is that something you can work with?