Changeset 3754846
- Timestamp:
- 10/19/2026 01:39:29 PM (3 weeks ago)
- Location:
- mailster-gravity-forms
- Files:
-
- 2 added
- 2 deleted
- 8 edited
- 1 copied
-
tags/2.1.0 (copied) (copied from mailster-gravity-forms/trunk )
-
tags/2.1.0/README.md (deleted)
-
tags/2.1.0/assets/style.css (modified) (2 diffs)
-
tags/2.1.0/classes/gravity.class.php (modified) (10 diffs)
-
tags/2.1.0/mailster-gravity-forms.php (modified) (1 diff)
-
tags/2.1.0/package.json (added)
-
tags/2.1.0/views/page.php (modified) (7 diffs)
-
trunk/README.md (deleted)
-
trunk/assets/style.css (modified) (2 diffs)
-
trunk/classes/gravity.class.php (modified) (10 diffs)
-
trunk/mailster-gravity-forms.php (modified) (1 diff)
-
trunk/package.json (added)
-
trunk/views/page.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mailster-gravity-forms/tags/2.1.0/assets/style.css
r2676638 r3754846 2 2 border-bottom: 1px solid #ccc; 3 3 } 4 4 5 #mailster-map li label { 5 6 display: inline-block; 6 7 width: 150px; 7 8 } 9 8 10 #mailster-map li label select { 9 11 display: inline-block; 10 12 width: 200px; 11 13 } 14 12 15 #mailster-map li ul li { 13 16 border-bottom: 0; 14 17 padding-left: 20px; 15 18 } 19 16 20 .gform-icon--mailster { 17 21 background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 949.9 778.9"><path d="M645.9 0L475 209 304 0H0v778.9h266V342l209 284.9L683.9 342v436.9h266V0z"/></svg>'); … … 21 25 width: 26px; 22 26 } 27 28 /* Gravity Forms renders this settings tab id. */ 29 /* stylelint-disable-next-line selector-id-pattern */ 23 30 #tab_mailster .gform-settings-panel__content select { 24 31 width: auto; -
mailster-gravity-forms/tags/2.1.0/classes/gravity.class.php
r2676638 r3754846 1 1 <?php 2 2 /** 3 * Gravity Forms integration for Mailster. 4 * 5 * @package Mailster_Gravity_Forms 6 */ 7 8 /** 9 * Connects Gravity Forms submissions to Mailster subscribers. 10 * 11 * @since 1.0 12 */ 3 13 class MailsterGravitiyForm { 4 14 15 /** 16 * Absolute filesystem path of this plugin. 17 * 18 * @since 1.0 19 * 20 * @var string 21 */ 5 22 private $plugin_path; 23 24 /** 25 * Base URL of this plugin. 26 * 27 * @since 1.0 28 * 29 * @var string 30 */ 6 31 private $plugin_url; 7 32 33 /** 34 * Registers lifecycle hooks and loads the text domain. 35 * 36 * @since 1.0 37 * 38 * @return void 39 */ 8 40 public function __construct() { 9 41 … … 17 49 18 50 add_action( 'plugins_loaded', array( &$this, 'init' ) ); 19 20 } 21 51 } 52 53 /** 54 * Fires when the plugin is activated. 55 * 56 * @since 1.0 57 * 58 * @param bool $network_wide Whether the plugin is being activated network-wide. 59 * @return void 60 */ 22 61 public function activate( $network_wide ) {} 23 62 63 /** 64 * Fires when the plugin is deactivated. 65 * 66 * @since 1.0 67 * 68 * @param bool $network_wide Whether the plugin is being deactivated network-wide. 69 * @return void 70 */ 24 71 public function deactivate( $network_wide ) {} 25 72 73 /** 74 * Registers Gravity Forms hooks for submissions and form settings. 75 * 76 * @since 1.0 77 * 78 * @return void 79 */ 26 80 public function init() { 27 81 … … 30 84 if ( is_admin() ) { 31 85 32 add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) , 10, 2);86 add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) ); 33 87 add_action( 'gform_form_settings_page_mailster', array( &$this, 'settings_page' ) ); 34 88 35 if ( isset( $_POST['gform_save_settings'] ) ) { 36 $this->save(); 37 } 38 } 39 } 40 89 $this->save(); 90 } 91 } 92 93 /** 94 * Creates or updates a Mailster subscriber from a Gravity Forms entry. 95 * 96 * Respects the form's list mapping, conditional field, and double opt-in settings. 97 * 98 * @since 1.0 99 * 100 * @param array $entry Submitted Gravity Forms entry. 101 * @param array $form Gravity Forms form meta, including Mailster settings. 102 * @return void 103 */ 41 104 public function after_submission( $entry, $form ) { 42 105 … … 62 125 if ( isset( $form['mailster']['conditional_id'] ) ) { 63 126 64 if ( isset( $entry[ $form['mailster']['conditional_id'] ] ) && ( $entry[ $form['mailster']['conditional_id'] ] != $form['mailster']['conditional_field'] ) ) { 65 return; 66 } 67 if ( ! isset( $entry[ $form['mailster']['conditional_id'] ] ) ) { 127 $conditional_id = $form['mailster']['conditional_id']; 128 if ( isset( $entry[ $conditional_id ] ) && (string) $entry[ $conditional_id ] !== (string) $form['mailster']['conditional_field'] ) { 129 return; 130 } 131 if ( ! isset( $entry[ $conditional_id ] ) ) { 68 132 return; 69 133 } … … 85 149 86 150 foreach ( $form['mailster']['map'] as $field_id => $key ) { 87 if ( '_list' == $key ) {151 if ( '_list' === $key ) { 88 152 $listname = $entry[ $field_id ]; 89 153 if ( empty( $listname ) ) { … … 96 160 $list_ids[] = $list_id; 97 161 } 98 } elseif ( $key != -1) {162 } elseif ( '-1' !== (string) $key ) { 99 163 $userdata[ $key ] = $entry[ $field_id ]; 100 164 } … … 105 169 } 106 170 107 if ( $subscriber = mailster( 'subscribers' )->get_by_mail( $userdata['email'] ) ) { 171 $subscriber = mailster( 'subscribers' )->get_by_mail( $userdata['email'] ); 172 if ( $subscriber ) { 173 $userdata['ID'] = (int) $subscriber->ID; 174 $userdata['hash'] = $subscriber->hash; 108 175 $userdata['status'] = $subscriber->status; 109 $subscriber_notification = $subscriber->status == 0; // send again if not confirmed already, 176 $subscriber_notification = 0 === (int) $subscriber->status; // send again if not confirmed already. 177 178 // add() strips the ID on the front end. When the duplicate-key update 179 // changes nothing, insert_id is 0 and send_confirmations() emails every 180 // pending subscriber. Updating by ID keeps the resend on this subscriber. 181 $subscriber_id = mailster( 'subscribers' )->update( $userdata, true, true, $subscriber_notification ); 110 182 } else { 111 183 $userdata['status'] = isset( $form['mailster']['double-opt-in'] ) ? 0 : 1; 112 184 $subscriber_notification = true; 113 } 114 115 $overwrite = true; 116 $merge = true; 117 $subscriber_id = mailster( 'subscribers' )->add( $userdata, $overwrite, $merge, $subscriber_notification ); 185 $subscriber_id = mailster( 'subscribers' )->add( $userdata, true, true, $subscriber_notification ); 186 } 118 187 119 188 if ( ! is_wp_error( $subscriber_id ) ) { 120 189 mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_ids, false, $userdata['status'] ? true : false ); 121 190 } 122 123 } 124 191 } 192 193 /** 194 * Prints the Mailster panel on the Gravity Forms settings screen. 195 * 196 * @since 1.0 197 * 198 * @return void 199 */ 125 200 public function settings_page() { 126 201 … … 132 207 } 133 208 134 public function settings_menu( $settings_tabs, $form_id ) { 209 /** 210 * Adds the Mailster tab to a form's settings menu. 211 * 212 * @since 1.0 213 * 214 * @param array $settings_tabs Existing settings tabs. 215 * @return array Settings tabs including the Mailster tab. 216 */ 217 public function settings_menu( $settings_tabs ) { 135 218 136 219 wp_enqueue_style( 'mailster-gravityforms-style', $this->plugin_url . 'assets/style.css', array(), MAILSTER_GRAVITYFORMS_VERSION ); … … 144 227 } 145 228 229 /** 230 * Saves the posted Mailster settings onto the current Gravity Form. 231 * 232 * @since 1.0 233 * 234 * @return void 235 */ 146 236 public function save() { 147 237 148 238 if ( ! current_user_can( 'manage_options' ) ) { 149 return; } 150 151 if ( ! isset( $_POST['gform_save_form_settings'] ) || ! wp_verify_nonce( $_POST['gform_save_form_settings'], 'mailster_gf_save_form' ) ) { 152 return; } 153 154 $form_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : null; 239 return; 240 } 241 242 $nonce = isset( $_POST['gform_save_form_settings'] ) ? sanitize_text_field( wp_unslash( $_POST['gform_save_form_settings'] ) ) : ''; 243 if ( ! wp_verify_nonce( $nonce, 'mailster_gf_save_form' ) ) { 244 return; 245 } 246 247 $form_id = isset( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : 0; 155 248 if ( ! $form_id ) { 156 return; } 249 return; 250 } 157 251 158 252 $form = RGFormsModel::get_form_meta( $form_id ); 159 if ( ! $form ) { 160 return; } 161 162 $form['mailster'] = $_POST['mailster']; 163 $conditional = explode( '|', $form['mailster']['conditional_field'] ); 253 if ( ! $form || ! isset( $_POST['mailster'] ) || ! is_array( $_POST['mailster'] ) ) { 254 return; 255 } 256 257 $form['mailster'] = map_deep( wp_unslash( $_POST['mailster'] ), 'sanitize_text_field' ); 258 259 if ( isset( $_POST['mailster']['conditional_field'] ) ) { 260 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- tags stripped; octets must be preserved for GF choice values. 261 $raw_conditional = wp_unslash( $_POST['mailster']['conditional_field'] ); 262 if ( is_scalar( $raw_conditional ) ) { 263 $form['mailster']['conditional_field'] = preg_replace( 264 '/[\r\n\t]+/', 265 '', 266 wp_strip_all_tags( (string) $raw_conditional ) 267 ); 268 } 269 } 270 271 $conditional_field = isset( $form['mailster']['conditional_field'] ) ? $form['mailster']['conditional_field'] : ''; 272 $conditional = explode( '|', $conditional_field ); 164 273 165 274 if ( count( $conditional ) > 1 ) { … … 170 279 171 280 RGFormsModel::update_form_meta( $form_id, $form ); 172 173 281 } 174 282 } -
mailster-gravity-forms/tags/2.1.0/mailster-gravity-forms.php
r3093222 r3754846 1 1 <?php 2 /* 3 Plugin Name: Mailster Gravity Forms 4 Plugin URI: https://mailster.co/?utm_campaign=wporg&utm_source=wordpress.org&utm_medium=plugin&utm_term=Gravity+Forms 5 Version: 2.0.0 6 License: GPLv2 7 Author: EverPress 8 Author URI: https://mailster.co 9 Text Domain: mailster-gravityforms 10 Description: Integrates Mailster Newsletter Plugin with Gravity Forms to subscribe users with a Gravity Form. 11 Requires the Mailster Newsletter Plugin and the Gravity Forms plugin 12 */ 2 /** 3 * Plugin Name: Mailster Gravity Forms 4 * Plugin URI: https://mailster.co/?utm_campaign=wporg&utm_source=wordpress.org&utm_medium=plugin&utm_term=Gravity+Forms 5 * Version: 2.1.0 6 * License: GPLv2 7 * Author: EverPress 8 * Author URI: https://mailster.co 9 * Text Domain: mailster-gravityforms 10 * Description: Integrates Mailster Newsletter Plugin with Gravity Forms to subscribe users with a Gravity Form. 11 * Requires the Mailster Newsletter Plugin and the Gravity Forms plugin 12 * 13 * @package Mailster_Gravity_Forms 14 */ 13 15 14 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2. 0.0' );16 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.1.0' ); 15 17 define( 'MAILSTER_GRAVITYFORMS_REQUIRED_VERSION', '4.0' ); 16 18 define( 'MAILSTER_GRAVITYFORMS_FILE', __FILE__ ); -
mailster-gravity-forms/tags/2.1.0/views/page.php
r3093222 r3754846 1 1 <?php 2 /** 3 * Mailster settings panel for a Gravity Form. 4 * 5 * @package Mailster_Gravity_Forms 6 */ 2 7 3 8 if ( ! function_exists( 'mailster' ) ) { … … 8 13 } 9 14 10 $ form_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : null;11 $ form = RGFormsModel::get_form_meta( $form_id );12 $mailster = isset( $form['mailster'] ) ? $form['mailster'] : array(15 $mailster_form_id = absint( filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) ); 16 $mailster_form = RGFormsModel::get_form_meta( $mailster_form_id ); 17 $mailster = isset( $mailster_form['mailster'] ) ? $mailster_form['mailster'] : array( 13 18 'lists' => array(), 14 19 'map' => array(), … … 39 44 </p> 40 45 <?php 41 $ fields = array(46 $mailster_fields = array( 42 47 'email' => mailster_text( 'email' ), 43 48 'firstname' => mailster_text( 'firstname' ), … … 45 50 ); 46 51 47 if ( $customfields = mailster()->get_custom_fields() ) { 48 foreach ( $customfields as $field => $data ) { 49 $fields[ $field ] = $data['name']; 52 $mailster_custom_fields = mailster()->get_custom_fields(); 53 if ( $mailster_custom_fields ) { 54 foreach ( $mailster_custom_fields as $mailster_field_key => $mailster_field_data ) { 55 $mailster_fields[ $mailster_field_key ] = $mailster_field_data['name']; 50 56 } 51 57 } 52 $optionsdd = '<option value="-1">' . esc_html__( 'choose', 'mailster-gravityforms' ) . '</option>';53 foreach ( $fields as $id => $name ) {54 $optionsdd .= '<option value="' . $id . '">' . $name . '</option>';55 }56 58 57 if ( is_array( $ form['fields'] ) && ! empty( $form['fields'] ) ) {59 if ( is_array( $mailster_form['fields'] ) && ! empty( $mailster_form['fields'] ) ) { 58 60 echo '<ul id="mailster-map">'; 59 foreach ( $form['fields'] as $field ) { 60 if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { 61 echo '<li><strong>' . ( ! empty( $field['label'] ) ? $field['label'] : esc_html__( 'Untitled', 'mailster-gravityforms' ) ) . ':</strong><ul>'; 61 foreach ( $mailster_form['fields'] as $mailster_field ) { 62 if ( isset( $mailster_field['inputs'] ) && is_array( $mailster_field['inputs'] ) ) { 63 $mailster_group_label = ! empty( $mailster_field['label'] ) ? $mailster_field['label'] : __( 'Untitled', 'mailster-gravityforms' ); 64 echo '<li><strong>' . esc_html( $mailster_group_label ) . ':</strong><ul>'; 62 65 63 foreach ( $field['inputs'] as $input ) { 64 echo '<li><label>' . $input['label'] . '</label> ➨ <select name="mailster[map][' . $input['id'] . ']" >'; 66 foreach ( $mailster_field['inputs'] as $mailster_input ) { 67 $mailster_mapped_input = isset( $mailster['map'][ $mailster_input['id'] . '' ] ) ? $mailster['map'][ $mailster_input['id'] . '' ] : ''; 68 echo '<li><label>' . esc_html( $mailster_input['label'] ) . '</label> ➨ <select name="mailster[map][' . esc_attr( $mailster_input['id'] ) . ']" >'; 65 69 echo '<option value="-1">' . esc_html__( 'not mapped', 'mailster-gravityforms' ) . '</option>'; 66 echo '<optgroup label="' . esc_ html__( 'Fields', 'mailster-gravityforms' ) . '">';67 foreach ( $ fields as $id => $name ) {68 echo '<option value="' . $id . '" ' . selected( $id, @$mailster['map'][ $input['id'] . '' ], false ) . '>' . $name. '</option>';70 echo '<optgroup label="' . esc_attr__( 'Fields', 'mailster-gravityforms' ) . '">'; 71 foreach ( $mailster_fields as $mailster_field_key => $mailster_field_name ) { 72 echo '<option value="' . esc_attr( $mailster_field_key ) . '" ' . selected( $mailster_field_key, $mailster_mapped_input, false ) . '>' . esc_html( $mailster_field_name ) . '</option>'; 69 73 } 70 74 echo '</optgroup>'; 71 echo '<optgroup label="' . esc_ html__( 'List specific', 'mailster-gravityforms' ) . '">';72 echo '<option value="_list" ' . selected( '_list', @$mailster['map'][ $input['id'] . '' ], false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>';75 echo '<optgroup label="' . esc_attr__( 'List specific', 'mailster-gravityforms' ) . '">'; 76 echo '<option value="_list" ' . selected( '_list', $mailster_mapped_input, false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>'; 73 77 echo '</optgroup>'; 74 78 echo '</select></li>'; … … 78 82 79 83 } else { 80 echo '<li> <label><strong>' . $field['label'] . '</strong></label> ➨ <select name="mailster[map][' . $field['id'] . ']">'; 84 $mailster_mapped_field = isset( $mailster['map'][ $mailster_field['id'] . '' ] ) ? $mailster['map'][ $mailster_field['id'] . '' ] : ''; 85 echo '<li> <label><strong>' . esc_html( $mailster_field['label'] ) . '</strong></label> ➨ <select name="mailster[map][' . esc_attr( $mailster_field['id'] ) . ']">'; 81 86 echo '<option value="-1">' . esc_html__( 'not mapped', 'mailster-gravityforms' ) . '</option>'; 82 echo '<optgroup label="' . esc_ html__( 'Fields', 'mailster-gravityforms' ) . '">';83 foreach ( $ fields as $id => $name ) {84 echo '<option value="' . $id . '" ' . selected( $id, @$mailster['map'][ $field['id'] . '' ], false ) . '>' . $name. '</option>';87 echo '<optgroup label="' . esc_attr__( 'Fields', 'mailster-gravityforms' ) . '">'; 88 foreach ( $mailster_fields as $mailster_field_key => $mailster_field_name ) { 89 echo '<option value="' . esc_attr( $mailster_field_key ) . '" ' . selected( $mailster_field_key, $mailster_mapped_field, false ) . '>' . esc_html( $mailster_field_name ) . '</option>'; 85 90 } 86 91 echo '</optgroup>'; 87 echo '<optgroup label="' . esc_ html__( 'List specific', 'mailster-gravityforms' ) . '">';88 echo '<option value="_list" ' . selected( '_list', @$mailster['map'][ $field['id'] . '' ], false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>';92 echo '<optgroup label="' . esc_attr__( 'List specific', 'mailster-gravityforms' ) . '">'; 93 echo '<option value="_list" ' . selected( '_list', $mailster_mapped_field, false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>'; 89 94 echo '</optgroup>'; 90 95 echo '</select></li>'; … … 104 109 <td> 105 110 <?php 106 $ selected= isset( $mailster['lists'] ) ? $mailster['lists'] : array();107 mailster( 'lists' )->print_it( null, null, $name = 'mailster[lists]', false, $selected);111 $mailster_selected_lists = isset( $mailster['lists'] ) ? $mailster['lists'] : array(); 112 mailster( 'lists' )->print_it( null, null, 'mailster[lists]', false, $mailster_selected_lists ); 108 113 ?> 109 114 </td> … … 121 126 <p><?php esc_html_e( 'subscribe user only if', 'mailster-gravityforms' ); ?> 122 127 <?php 123 if ( is_array( $ form['fields'] ) ) {128 if ( is_array( $mailster_form['fields'] ) ) { 124 129 echo '<select name="mailster[conditional_field]"><option value="-1">-</option>'; 125 foreach ( $ form['fields'] as $field ) {126 if ( ! in_array( $ field['type'], array( 'checkbox', 'radio' )) ) {130 foreach ( $mailster_form['fields'] as $mailster_field ) { 131 if ( ! in_array( $mailster_field['type'], array( 'checkbox', 'radio' ), true ) ) { 127 132 continue; 128 133 } 129 134 130 if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { 131 echo '<optgroup label="' . ( $field['label'] ? $field['label'] : esc_html__( 'Checkbox', 'mailster-gravityforms' ) ) . '">'; 132 foreach ( $field['inputs'] as $input ) { 133 echo '<option value="' . $input['id'] . '" ' . selected( $input['id'], $mailster['conditional_field'], false ) . '>' . $input['label'] . '</option>'; } 135 if ( isset( $mailster_field['inputs'] ) && is_array( $mailster_field['inputs'] ) ) { 136 $mailster_group_label = $mailster_field['label'] ? $mailster_field['label'] : __( 'Checkbox', 'mailster-gravityforms' ); 137 echo '<optgroup label="' . esc_attr( $mailster_group_label ) . '">'; 138 foreach ( $mailster_field['inputs'] as $mailster_input ) { 139 echo '<option value="' . esc_attr( $mailster_input['id'] ) . '" ' . selected( $mailster_input['id'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_input['label'] ) . '</option>'; 140 } 134 141 echo '</optgroup>'; 135 142 136 } elseif ( isset( $field['choices'] ) && is_array( $field['choices'] ) ) { 137 echo '<optgroup label="' . $field['label'] . '">'; 138 foreach ( $field['choices'] as $input ) { 139 echo '<option value="' . $field['id'] . '|' . $input['value'] . '" ' . selected( $input['value'], $mailster['conditional_field'], false ) . '>' . $input['text'] . '</option>'; } 143 } elseif ( isset( $mailster_field['choices'] ) && is_array( $mailster_field['choices'] ) ) { 144 echo '<optgroup label="' . esc_attr( $mailster_field['label'] ) . '">'; 145 foreach ( $mailster_field['choices'] as $mailster_input ) { 146 echo '<option value="' . esc_attr( $mailster_field['id'] . '|' . $mailster_input['value'] ) . '" ' . selected( $mailster_input['value'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_input['text'] ) . '</option>'; 147 } 140 148 echo '</optgroup>'; 141 149 142 150 } else { 143 echo '<option value="' . $field['id'] . '" ' . selected( $input['id'], $mailster['conditional_field'], false ) . '>sss' . $field['label']. '</option>';151 echo '<option value="' . esc_attr( $mailster_field['id'] ) . '" ' . selected( $mailster_field['id'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_field['label'] ) . '</option>'; 144 152 } 145 153 } -
mailster-gravity-forms/trunk/assets/style.css
r2676638 r3754846 2 2 border-bottom: 1px solid #ccc; 3 3 } 4 4 5 #mailster-map li label { 5 6 display: inline-block; 6 7 width: 150px; 7 8 } 9 8 10 #mailster-map li label select { 9 11 display: inline-block; 10 12 width: 200px; 11 13 } 14 12 15 #mailster-map li ul li { 13 16 border-bottom: 0; 14 17 padding-left: 20px; 15 18 } 19 16 20 .gform-icon--mailster { 17 21 background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 949.9 778.9"><path d="M645.9 0L475 209 304 0H0v778.9h266V342l209 284.9L683.9 342v436.9h266V0z"/></svg>'); … … 21 25 width: 26px; 22 26 } 27 28 /* Gravity Forms renders this settings tab id. */ 29 /* stylelint-disable-next-line selector-id-pattern */ 23 30 #tab_mailster .gform-settings-panel__content select { 24 31 width: auto; -
mailster-gravity-forms/trunk/classes/gravity.class.php
r2676638 r3754846 1 1 <?php 2 2 /** 3 * Gravity Forms integration for Mailster. 4 * 5 * @package Mailster_Gravity_Forms 6 */ 7 8 /** 9 * Connects Gravity Forms submissions to Mailster subscribers. 10 * 11 * @since 1.0 12 */ 3 13 class MailsterGravitiyForm { 4 14 15 /** 16 * Absolute filesystem path of this plugin. 17 * 18 * @since 1.0 19 * 20 * @var string 21 */ 5 22 private $plugin_path; 23 24 /** 25 * Base URL of this plugin. 26 * 27 * @since 1.0 28 * 29 * @var string 30 */ 6 31 private $plugin_url; 7 32 33 /** 34 * Registers lifecycle hooks and loads the text domain. 35 * 36 * @since 1.0 37 * 38 * @return void 39 */ 8 40 public function __construct() { 9 41 … … 17 49 18 50 add_action( 'plugins_loaded', array( &$this, 'init' ) ); 19 20 } 21 51 } 52 53 /** 54 * Fires when the plugin is activated. 55 * 56 * @since 1.0 57 * 58 * @param bool $network_wide Whether the plugin is being activated network-wide. 59 * @return void 60 */ 22 61 public function activate( $network_wide ) {} 23 62 63 /** 64 * Fires when the plugin is deactivated. 65 * 66 * @since 1.0 67 * 68 * @param bool $network_wide Whether the plugin is being deactivated network-wide. 69 * @return void 70 */ 24 71 public function deactivate( $network_wide ) {} 25 72 73 /** 74 * Registers Gravity Forms hooks for submissions and form settings. 75 * 76 * @since 1.0 77 * 78 * @return void 79 */ 26 80 public function init() { 27 81 … … 30 84 if ( is_admin() ) { 31 85 32 add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) , 10, 2);86 add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) ); 33 87 add_action( 'gform_form_settings_page_mailster', array( &$this, 'settings_page' ) ); 34 88 35 if ( isset( $_POST['gform_save_settings'] ) ) { 36 $this->save(); 37 } 38 } 39 } 40 89 $this->save(); 90 } 91 } 92 93 /** 94 * Creates or updates a Mailster subscriber from a Gravity Forms entry. 95 * 96 * Respects the form's list mapping, conditional field, and double opt-in settings. 97 * 98 * @since 1.0 99 * 100 * @param array $entry Submitted Gravity Forms entry. 101 * @param array $form Gravity Forms form meta, including Mailster settings. 102 * @return void 103 */ 41 104 public function after_submission( $entry, $form ) { 42 105 … … 62 125 if ( isset( $form['mailster']['conditional_id'] ) ) { 63 126 64 if ( isset( $entry[ $form['mailster']['conditional_id'] ] ) && ( $entry[ $form['mailster']['conditional_id'] ] != $form['mailster']['conditional_field'] ) ) { 65 return; 66 } 67 if ( ! isset( $entry[ $form['mailster']['conditional_id'] ] ) ) { 127 $conditional_id = $form['mailster']['conditional_id']; 128 if ( isset( $entry[ $conditional_id ] ) && (string) $entry[ $conditional_id ] !== (string) $form['mailster']['conditional_field'] ) { 129 return; 130 } 131 if ( ! isset( $entry[ $conditional_id ] ) ) { 68 132 return; 69 133 } … … 85 149 86 150 foreach ( $form['mailster']['map'] as $field_id => $key ) { 87 if ( '_list' == $key ) {151 if ( '_list' === $key ) { 88 152 $listname = $entry[ $field_id ]; 89 153 if ( empty( $listname ) ) { … … 96 160 $list_ids[] = $list_id; 97 161 } 98 } elseif ( $key != -1) {162 } elseif ( '-1' !== (string) $key ) { 99 163 $userdata[ $key ] = $entry[ $field_id ]; 100 164 } … … 105 169 } 106 170 107 if ( $subscriber = mailster( 'subscribers' )->get_by_mail( $userdata['email'] ) ) { 171 $subscriber = mailster( 'subscribers' )->get_by_mail( $userdata['email'] ); 172 if ( $subscriber ) { 173 $userdata['ID'] = (int) $subscriber->ID; 174 $userdata['hash'] = $subscriber->hash; 108 175 $userdata['status'] = $subscriber->status; 109 $subscriber_notification = $subscriber->status == 0; // send again if not confirmed already, 176 $subscriber_notification = 0 === (int) $subscriber->status; // send again if not confirmed already. 177 178 // add() strips the ID on the front end. When the duplicate-key update 179 // changes nothing, insert_id is 0 and send_confirmations() emails every 180 // pending subscriber. Updating by ID keeps the resend on this subscriber. 181 $subscriber_id = mailster( 'subscribers' )->update( $userdata, true, true, $subscriber_notification ); 110 182 } else { 111 183 $userdata['status'] = isset( $form['mailster']['double-opt-in'] ) ? 0 : 1; 112 184 $subscriber_notification = true; 113 } 114 115 $overwrite = true; 116 $merge = true; 117 $subscriber_id = mailster( 'subscribers' )->add( $userdata, $overwrite, $merge, $subscriber_notification ); 185 $subscriber_id = mailster( 'subscribers' )->add( $userdata, true, true, $subscriber_notification ); 186 } 118 187 119 188 if ( ! is_wp_error( $subscriber_id ) ) { 120 189 mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_ids, false, $userdata['status'] ? true : false ); 121 190 } 122 123 } 124 191 } 192 193 /** 194 * Prints the Mailster panel on the Gravity Forms settings screen. 195 * 196 * @since 1.0 197 * 198 * @return void 199 */ 125 200 public function settings_page() { 126 201 … … 132 207 } 133 208 134 public function settings_menu( $settings_tabs, $form_id ) { 209 /** 210 * Adds the Mailster tab to a form's settings menu. 211 * 212 * @since 1.0 213 * 214 * @param array $settings_tabs Existing settings tabs. 215 * @return array Settings tabs including the Mailster tab. 216 */ 217 public function settings_menu( $settings_tabs ) { 135 218 136 219 wp_enqueue_style( 'mailster-gravityforms-style', $this->plugin_url . 'assets/style.css', array(), MAILSTER_GRAVITYFORMS_VERSION ); … … 144 227 } 145 228 229 /** 230 * Saves the posted Mailster settings onto the current Gravity Form. 231 * 232 * @since 1.0 233 * 234 * @return void 235 */ 146 236 public function save() { 147 237 148 238 if ( ! current_user_can( 'manage_options' ) ) { 149 return; } 150 151 if ( ! isset( $_POST['gform_save_form_settings'] ) || ! wp_verify_nonce( $_POST['gform_save_form_settings'], 'mailster_gf_save_form' ) ) { 152 return; } 153 154 $form_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : null; 239 return; 240 } 241 242 $nonce = isset( $_POST['gform_save_form_settings'] ) ? sanitize_text_field( wp_unslash( $_POST['gform_save_form_settings'] ) ) : ''; 243 if ( ! wp_verify_nonce( $nonce, 'mailster_gf_save_form' ) ) { 244 return; 245 } 246 247 $form_id = isset( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : 0; 155 248 if ( ! $form_id ) { 156 return; } 249 return; 250 } 157 251 158 252 $form = RGFormsModel::get_form_meta( $form_id ); 159 if ( ! $form ) { 160 return; } 161 162 $form['mailster'] = $_POST['mailster']; 163 $conditional = explode( '|', $form['mailster']['conditional_field'] ); 253 if ( ! $form || ! isset( $_POST['mailster'] ) || ! is_array( $_POST['mailster'] ) ) { 254 return; 255 } 256 257 $form['mailster'] = map_deep( wp_unslash( $_POST['mailster'] ), 'sanitize_text_field' ); 258 259 if ( isset( $_POST['mailster']['conditional_field'] ) ) { 260 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- tags stripped; octets must be preserved for GF choice values. 261 $raw_conditional = wp_unslash( $_POST['mailster']['conditional_field'] ); 262 if ( is_scalar( $raw_conditional ) ) { 263 $form['mailster']['conditional_field'] = preg_replace( 264 '/[\r\n\t]+/', 265 '', 266 wp_strip_all_tags( (string) $raw_conditional ) 267 ); 268 } 269 } 270 271 $conditional_field = isset( $form['mailster']['conditional_field'] ) ? $form['mailster']['conditional_field'] : ''; 272 $conditional = explode( '|', $conditional_field ); 164 273 165 274 if ( count( $conditional ) > 1 ) { … … 170 279 171 280 RGFormsModel::update_form_meta( $form_id, $form ); 172 173 281 } 174 282 } -
mailster-gravity-forms/trunk/mailster-gravity-forms.php
r3093222 r3754846 1 1 <?php 2 /* 3 Plugin Name: Mailster Gravity Forms 4 Plugin URI: https://mailster.co/?utm_campaign=wporg&utm_source=wordpress.org&utm_medium=plugin&utm_term=Gravity+Forms 5 Version: 2.0.0 6 License: GPLv2 7 Author: EverPress 8 Author URI: https://mailster.co 9 Text Domain: mailster-gravityforms 10 Description: Integrates Mailster Newsletter Plugin with Gravity Forms to subscribe users with a Gravity Form. 11 Requires the Mailster Newsletter Plugin and the Gravity Forms plugin 12 */ 2 /** 3 * Plugin Name: Mailster Gravity Forms 4 * Plugin URI: https://mailster.co/?utm_campaign=wporg&utm_source=wordpress.org&utm_medium=plugin&utm_term=Gravity+Forms 5 * Version: 2.1.0 6 * License: GPLv2 7 * Author: EverPress 8 * Author URI: https://mailster.co 9 * Text Domain: mailster-gravityforms 10 * Description: Integrates Mailster Newsletter Plugin with Gravity Forms to subscribe users with a Gravity Form. 11 * Requires the Mailster Newsletter Plugin and the Gravity Forms plugin 12 * 13 * @package Mailster_Gravity_Forms 14 */ 13 15 14 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2. 0.0' );16 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.1.0' ); 15 17 define( 'MAILSTER_GRAVITYFORMS_REQUIRED_VERSION', '4.0' ); 16 18 define( 'MAILSTER_GRAVITYFORMS_FILE', __FILE__ ); -
mailster-gravity-forms/trunk/views/page.php
r3093222 r3754846 1 1 <?php 2 /** 3 * Mailster settings panel for a Gravity Form. 4 * 5 * @package Mailster_Gravity_Forms 6 */ 2 7 3 8 if ( ! function_exists( 'mailster' ) ) { … … 8 13 } 9 14 10 $ form_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : null;11 $ form = RGFormsModel::get_form_meta( $form_id );12 $mailster = isset( $form['mailster'] ) ? $form['mailster'] : array(15 $mailster_form_id = absint( filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) ); 16 $mailster_form = RGFormsModel::get_form_meta( $mailster_form_id ); 17 $mailster = isset( $mailster_form['mailster'] ) ? $mailster_form['mailster'] : array( 13 18 'lists' => array(), 14 19 'map' => array(), … … 39 44 </p> 40 45 <?php 41 $ fields = array(46 $mailster_fields = array( 42 47 'email' => mailster_text( 'email' ), 43 48 'firstname' => mailster_text( 'firstname' ), … … 45 50 ); 46 51 47 if ( $customfields = mailster()->get_custom_fields() ) { 48 foreach ( $customfields as $field => $data ) { 49 $fields[ $field ] = $data['name']; 52 $mailster_custom_fields = mailster()->get_custom_fields(); 53 if ( $mailster_custom_fields ) { 54 foreach ( $mailster_custom_fields as $mailster_field_key => $mailster_field_data ) { 55 $mailster_fields[ $mailster_field_key ] = $mailster_field_data['name']; 50 56 } 51 57 } 52 $optionsdd = '<option value="-1">' . esc_html__( 'choose', 'mailster-gravityforms' ) . '</option>';53 foreach ( $fields as $id => $name ) {54 $optionsdd .= '<option value="' . $id . '">' . $name . '</option>';55 }56 58 57 if ( is_array( $ form['fields'] ) && ! empty( $form['fields'] ) ) {59 if ( is_array( $mailster_form['fields'] ) && ! empty( $mailster_form['fields'] ) ) { 58 60 echo '<ul id="mailster-map">'; 59 foreach ( $form['fields'] as $field ) { 60 if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { 61 echo '<li><strong>' . ( ! empty( $field['label'] ) ? $field['label'] : esc_html__( 'Untitled', 'mailster-gravityforms' ) ) . ':</strong><ul>'; 61 foreach ( $mailster_form['fields'] as $mailster_field ) { 62 if ( isset( $mailster_field['inputs'] ) && is_array( $mailster_field['inputs'] ) ) { 63 $mailster_group_label = ! empty( $mailster_field['label'] ) ? $mailster_field['label'] : __( 'Untitled', 'mailster-gravityforms' ); 64 echo '<li><strong>' . esc_html( $mailster_group_label ) . ':</strong><ul>'; 62 65 63 foreach ( $field['inputs'] as $input ) { 64 echo '<li><label>' . $input['label'] . '</label> ➨ <select name="mailster[map][' . $input['id'] . ']" >'; 66 foreach ( $mailster_field['inputs'] as $mailster_input ) { 67 $mailster_mapped_input = isset( $mailster['map'][ $mailster_input['id'] . '' ] ) ? $mailster['map'][ $mailster_input['id'] . '' ] : ''; 68 echo '<li><label>' . esc_html( $mailster_input['label'] ) . '</label> ➨ <select name="mailster[map][' . esc_attr( $mailster_input['id'] ) . ']" >'; 65 69 echo '<option value="-1">' . esc_html__( 'not mapped', 'mailster-gravityforms' ) . '</option>'; 66 echo '<optgroup label="' . esc_ html__( 'Fields', 'mailster-gravityforms' ) . '">';67 foreach ( $ fields as $id => $name ) {68 echo '<option value="' . $id . '" ' . selected( $id, @$mailster['map'][ $input['id'] . '' ], false ) . '>' . $name. '</option>';70 echo '<optgroup label="' . esc_attr__( 'Fields', 'mailster-gravityforms' ) . '">'; 71 foreach ( $mailster_fields as $mailster_field_key => $mailster_field_name ) { 72 echo '<option value="' . esc_attr( $mailster_field_key ) . '" ' . selected( $mailster_field_key, $mailster_mapped_input, false ) . '>' . esc_html( $mailster_field_name ) . '</option>'; 69 73 } 70 74 echo '</optgroup>'; 71 echo '<optgroup label="' . esc_ html__( 'List specific', 'mailster-gravityforms' ) . '">';72 echo '<option value="_list" ' . selected( '_list', @$mailster['map'][ $input['id'] . '' ], false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>';75 echo '<optgroup label="' . esc_attr__( 'List specific', 'mailster-gravityforms' ) . '">'; 76 echo '<option value="_list" ' . selected( '_list', $mailster_mapped_input, false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>'; 73 77 echo '</optgroup>'; 74 78 echo '</select></li>'; … … 78 82 79 83 } else { 80 echo '<li> <label><strong>' . $field['label'] . '</strong></label> ➨ <select name="mailster[map][' . $field['id'] . ']">'; 84 $mailster_mapped_field = isset( $mailster['map'][ $mailster_field['id'] . '' ] ) ? $mailster['map'][ $mailster_field['id'] . '' ] : ''; 85 echo '<li> <label><strong>' . esc_html( $mailster_field['label'] ) . '</strong></label> ➨ <select name="mailster[map][' . esc_attr( $mailster_field['id'] ) . ']">'; 81 86 echo '<option value="-1">' . esc_html__( 'not mapped', 'mailster-gravityforms' ) . '</option>'; 82 echo '<optgroup label="' . esc_ html__( 'Fields', 'mailster-gravityforms' ) . '">';83 foreach ( $ fields as $id => $name ) {84 echo '<option value="' . $id . '" ' . selected( $id, @$mailster['map'][ $field['id'] . '' ], false ) . '>' . $name. '</option>';87 echo '<optgroup label="' . esc_attr__( 'Fields', 'mailster-gravityforms' ) . '">'; 88 foreach ( $mailster_fields as $mailster_field_key => $mailster_field_name ) { 89 echo '<option value="' . esc_attr( $mailster_field_key ) . '" ' . selected( $mailster_field_key, $mailster_mapped_field, false ) . '>' . esc_html( $mailster_field_name ) . '</option>'; 85 90 } 86 91 echo '</optgroup>'; 87 echo '<optgroup label="' . esc_ html__( 'List specific', 'mailster-gravityforms' ) . '">';88 echo '<option value="_list" ' . selected( '_list', @$mailster['map'][ $field['id'] . '' ], false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>';92 echo '<optgroup label="' . esc_attr__( 'List specific', 'mailster-gravityforms' ) . '">'; 93 echo '<option value="_list" ' . selected( '_list', $mailster_mapped_field, false ) . '>' . esc_html__( 'Add to List if checked or not empty', 'mailster-gravityforms' ) . '</option>'; 89 94 echo '</optgroup>'; 90 95 echo '</select></li>'; … … 104 109 <td> 105 110 <?php 106 $ selected= isset( $mailster['lists'] ) ? $mailster['lists'] : array();107 mailster( 'lists' )->print_it( null, null, $name = 'mailster[lists]', false, $selected);111 $mailster_selected_lists = isset( $mailster['lists'] ) ? $mailster['lists'] : array(); 112 mailster( 'lists' )->print_it( null, null, 'mailster[lists]', false, $mailster_selected_lists ); 108 113 ?> 109 114 </td> … … 121 126 <p><?php esc_html_e( 'subscribe user only if', 'mailster-gravityforms' ); ?> 122 127 <?php 123 if ( is_array( $ form['fields'] ) ) {128 if ( is_array( $mailster_form['fields'] ) ) { 124 129 echo '<select name="mailster[conditional_field]"><option value="-1">-</option>'; 125 foreach ( $ form['fields'] as $field ) {126 if ( ! in_array( $ field['type'], array( 'checkbox', 'radio' )) ) {130 foreach ( $mailster_form['fields'] as $mailster_field ) { 131 if ( ! in_array( $mailster_field['type'], array( 'checkbox', 'radio' ), true ) ) { 127 132 continue; 128 133 } 129 134 130 if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { 131 echo '<optgroup label="' . ( $field['label'] ? $field['label'] : esc_html__( 'Checkbox', 'mailster-gravityforms' ) ) . '">'; 132 foreach ( $field['inputs'] as $input ) { 133 echo '<option value="' . $input['id'] . '" ' . selected( $input['id'], $mailster['conditional_field'], false ) . '>' . $input['label'] . '</option>'; } 135 if ( isset( $mailster_field['inputs'] ) && is_array( $mailster_field['inputs'] ) ) { 136 $mailster_group_label = $mailster_field['label'] ? $mailster_field['label'] : __( 'Checkbox', 'mailster-gravityforms' ); 137 echo '<optgroup label="' . esc_attr( $mailster_group_label ) . '">'; 138 foreach ( $mailster_field['inputs'] as $mailster_input ) { 139 echo '<option value="' . esc_attr( $mailster_input['id'] ) . '" ' . selected( $mailster_input['id'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_input['label'] ) . '</option>'; 140 } 134 141 echo '</optgroup>'; 135 142 136 } elseif ( isset( $field['choices'] ) && is_array( $field['choices'] ) ) { 137 echo '<optgroup label="' . $field['label'] . '">'; 138 foreach ( $field['choices'] as $input ) { 139 echo '<option value="' . $field['id'] . '|' . $input['value'] . '" ' . selected( $input['value'], $mailster['conditional_field'], false ) . '>' . $input['text'] . '</option>'; } 143 } elseif ( isset( $mailster_field['choices'] ) && is_array( $mailster_field['choices'] ) ) { 144 echo '<optgroup label="' . esc_attr( $mailster_field['label'] ) . '">'; 145 foreach ( $mailster_field['choices'] as $mailster_input ) { 146 echo '<option value="' . esc_attr( $mailster_field['id'] . '|' . $mailster_input['value'] ) . '" ' . selected( $mailster_input['value'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_input['text'] ) . '</option>'; 147 } 140 148 echo '</optgroup>'; 141 149 142 150 } else { 143 echo '<option value="' . $field['id'] . '" ' . selected( $input['id'], $mailster['conditional_field'], false ) . '>sss' . $field['label']. '</option>';151 echo '<option value="' . esc_attr( $mailster_field['id'] ) . '" ' . selected( $mailster_field['id'], $mailster['conditional_field'], false ) . '>' . esc_html( $mailster_field['label'] ) . '</option>'; 144 152 } 145 153 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)