Plugin Directory

Changeset 2129855


Ignore:
Timestamp:
07/28/2019 08:36:38 PM (7 years ago)
Author:
xcoobee
Message:

version 1.2.1
support xcoobee consent registration

Location:
xcoobee-form/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • xcoobee-form/trunk/CHANGELOG

    r2055947 r2129855  
    11== Changelog ==
     2
     3= 1.2.1 - 2019-07-29 =
     4* fix bugs with Contact form 7 and XcooBee consent registration
     5
     6= 1.2.0 - 2019-07-21 =
     7* Add Contact Form 7 Support.
    28
    39= 1.0.0 - 2019-03-22 =
  • xcoobee-form/trunk/includes/admin/views/settings-form.php

    r2107044 r2129855  
    4747        <nav class="tabs-nav">
    4848            <a class="nav active" data-nav="xcoobee-form"><code>[xcoobee_form]</code><span><?php _e( 'Renders a safe form button.', 'xcoobee' ); ?></span></a>
     49            <a class="nav" data-nav="xcoobee_save_consent"><code>[xcoobee_save_consent]</code><span><?php _e( 'This shortcode can be embedded in Contact Form 7. It will register corresponding consent for using of data with XcooBee. Users can then manage consent directly.', 'xcoobee' ); ?></span></a>
    4950        </nav>
    5051        <div class="tabs-content">
     
    116117                    </tbody>
    117118                </table>
    118                 <div class="example" id="shortcode-example-xcoobee-form"><span class="xbee-copy-text xbee-tooltip" data-tooltip="<?php _e('Copy', 'xcoobee'); ?>" data-copy="shortcode-example-xcoobee-form"></span><span class="headline"><?php _e( 'Example', 'xcoobee' ); ?></span><code>[xcoobee_form campaign_reference=&quot;xxx.xxxxxxxxxxx&quot; button_size=&quot;medium&quot; approve_redirect=&quot;https://example.com/thank-you/&quot; decline_redirect=&quot;https://example.com/oops/&quot; text=&quot;Use Safe Form&quot; alt_text=&quot;Use the XcooBee secure network!&quot; class=&quot;my-safe-form&quot; id=&quot;xbee-safe-form&quot;][/xcoobee_form]</code></div>
     119                <div class="example">
     120                    <span class="xbee-copy-text xbee-tooltip" data-clipboard-target="#xcoobee_form_all_attrs" data-tooltip="<?php esc_attr_e('Copy', 'xcoobee'); ?>"></span>
     121                    <span class="headline"><?php _e( 'XcooBee Form Example', 'xcoobee' ); ?></span>
     122                    <code id="xcoobee_form_all_attrs">[xcoobee_form campaign_reference=&quot;xxx.xxxxxxxxxxx&quot; button_size=&quot;medium&quot; approve_redirect=&quot;https://example.com/thank-you/&quot; decline_redirect=&quot;https://example.com/oops/&quot; text=&quot;Use Safe Form&quot; alt_text=&quot;Use the XcooBee secure network!&quot; class=&quot;my-safe-form&quot; id=&quot;xbee-safe-form&quot;][/xcoobee_form]</code>
     123                </div>
     124            </div>
     125            <div class="content" data-nav="xcoobee_save_consent">
     126                <table class="shortcode-info">
     127                    <thead>
     128                        <tr>
     129                            <th><?php _e( 'Attribute', 'xcoobee' ); ?></th>
     130                            <th><?php _e( 'Description', 'xcoobee' ); ?></th>
     131                            <th><?php _e( 'Default', 'xcoobee' ); ?></th>
     132                            <th><?php _e( 'Example', 'xcoobee' ); ?></th>
     133                        </tr>
     134                    </thead>
     135                    <tbody>
     136                        <tr>
     137                            <td><code>campaign_reference</code></td>
     138                            <td><?php _e( 'This is the XcooBee Campaign Reference. You can get this from your XcooBee campaign wizard screen.', 'xcoobee' ); ?></td>
     139                            <td>Default Campaign Reference</td>
     140                            <td><code>xxx.xxxxxxxxxx</code></td>
     141                        </tr>
     142                        <tr>
     143                            <td><code>xcoobee_id_field</code></td>
     144                            <td><?php _e( "This should be the name or ID of the form field of the form's field that contains the user's XcooBee ID. If both an email and XcooBee ID are present, we will process using XcooBee ID first.", 'xcoobee' ); ?></td>
     145                            <td>xcoobee_id</td>
     146                            <td><code>your-xcoobeeid</code></td>
     147                        </tr>
     148                        <tr>
     149                            <td><code>email_field</code></td>
     150                            <td><?php _e( "This should be the name or ID of the form field of the form's field that contains the user's email.", 'xcoobee' ); ?></td>
     151                            <td>email</td>
     152                            <td><code>your-email</code></td>
     153                        </tr>
     154                    </tbody>
     155                </table>
     156                <div class="example">
     157                    <span class="xbee-copy-text xbee-tooltip" data-clipboard-target="#xcoobee_save_consent_all_defaults" data-tooltip="<?php esc_attr_e('Copy', 'xcoobee'); ?>"></span>
     158                    <span class="headline"><?php _e( 'XcooBee Save Consent', 'xcoobee' ); ?></span>
     159                    <code id="xcoobee_save_consent_all_defaults">[xcoobee_save_consent]</code>
     160                </div>
     161                <div class="example">
     162                    <span class="xbee-copy-text xbee-tooltip" data-clipboard-target="#xcoobee_save_consent_no_defaults" data-tooltip="<?php esc_attr_e('Copy', 'xcoobee'); ?>"></span>
     163                    <span class="headline"><?php _e( 'XcooBee Save Consent', 'xcoobee' ); ?></span>
     164                    <code id="xcoobee_save_consent_no_defaults">[xcoobee_save_consent campaign_reference=&quot;xxx.xxxxxxxxxx&quot; xcoobee_id_field=&quot;xcoobeeid-field&quot; email_field=&quot;email-field&quot;]</code>
     165                </div>
    119166            </div>
    120167        </div>
     
    124171
    125172<p class="actions"><?php submit_button( 'Save Changes', 'primary', 'submit', false ); ?></p>
     173
     174<script>
     175    (function ($) {
     176        $(document).ready(function ($) {
     177            new ClipboardJS('.xbee-copy-text');
     178        });
     179    })(jQuery);
     180</script>
     181
     182<?php
     183unset( $default_campaign_reference );
  • xcoobee-form/trunk/languages/xcoobee-form.pot

    r2107044 r2129855  
    5050msgstr ""
    5151
    52 #: includes/admin/views/settings-form.php:55
     52#: includes/admin/views/settings-form.php:49
     53msgid "This shortcode can be embedded in Contact Form 7. It will register corresponding consent for using of data with XcooBee. Users can then manage consent directly."
     54msgstr ""
     55
     56#: includes/admin/views/settings-form.php:56, includes/admin/views/settings-form.php:129
    5357msgid "Attribute"
    5458msgstr ""
    5559
    56 #: includes/admin/views/settings-form.php:56
     60#: includes/admin/views/settings-form.php:57, includes/admin/views/settings-form.php:130
    5761msgid "Description"
    5862msgstr ""
    5963
    60 #: includes/admin/views/settings-form.php:57
     64#: includes/admin/views/settings-form.php:58, includes/admin/views/settings-form.php:131
    6165msgid "Default"
    6266msgstr ""
    6367
    64 #: includes/admin/views/settings-form.php:58, includes/admin/views/settings-form.php:118
     68#: includes/admin/views/settings-form.php:59, includes/admin/views/settings-form.php:132
    6569msgid "Example"
    6670msgstr ""
    6771
    68 #: includes/admin/views/settings-form.php:64
     72#: includes/admin/views/settings-form.php:65
    6973msgid "Campaign reference."
    7074msgstr ""
    7175
    72 #: includes/admin/views/settings-form.php:70
     76#: includes/admin/views/settings-form.php:71
    7377msgid "Size of the button (<code>small</code>, <code>medium</code> or <code>large</code>)."
    7478msgstr ""
    7579
    76 #: includes/admin/views/settings-form.php:76
     80#: includes/admin/views/settings-form.php:77
    7781msgid "URL to redirect to when request is approved."
    7882msgstr ""
    7983
    80 #: includes/admin/views/settings-form.php:82
     84#: includes/admin/views/settings-form.php:83
    8185msgid "URL to redirect to when request is declined."
    8286msgstr ""
    8387
    84 #: includes/admin/views/settings-form.php:88
     88#: includes/admin/views/settings-form.php:89
    8589msgid "The <code>id</code> of the form. Leave this empty if the shortcode is placed inside the form."
    8690msgstr ""
    8791
    88 #: includes/admin/views/settings-form.php:94
     92#: includes/admin/views/settings-form.php:95
    8993msgid "Alternate text for the button."
    9094msgstr ""
    9195
    92 #: includes/admin/views/settings-form.php:95, includes/class-xcoobee-form-shortcodes.php:43
     96#: includes/admin/views/settings-form.php:96, includes/class-xcoobee-form-shortcodes.php:43
    9397msgid "Safe Form"
    9498msgstr ""
    9599
    96 #: includes/admin/views/settings-form.php:96, includes/admin/views/settings-form.php:102
     100#: includes/admin/views/settings-form.php:97, includes/admin/views/settings-form.php:103
    97101msgid "Your text"
    98102msgstr ""
    99103
    100 #: includes/admin/views/settings-form.php:100
     104#: includes/admin/views/settings-form.php:101
    101105msgid "Alternate text for the button on hover."
    102106msgstr ""
    103107
    104 #: includes/admin/views/settings-form.php:101
     108#: includes/admin/views/settings-form.php:102
    105109msgid "Submit data securley via XcooBee!"
    106110msgstr ""
    107111
    108 #: includes/admin/views/settings-form.php:106
     112#: includes/admin/views/settings-form.php:107
    109113msgid "Additional CSS classes to button."
    110114msgstr ""
    111115
    112 #: includes/admin/views/settings-form.php:112
     116#: includes/admin/views/settings-form.php:113
    113117msgid "Custom HTML Id for the button."
    114118msgstr ""
    115119
    116 #: includes/admin/views/settings-form.php:118
     120#: includes/admin/views/settings-form.php:120, includes/admin/views/settings-form.php:157, includes/admin/views/settings-form.php:162
    117121msgid "Copy"
     122msgstr ""
     123
     124#: includes/admin/views/settings-form.php:121
     125msgid "XcooBee Form Example"
     126msgstr ""
     127
     128#: includes/admin/views/settings-form.php:138
     129msgid "This is the XcooBee Campaign Reference. You can get this from your XcooBee campaign wizard screen."
     130msgstr ""
     131
     132#: includes/admin/views/settings-form.php:144
     133msgid "This should be the name or ID of the form field of the form's field that contains the user's XcooBee ID. If both an email and XcooBee ID are present, we will process using XcooBee ID first."
     134msgstr ""
     135
     136#: includes/admin/views/settings-form.php:150
     137msgid "This should be the name or ID of the form field of the form's field that contains the user's email."
     138msgstr ""
     139
     140#: includes/admin/views/settings-form.php:158, includes/admin/views/settings-form.php:163
     141msgid "XcooBee Save Consent"
    118142msgstr ""
    119143
     
    122146msgstr ""
    123147
    124 #: xcoobee-form.php:99
     148#: xcoobee-form.php:102
    125149msgid "XcooBee Form requires XcooBee for WordPress to be installed and active. You can download %s here."
    126150msgstr ""
    127151
    128 #: xcoobee-form.php:143
     152#: xcoobee-form.php:250
    129153msgid "View XcooBee Form settings"
    130154msgstr ""
    131155
    132 #: xcoobee-form.php:143
     156#: xcoobee-form.php:250
    133157msgid "Settings"
    134158msgstr ""
  • xcoobee-form/trunk/readme.txt

    r2107044 r2129855  
    33Tags: xcoobee, privacy, consent, ccpa, gdpr, security, form
    44Requires at least: 4.4.0
    5 Tested up to: 5.2.1
    6 Stable tag: 1.1.1
     5Tested up to: 5.2.2
     6Stable tag: 1.2.1
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
  • xcoobee-form/trunk/xcoobee-form.php

    r2107044 r2129855  
    55 * Author URI:  https://www.xcoobee.com/
    66 * Description: Ask user for Data and Consent in GDPR compliant manner. Safely transfer the collected information to backend.
    7  * Version:     1.1.1
     7 * Version:     1.2.1
    88 * Author:      XcooBee
    99 * License:     GPLv3
     
    1414 *
    1515 * Requires at least: 4.4.0
    16  * Tested up to: 5.2.1
     16 * Tested up to: 5.2.2
    1717 *
    1818 * @package XcooBee/Form
     
    3737 */
    3838class XcooBee_Form {
     39    private static $default_email_field = 'email';
     40    private static $default_xcoobee_id_field = 'xcoobee_id';
     41
    3942    /**
    4043     * The singleton instance of XcooBee_Form.
     
    105108     * @since 1.0.0
    106109     */
    107     public function includes() {
     110    private function includes() {
    108111        // Global includes.
    109112        include_once XBEE_FORM_ABSPATH . 'includes/functions.php';
    110113        include_once XBEE_FORM_ABSPATH . 'includes/class-xcoobee-form-shortcodes.php';
     114        include_once XBEE_FORM_ABSPATH . 'includes/class-xcoobee-save-consent-shortcodes.php';
    111115
    112116        // Back-end includes.
     
    114118            include_once XBEE_FORM_ABSPATH . 'includes/admin/class-xcoobee-form-admin.php';
    115119        }
    116        
     120
    117121        // Front-end includes.
    118122        if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
     
    126130     * @since 1.0.0
    127131     */
    128     public function hooks() {
     132    private function hooks() {
    129133        add_filter( 'plugin_action_links_' . XBEE_FORM_PLUGIN_BASENAME, [ $this, 'action_links' ], 10, 1 );
    130134        add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] );
     
    132136        add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );
    133137        add_action( 'wp_enqueue_scripts', [ $this, 'styles' ] );
    134     }
     138
     139        // Allows processing of our shortcodes in CF7. Without it, the embedded shortcode remains as text in the HTML.
     140        add_filter( 'wpcf7_form_elements', 'do_shortcode' );
     141        add_action( 'wpcf7_submit', [ $this, 'handle_cf7_submit' ], 10, 2 );
     142        // add_action( 'wpcf7_validate', [ $this, 'handle_cf7_validate' ], 10, 2 ); // TODO: Revisit.
     143
     144        // Uncomment the following to test the CF7 form when the CF7 JavaScript has been disabled.
     145        // That is, the form submission will do a regular form submission as opposed to using AJAX.
     146        // add_filter( 'wpcf7_load_js', '__return_false' );
     147    }
     148
     149    /**
     150     * @since 1.2.0
     151     *
     152     * @param WPCF7_ContactForm $cf7form
     153     * @param Array $result
     154     * @param number $result['contact_form_id']
     155     * @param string $result['message']
     156     * @param string $result['status']
     157     * @param string [$result['invalid_fields']]
     158     */
     159    public function handle_cf7_submit( $cf7form, $result ) {
     160        // error_log('XcooBee_Form->handle_cf7_submit');
     161        // error_log(print_r($_POST, true));
     162        // error_log(print_r($result, true));
     163
     164        if ( $cf7form->in_demo_mode() ) {
     165            return;
     166        }
     167
     168        // $status may be: aborted, acceptance_missing, error, init, mail_failed, mail_sent, spam, validation_failed
     169        $status = $result['status'];
     170        if ( $status === 'mail_sent' || $status === 'mail_failed' || $status === 'init' ) {
     171            $targets = [];
     172            $xbee_action = isset( $_POST['xbee__action'] ) ? $_POST['xbee__action'] : '';
     173            if ( 'save_consent' === $xbee_action ) {
     174                $campaign_reference = isset( $_POST['xbee__campaign_reference'] ) ? $_POST['xbee__campaign_reference'] : '';
     175                if ( empty( $campaign_reference ) ) {
     176                    $default_campaign_reference = get_option( 'xbee_form_default_campaign_reference', '' );
     177                    $campaign_reference = $default_campaign_reference;
     178                }
     179
     180                // error_log('$campaign_reference:' . print_r($campaign_reference, true));
     181
     182                if ( ! empty( $campaign_reference) ) {
     183                    $xcoobee_id_field = isset( $_POST['xbee__xcoobee_id_field'] ) ? $_POST['xbee__xcoobee_id_field'] : '';
     184                    if ( empty( $xcoobee_id_field ) ) {
     185                        $xcoobee_id_field = $default_xcoobee_id_field;
     186                    }
     187                    $xcoobee_id = isset( $_POST[$xcoobee_id_field] ) ? $_POST[$xcoobee_id_field] : '';
     188                    // If appears to be a valid XcooBee ID, then ...
     189                    if ( ! empty( $xcoobee_id ) && xbee_validate_xid( $xcoobee_id ) ) {
     190                        $targets[] = array( 'target' => $xcoobee_id );
     191                    } else {
     192                        $email_field = isset( $_POST['xbee__email_field'] ) ? $_POST['xbee__email_field'] : '';
     193                        if ( empty( $email_field ) ) {
     194                            $email_field = $default_email_field;
     195                        }
     196                        $email = isset( $_POST[$email_field] ) ? $_POST[$email_field] : '';
     197                        if ( ! empty( $email ) ) {
     198                            $targets[] = array( 'target' => $email );
     199                        }
     200                    }
     201
     202                    if ( count( $targets ) > 0 ) {
     203                        $xcoobee = XcooBee::get_xcoobee();
     204                        $response = $xcoobee->consents->getCampaignIdByRef( $campaign_reference );
     205
     206                        // error_log('$response:' . print_r($response, true));
     207                        if ( 200 === $response->code ) {
     208                            $campaign_id = $response->result;
     209                            // error_log('$targets:' . print_r($targets, true));
     210                            // error_log('$campaign_id:' . print_r($campaign_id, true));
     211                            $response = $xcoobee->consents->registerConsents( null, $targets, null, $campaign_id );
     212                            if ( 200 !== $response->code || ! empty( $response->errors ) ) {
     213                                error_log( 'Failed to save consent. Error Code: ' . $response->code );
     214                                if ( ! empty( $response->errors ) ) {
     215                                    error_log( print_r( $response->errors, true ) );
     216                                }
     217                            }
     218                        } else {
     219                            error_log( 'Failed to save consent. Unable to get campaign using "' . $campaign_reference . '".' );
     220                        }
     221                    }
     222                } else {
     223                    error_log( 'No campaign reference set. Unable to save consent.' );
     224                }
     225            }
     226        }
     227    }
     228
     229    // /**
     230    //  * @since 1.2.0
     231    //  *
     232    //  * @param WPCF7_Validation $result
     233    //  * @param Array<WPCF7_FormTag>
     234    //  */
     235    // public function handle_cf7_validate( $result, $tags ) {
     236    //  error_log('XcooBee_Form->handle_cf7_validate');
     237    //  error_log(print_r($result, true));
     238    //  error_log(print_r($tags, true));
     239
     240    //  return $result;
     241    // }
    135242
    136243    /**
     
    155262        // Back-end scripts.
    156263        if ( 'admin_enqueue_scripts' === current_action() ) {
    157             wp_enqueue_script( 'xbee-form-admin-scripts', XBEE_FORM_DIR_URL . 'assets/dist/js/admin/scripts.min.js', [ 'jquery', 'xbee-admin-scripts' ], null, true );
     264            wp_enqueue_script( 'xbee-form-admin-scripts', XBEE_FORM_DIR_URL . 'assets/dist/js/admin/scripts.min.js', [ 'clipboard', 'jquery', 'xbee-admin-scripts' ], null, true );
    158265            wp_localize_script( 'xbee-form-admin-scripts', 'xbeeFormAdminParams', [
    159266                'ajaxURL' => admin_url( 'admin-ajax.php' ),
     
    211318        // Nothing to do for now.
    212319    }
    213    
     320
    214321    /**
    215322     * Deactivation hooks.
     
    234341    XcooBee_Form::get_instance();
    235342}
    236 
    237343add_action( 'plugins_loaded', 'init_xcoobee_form' );
    238344
Note: See TracChangeset for help on using the changeset viewer.