Skip to content

Instantly share code, notes, and snippets.

@gbeine
Last active June 9, 2020 13:43
Show Gist options
  • Save gbeine/9213695f481ee49feaae63d7b57040a9 to your computer and use it in GitHub Desktop.
Save gbeine/9213695f481ee49feaae63d7b57040a9 to your computer and use it in GitHub Desktop.
Individual fields support for The Newsletter Plugin's integration for WP Forms
diff -Nur newsletter-wpforms.orig/edit.php newsletter-wpforms/edit.php
--- newsletter-wpforms.orig/edit.php 2020-06-09 10:23:33.269629335 +0200
+++ newsletter-wpforms/edit.php 2020-06-09 11:47:12.719762440 +0200
@@ -117,6 +117,42 @@
</td>
</tr>
+ <tr valign="top">
+ <th>Extra profile fields</th>
+ <td>
+ <?php
+ // Use an API for this
+ $options_profile = get_option('newsletter_profile');
+ ?>
+ <table style="width: auto">
+ <thead>
+ <tr>
+ <th>
+ Newsletter field
+ </th>
+ <th>
+ Form field
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+
+ <?php
+ for ($i = 1; $i <= NEWSLETTER_PROFILE_MAX; $i++) {
+ if (empty($options_profile['profile_' . $i])) {
+ continue;
+ }
+ echo '<tr><td>' . esc_html($options_profile['profile_' . $i]) . '</td><td>';
+
+ $controls->select('profile_' . $i, $fields, 'Select...');
+ echo '</td></tr>';
+ }
+ ?>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+
<tr>
<th>Add subscribers to these lists</th>
<td><?php $controls->preferences() ?></td>
diff -Nur newsletter-wpforms.orig/plugin.php newsletter-wpforms/plugin.php
--- newsletter-wpforms.orig/plugin.php 2020-06-09 10:23:33.269629335 +0200
+++ newsletter-wpforms/plugin.php 2020-06-09 15:42:48.348617204 +0200
@@ -80,11 +80,23 @@
$_REQUEST['ns'] = stripslashes($flat_fields[$form_options['surname']]);
}
+
$user = NewsletterSubscription::instance()->subscribe();
- //var_dump($user);
- // Pre-assigned lists for this form
$user = array('id' => $user->id);
+
+ // Extra profiles
+ for ($i = 1; $i <= NEWSLETTER_PROFILE_MAX; $i++) {
+ if (empty($form_options['profile_' . $i])) {
+ continue;
+ }
+ $form_field = $form_options['profile_' . $i];
+ if (!isset($flat_fields[$form_field]))
+ continue;
+ $value = $flat_fields[$form_field];
+ $user['profile_' . $i] = stripslashes($value);
+ }
+ // Pre-assigned lists for this form
for ($i = 1; $i <= NEWSLETTER_LIST_MAX; $i++) {
if (empty($form_options['preferences_' . $i])) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment