There are many great code snippets in their Gitlab. You might find more on their…
Mailster Integration for Formidable Forms
On my main site enym.com I use Formidable forms because it has great anti-spam measures and also uses the general „block words“ settings from WordPress. Formidable forms integrate well with a lot of external services like Mailchimp etc. Nonetheless, there is no official support for the newsletter plugin „Mailster“ which I tend to use.
But there is an API and I dug deep on the web and finally found a solution which I want to share with you to make it widespread available. The original undocumented script was found in the codecanyon comment area of Mailster – there was a link to a Pastebin. So all credit goes to the unknown user who kindely pasted the solution there.
- See it in action here on enym.com and don’t forget to subscribe: DEMO 🙂
Why do I use Mailster?
Mailster is a fully functioned newsletter plugin which you can buy for a one-time-payment on themeforest/ codecanyon. It perfectly integrates with WordPress and can easily use external mail providers like Mailgun, which is my favorite BTW.
Having the mailing service within WordPress is nice because you have one less login to remember and have direct access to the content created in your site to be added to the mailing. Great. Also, you have a one common place for your subscribers and users. Especially for community sites, this is easier to handle than to have multiple subscriber lists across different services.
How to add a „Newsletter signup“ option to formidable forms?
First open the form where you want to add the „Subscribe me“ option. Use the switch field or a radio button to integrate the according question. Make sure it is disabled by default to not violate any laws. Note the ID in the top right corner.
1. Note the Form-ID
2. and 3. Note the data field IDs and the ID for the newsletter optin-field
4. Note the ID of the target mailing-list from Mailster
Snippet for functions.php
Paste the following script in your functions.php file in your child themes directory and adapt the following values in the mentioned places.
- Change the ID of the form:
$form_id == 1 - Change the IDs of the data fields. You can find the IDs easily in the backend:
$_POST[‚item_meta‘][7] (see the image above for an example). - Change the ID of the Optin-field:
if ($_POST[‚item_meta‘][72] == true) { - Change the ID of the list you want your guests to subscribe to:
$list_ids = 1;
//FORMIDABLE MAILSTER INTEGRATION add_action('frm_after_create_entry', 'mailster_formidable_subscribe', 30, 2); add_action('frm_after_update_entry', 'mailster_formidable_subscribe', 30, 2); function mailster_formidable_subscribe($entry_id, $form_id){ if ( $form_id == 1 ) { //change to the ID of your form // define to overwrite existing users $overwrite = true; // add with double opt in $double_opt_in = true; // prepare the userdata from a $_POST request. only the email is required $userdata = array( 'email' => $_POST['item_meta'][7], //change 535, 534, 533 to the ID of your email, first name and last name field 'firstname' => $_POST['item_meta'][6], //'lastname' => $_POST['item_meta'][534], 'status' => $double_opt_in ? 0 : 1, ); //only subscribe the user if opt-in is true if ($_POST['item_meta'][72] == true) { $subscriber_id = mailster( 'subscribers' )->add( $userdata, $overwrite ); if ( ! is_wp_error( $subscriber_id ) ) { // your list ids $list_ids = 1; mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_ids ); } else { // actions if adding fails. $subscriber_id is a WP_Error object } } } }
Dieser Beitrag hat 0 Kommentare