Commit 4f71b2d0 authored by KR Moorhouse's avatar KR Moorhouse

Updated settings page to remove telemetry checkbox and replace with...

Updated settings page to remove telemetry checkbox and replace with opt-in/opt-out buttons. Updated opt-out functionality to push the opt-out to api.
parent 7ef2874d
......@@ -178,4 +178,43 @@ jQuery(document).ready(function($) {
$( "#delete_on_uninstall" ).attr( 'checked', true );
} );
// If we're allowed to track site data...
if ( '1' == nf_settings.allow_telemetry ) {
// Show the optout button.
$( '#nfTelOptin' ).addClass( 'hidden' );
$( '#nfTelOptout' ).removeClass( 'hidden' );
} // Otherwise...
else {
// Show the optin button.
$( '#nfTelOptout' ).addClass( 'hidden' );
$( '#nfTelOptin' ).removeClass( 'hidden' );
}
// If optin is clicked...
$( '#nfTelOptin' ).click( function( e ) {
// Hide the button.
$( '#nfTelOptin' ).addClass( 'hidden' );
$( '#nfTelSpinner' ).css( 'display', 'inline-block' );
// Hit AJAX endpoint and opt-in.
$.post( ajaxurl, { action: 'nf_optin', ninja_forms_opt_in: 1 },
function( response ) {
$( '#nfTelOptout' ).removeClass( 'hidden' );
$( '#nfTelSpinner' ).css( 'display', 'none' );
} );
} );
// If optout is clicked...
$( '#nfTelOptout' ).click( function( e ) {
// Hide the button.
$( '#nfTelOptout' ).addClass( 'hidden' );
$( '#nfTelSpinner' ).css( 'display', 'inline-block' );
// Hit AJAX endpoint and opt-out.
$.post( ajaxurl, { action: 'nf_optin', ninja_forms_opt_in: 0 },
function( response ) {
$( '#nfTelOptin' ).removeClass( 'hidden' );
$( '#nfTelSpinner' ).css( 'display', 'none' );
} );
} );
});
......@@ -143,11 +143,18 @@ final class NF_Admin_Menus_Settings extends NF_Abstracts_Submenu
}
$form_options = apply_filters( 'ninja_forms_submission_filter_form_options', $form_options );
asort($form_options);
if ( get_option( 'ninja_forms_allow_tracking' ) && '1' == get_option( 'ninja_forms_allow_tracking' ) ) {
$allow_tel = 1;
} else {
$allow_tel = 0;
}
wp_enqueue_script( 'jBox', Ninja_Forms::$url . 'assets/js/lib/jBox.min.js', array( 'jquery' ) );
wp_enqueue_style( 'nf-combobox', Ninja_Forms::$url . 'assets/css/combobox.css' );
wp_enqueue_style( 'jBox', Ninja_Forms::$url . 'assets/css/jBox.css' );
wp_enqueue_style( 'nf-dashboard', Ninja_Forms::$url . 'assets/css/dashboard.min.css' );
wp_register_script( 'ninja_forms_admin_menu_settings', Ninja_Forms::$url . 'assets/js/admin-settings.js', array( 'jquery' ), FALSE, TRUE );
wp_localize_script( 'ninja_forms_admin_menu_settings', 'nf_settings', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
......@@ -156,7 +163,8 @@ final class NF_Admin_Menus_Settings extends NF_Abstracts_Submenu
'nonce' => wp_create_nonce( "ninja_forms_settings_nonce" ),
'i18n' => array(
'rollbackConfirm' => __( 'Are you sure you want to rollback?', 'ninja-forms' )
)
),
'allow_telemetry' => $allow_tel
));
......
......@@ -50,11 +50,19 @@ return apply_filters( 'ninja_forms_plugin_settings_advanced', array(
'allow_tracking' => array(
'id' => 'allow_tracking',
'type' => 'checkbox',
'label' => __( 'Allow Tracking', 'ninja-forms' ),
'desc' => __( 'If you opt-in, some data about your installation of Ninja Forms will be sent to NinjaForms.com (this does NOT include your submissions).', 'ninja-forms' )
'type' => 'html',
'html' => '<span id="nfTelOptin" class="button hidden">' . __( 'Opt-in', 'ninja-forms' ) . '</span><span id="nfTelOptout" class="button hidden">' . __( 'Opt-out', 'ninja-forms' ) . '</span><span id="nfTelSpinner" class="nf-loading-spinner" style="display:none;"></span>',
'label' => __( 'Allow Telemetry', 'ninja-forms' ),
'desc' => __( 'Opt-in to allow Ninja Forms to collect anonymous usage statistics from your site, such as PHP version, installed plugins, and other non-personally idetifiable informations.', 'ninja-forms' ),
),
// 'allow_tracking' => array(
// 'id' => 'allow_tracking',
// 'type' => 'checkbox',
// 'label' => __( 'Allow Tracking', 'ninja-forms' ),
// 'desc' => __( 'If you opt-in, some data about your installation of Ninja Forms will be sent to NinjaForms.com (this does NOT include your submissions).', 'ninja-forms' )
// ),
/*
|--------------------------------------------------------------------------
| Opinionated Styles
......
......@@ -184,6 +184,14 @@ final class NF_Tracking
// Clear dispatch debounce flag.
update_option( 'ninja_forms_optin_reported', 0 );
$data = array();
$user_email = get_option( 'ninja_forms_optin_email' );
if ( $user_email ) {
$data[ 'user_email' ] = $user_email;
}
Ninja_Forms()->dispatcher()->send( 'optout', $data );
delete_option( 'ninja_forms_optin_email' );
}
public function check_setting( $setting )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment