Plugin Directory

Changeset 3754846


Ignore:
Timestamp:
10/19/2026 01:39:29 PM (3 weeks ago)
Author:
everpress
Message:

Update to version 2.1.0 from GitHub

Location:
mailster-gravity-forms
Files:
2 added
2 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • mailster-gravity-forms/tags/2.1.0/assets/style.css

    r2676638 r3754846  
    22        border-bottom: 1px solid #ccc;
    33}
     4
    45#mailster-map li label {
    56        display: inline-block;
    67        width: 150px;
    78}
     9
    810#mailster-map li label select {
    911        display: inline-block;
    1012        width: 200px;
    1113}
     14
    1215#mailster-map li ul li {
    1316        border-bottom: 0;
    1417        padding-left: 20px;
    1518}
     19
    1620.gform-icon--mailster {
    1721        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>');
    … …  
    2125        width: 26px;
    2226}
     27
     28/* Gravity Forms renders this settings tab id. */
     29/* stylelint-disable-next-line selector-id-pattern */
    2330#tab_mailster .gform-settings-panel__content select {
    2431        width: auto;
  • mailster-gravity-forms/tags/2.1.0/classes/gravity.class.php

    r2676638 r3754846  
    11<?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 */
    313class MailsterGravitiyForm {
    414
     15        /**
     16         * Absolute filesystem path of this plugin.
     17         *
     18         * @since 1.0
     19         *
     20         * @var string
     21         */
    522        private $plugin_path;
     23
     24        /**
     25         * Base URL of this plugin.
     26         *
     27         * @since 1.0
     28         *
     29         * @var string
     30         */
    631        private $plugin_url;
    732
     33        /**
     34         * Registers lifecycle hooks and loads the text domain.
     35         *
     36         * @since 1.0
     37         *
     38         * @return void
     39         */
    840        public function __construct() {
    941
    … …  
    1749
    1850                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         */
    2261        public function activate( $network_wide ) {}
    2362
     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         */
    2471        public function deactivate( $network_wide ) {}
    2572
     73        /**
     74         * Registers Gravity Forms hooks for submissions and form settings.
     75         *
     76         * @since 1.0
     77         *
     78         * @return void
     79         */
    2680        public function init() {
    2781
    … …  
    3084                if ( is_admin() ) {
    3185
    32                         add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ), 10, 2 );
     86                        add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) );
    3387                        add_action( 'gform_form_settings_page_mailster', array( &$this, 'settings_page' ) );
    3488
    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         */
    41104        public function after_submission( $entry, $form ) {
    42105
    … …  
    62125                        if ( isset( $form['mailster']['conditional_id'] ) ) {
    63126
    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 ] ) ) {
    68132                                        return;
    69133                                }
    … …  
    85149
    86150                foreach ( $form['mailster']['map'] as $field_id => $key ) {
    87                         if ( '_list' == $key ) {
     151                        if ( '_list' === $key ) {
    88152                                $listname = $entry[ $field_id ];
    89153                                if ( empty( $listname ) ) {
    … …  
    96160                                        $list_ids[] = $list_id;
    97161                                }
    98                         } elseif ( $key != -1 ) {
     162                        } elseif ( '-1' !== (string) $key ) {
    99163                                $userdata[ $key ] = $entry[ $field_id ];
    100164                        }
    … …  
    105169                }
    106170
    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;
    108175                        $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 );
    110182                } else {
    111183                        $userdata['status']      = isset( $form['mailster']['double-opt-in'] ) ? 0 : 1;
    112184                        $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                }
    118187
    119188                if ( ! is_wp_error( $subscriber_id ) ) {
    120189                        mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_ids, false, $userdata['status'] ? true : false );
    121190                }
    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         */
    125200        public function settings_page() {
    126201
    … …  
    132207        }
    133208
    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 ) {
    135218
    136219                wp_enqueue_style( 'mailster-gravityforms-style', $this->plugin_url . 'assets/style.css', array(), MAILSTER_GRAVITYFORMS_VERSION );
    … …  
    144227        }
    145228
     229        /**
     230         * Saves the posted Mailster settings onto the current Gravity Form.
     231         *
     232         * @since 1.0
     233         *
     234         * @return void
     235         */
    146236        public function save() {
    147237
    148238                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;
    155248                if ( ! $form_id ) {
    156                         return; }
     249                        return;
     250                }
    157251
    158252                $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 );
    164273
    165274                if ( count( $conditional ) > 1 ) {
    … …  
    170279
    171280                RGFormsModel::update_form_meta( $form_id, $form );
    172 
    173281        }
    174282}
  • mailster-gravity-forms/tags/2.1.0/mailster-gravity-forms.php

    r3093222 r3754846  
    11<?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 */
    1315
    14 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.0.0' );
     16define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.1.0' );
    1517define( 'MAILSTER_GRAVITYFORMS_REQUIRED_VERSION', '4.0' );
    1618define( 'MAILSTER_GRAVITYFORMS_FILE', __FILE__ );
  • mailster-gravity-forms/tags/2.1.0/views/page.php

    r3093222 r3754846  
    11<?php
     2/**
     3 * Mailster settings panel for a Gravity Form.
     4 *
     5 * @package Mailster_Gravity_Forms
     6 */
    27
    38if ( ! function_exists( 'mailster' ) ) {
    … …  
    813}
    914
    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(
    1318        'lists'             => array(),
    1419        'map'               => array(),
    … …  
    3944                                </p>
    4045                                <?php
    41                                 $fields = array(
     46                                $mailster_fields = array(
    4247                                        'email'     => mailster_text( 'email' ),
    4348                                        'firstname' => mailster_text( 'firstname' ),
    … …  
    4550                                );
    4651
    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'];
    5056                                        }
    5157                                }
    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                                 }
    5658
    57                                 if ( is_array( $form['fields'] ) && ! empty( $form['fields'] ) ) {
     59                                if ( is_array( $mailster_form['fields'] ) && ! empty( $mailster_form['fields'] ) ) {
    5860                                        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>';
    6265
    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'] ) . ']" >';
    6569                                                                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>';
    6973                                                                }
    7074                                                                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>';
    7377                                                                echo '</optgroup>';
    7478                                                                echo '</select></li>';
    … …  
    7882
    7983                                                } 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'] ) . ']">';
    8186                                                        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>';
    8590                                                        }
    8691                                                        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>';
    8994                                                        echo '</optgroup>';
    9095                                                        echo '</select></li>';
    … …  
    104109                                <td>
    105110                                <?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 );
    108113                                ?>
    109114                                </td>
    … …  
    121126                                <p><?php esc_html_e( 'subscribe user only if', 'mailster-gravityforms' ); ?>
    122127                                <?php
    123                                 if ( is_array( $form['fields'] ) ) {
     128                                if ( is_array( $mailster_form['fields'] ) ) {
    124129                                        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 ) ) {
    127132                                                        continue;
    128133                                                }
    129134
    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                                                        }
    134141                                                        echo '</optgroup>';
    135142
    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                                                        }
    140148                                                        echo '</optgroup>';
    141149
    142150                                                } 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>';
    144152                                                }
    145153                                        }
  • mailster-gravity-forms/trunk/assets/style.css

    r2676638 r3754846  
    22        border-bottom: 1px solid #ccc;
    33}
     4
    45#mailster-map li label {
    56        display: inline-block;
    67        width: 150px;
    78}
     9
    810#mailster-map li label select {
    911        display: inline-block;
    1012        width: 200px;
    1113}
     14
    1215#mailster-map li ul li {
    1316        border-bottom: 0;
    1417        padding-left: 20px;
    1518}
     19
    1620.gform-icon--mailster {
    1721        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>');
    … …  
    2125        width: 26px;
    2226}
     27
     28/* Gravity Forms renders this settings tab id. */
     29/* stylelint-disable-next-line selector-id-pattern */
    2330#tab_mailster .gform-settings-panel__content select {
    2431        width: auto;
  • mailster-gravity-forms/trunk/classes/gravity.class.php

    r2676638 r3754846  
    11<?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 */
    313class MailsterGravitiyForm {
    414
     15        /**
     16         * Absolute filesystem path of this plugin.
     17         *
     18         * @since 1.0
     19         *
     20         * @var string
     21         */
    522        private $plugin_path;
     23
     24        /**
     25         * Base URL of this plugin.
     26         *
     27         * @since 1.0
     28         *
     29         * @var string
     30         */
    631        private $plugin_url;
    732
     33        /**
     34         * Registers lifecycle hooks and loads the text domain.
     35         *
     36         * @since 1.0
     37         *
     38         * @return void
     39         */
    840        public function __construct() {
    941
    … …  
    1749
    1850                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         */
    2261        public function activate( $network_wide ) {}
    2362
     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         */
    2471        public function deactivate( $network_wide ) {}
    2572
     73        /**
     74         * Registers Gravity Forms hooks for submissions and form settings.
     75         *
     76         * @since 1.0
     77         *
     78         * @return void
     79         */
    2680        public function init() {
    2781
    … …  
    3084                if ( is_admin() ) {
    3185
    32                         add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ), 10, 2 );
     86                        add_filter( 'gform_form_settings_menu', array( &$this, 'settings_menu' ) );
    3387                        add_action( 'gform_form_settings_page_mailster', array( &$this, 'settings_page' ) );
    3488
    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         */
    41104        public function after_submission( $entry, $form ) {
    42105
    … …  
    62125                        if ( isset( $form['mailster']['conditional_id'] ) ) {
    63126
    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 ] ) ) {
    68132                                        return;
    69133                                }
    … …  
    85149
    86150                foreach ( $form['mailster']['map'] as $field_id => $key ) {
    87                         if ( '_list' == $key ) {
     151                        if ( '_list' === $key ) {
    88152                                $listname = $entry[ $field_id ];
    89153                                if ( empty( $listname ) ) {
    … …  
    96160                                        $list_ids[] = $list_id;
    97161                                }
    98                         } elseif ( $key != -1 ) {
     162                        } elseif ( '-1' !== (string) $key ) {
    99163                                $userdata[ $key ] = $entry[ $field_id ];
    100164                        }
    … …  
    105169                }
    106170
    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;
    108175                        $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 );
    110182                } else {
    111183                        $userdata['status']      = isset( $form['mailster']['double-opt-in'] ) ? 0 : 1;
    112184                        $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                }
    118187
    119188                if ( ! is_wp_error( $subscriber_id ) ) {
    120189                        mailster( 'subscribers' )->assign_lists( $subscriber_id, $list_ids, false, $userdata['status'] ? true : false );
    121190                }
    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         */
    125200        public function settings_page() {
    126201
    … …  
    132207        }
    133208
    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 ) {
    135218
    136219                wp_enqueue_style( 'mailster-gravityforms-style', $this->plugin_url . 'assets/style.css', array(), MAILSTER_GRAVITYFORMS_VERSION );
    … …  
    144227        }
    145228
     229        /**
     230         * Saves the posted Mailster settings onto the current Gravity Form.
     231         *
     232         * @since 1.0
     233         *
     234         * @return void
     235         */
    146236        public function save() {
    147237
    148238                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;
    155248                if ( ! $form_id ) {
    156                         return; }
     249                        return;
     250                }
    157251
    158252                $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 );
    164273
    165274                if ( count( $conditional ) > 1 ) {
    … …  
    170279
    171280                RGFormsModel::update_form_meta( $form_id, $form );
    172 
    173281        }
    174282}
  • mailster-gravity-forms/trunk/mailster-gravity-forms.php

    r3093222 r3754846  
    11<?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 */
    1315
    14 define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.0.0' );
     16define( 'MAILSTER_GRAVITYFORMS_VERSION', '2.1.0' );
    1517define( 'MAILSTER_GRAVITYFORMS_REQUIRED_VERSION', '4.0' );
    1618define( 'MAILSTER_GRAVITYFORMS_FILE', __FILE__ );
  • mailster-gravity-forms/trunk/views/page.php

    r3093222 r3754846  
    11<?php
     2/**
     3 * Mailster settings panel for a Gravity Form.
     4 *
     5 * @package Mailster_Gravity_Forms
     6 */
    27
    38if ( ! function_exists( 'mailster' ) ) {
    … …  
    813}
    914
    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(
    1318        'lists'             => array(),
    1419        'map'               => array(),
    … …  
    3944                                </p>
    4045                                <?php
    41                                 $fields = array(
     46                                $mailster_fields = array(
    4247                                        'email'     => mailster_text( 'email' ),
    4348                                        'firstname' => mailster_text( 'firstname' ),
    … …  
    4550                                );
    4651
    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'];
    5056                                        }
    5157                                }
    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                                 }
    5658
    57                                 if ( is_array( $form['fields'] ) && ! empty( $form['fields'] ) ) {
     59                                if ( is_array( $mailster_form['fields'] ) && ! empty( $mailster_form['fields'] ) ) {
    5860                                        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>';
    6265
    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'] ) . ']" >';
    6569                                                                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>';
    6973                                                                }
    7074                                                                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>';
    7377                                                                echo '</optgroup>';
    7478                                                                echo '</select></li>';
    … …  
    7882
    7983                                                } 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'] ) . ']">';
    8186                                                        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>';
    8590                                                        }
    8691                                                        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>';
    8994                                                        echo '</optgroup>';
    9095                                                        echo '</select></li>';
    … …  
    104109                                <td>
    105110                                <?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 );
    108113                                ?>
    109114                                </td>
    … …  
    121126                                <p><?php esc_html_e( 'subscribe user only if', 'mailster-gravityforms' ); ?>
    122127                                <?php
    123                                 if ( is_array( $form['fields'] ) ) {
     128                                if ( is_array( $mailster_form['fields'] ) ) {
    124129                                        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 ) ) {
    127132                                                        continue;
    128133                                                }
    129134
    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                                                        }
    134141                                                        echo '</optgroup>';
    135142
    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                                                        }
    140148                                                        echo '</optgroup>';
    141149
    142150                                                } 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>';
    144152                                                }
    145153                                        }
Note: See TracChangeset for help on using the changeset viewer.