Commit e4db8624 authored by KR Moorhouse's avatar KR Moorhouse

Removed optin behavior from deprecated codebase in favor of showing optin...

Removed optin behavior from deprecated codebase in favor of showing optin dialogue after upgrade instead.
parent 8dc2b4a2
......@@ -61,8 +61,6 @@ class NF_THREE_Submenu
add_action( 'admin_menu', array( $this, 'register' ), $this->priority );
add_action( 'wp_ajax_ninja_forms_upgrade_check', array( $this, 'upgrade_check' ) );
add_action( 'wp_ajax_ninja_forms_optin', array( $this, 'optin' ) );
add_action( 'wp_ajax_ninja_forms_optout', array( $this, 'optout' ) );
add_filter( 'nf_general_settings_advanced', array( $this, 'settings_upgrade_button' ) );
}
......@@ -176,153 +174,6 @@ class NF_THREE_Submenu
{
include plugin_dir_path( __FILE__ ) . 'tmpl-settings-upgrade-button.html.php';
}
public function optin() {
if ( ! current_user_can( 'manage_options' ) ) return false;
$api_url = 'http://api.ninjaforms.com/';
/**
* Update our tracking option.
*/
update_option( 'ninja_forms_allow_tracking', true );
update_option( 'ninja_forms_do_not_allow_tracking', false );
/**
* Gather site data before we send.
*
* We send the following site data with our passed data:
* IP Address
* Email
* Site Url
*/
$ip_address = '';
if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
$ip_address = $_SERVER[ 'SERVER_ADDR' ];
} else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
$ip_address = $_SERVER[ 'LOCAL_ADDR' ];
}
/**
* Email address of the current user, defaulting to admin email if they do not have one.
*/
/*$current_user = wp_get_current_user();
if ( ! empty ( $current_user->user_email ) ) {
$email = $current_user->user_email;
} else {
$email = get_option( 'admin_email' );
} */
$email = $_REQUEST[ 'user_email' ];
$site_data = array(
'url' => site_url(),
'ip_address' => $ip_address,
'email' => $email,
);
/**
* Send our environment variables.
*/
global $wpdb;
// Plugins
$active_plugins = (array) get_option( 'active_plugins', array() );
//WP_DEBUG
if ( defined('WP_DEBUG') && WP_DEBUG ){
$debug = 1;
} else {
$debug = 0;
}
//WPLANG
if ( defined( 'WPLANG' ) && WPLANG ) {
$lang = WPLANG;
} else {
$lang = 'default';
}
$ip_address = '';
if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
$ip_address = $_SERVER[ 'SERVER_ADDR' ];
} else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
$ip_address = $_SERVER[ 'LOCAL_ADDR' ];
}
$host_name = gethostbyaddr( $ip_address );
if ( is_multisite() ) {
$multisite_enabled = 1;
} else {
$multisite_enabled = 0;
}
$tls = 'unknown';
$environment = array(
'nf_version' => NF_PLUGIN_VERSION,
'wp_version' => get_bloginfo('version'),
'multisite_enabled' => $multisite_enabled,
'server_type' => $_SERVER['SERVER_SOFTWARE'],
'tls_version' => $tls,
'php_version' => phpversion(),
'mysql_version' => $wpdb->db_version(),
'wp_memory_limit' => WP_MEMORY_LIMIT,
'wp_debug_mode' => $debug,
'wp_lang' => $lang,
'wp_max_upload_size' => size_format( wp_max_upload_size() ),
'php_max_post_size' => ini_get( 'post_max_size' ),
'hostname' => $host_name,
'smtp' => ini_get('SMTP'),
'smtp_port' => ini_get('smtp_port'),
'active_plugins' => $active_plugins,
);
/*
* Send our data using wp_remote_post.
*/
$response = wp_remote_post(
$api_url,
array(
'body' => array(
'slug' => 'update_environment_vars',
'data' => wp_json_encode( $environment ),
'site_data' => wp_json_encode( $site_data ),
),
)
);
$send_email = absint( $_REQUEST[ 'send_email' ] );
/*
* Send our opt-in event using wp_remote_post.
*/
$response = wp_remote_post(
$api_url,
array(
'body' => array(
'slug' => 'optin',
'data' => wp_json_encode( array( 'send_email' => $send_email ) ),
'site_data' => wp_json_encode( $site_data ),
),
)
);
die();
}
public function optout() {
if ( ! current_user_can( 'manage_options' ) ) return false;
/**
* Update our tracking option
*/
update_option( 'ninja_forms_do_not_allow_tracking', true );
die();
}
}
new NF_THREE_Submenu();
......@@ -171,37 +171,4 @@
<span id="optin-spinner" class="spinner"></span>
<button id="optin" class="button-primary" style="margin-bottom: 10px; font-size: 16px;">Yes, I want to make Ninja Forms better!</button> <button id="optout" class="button-secondary" style="margin-bottom: 10px;">No, please don't collect errors or other data.</button>
</div>
-->
<div style="display:none;">
<div id="optin-modal-title">
<h2 style="font-size:180%;">Help make Ninja Forms better!</h2>
</div>
</div>
<div id="optin-modal" style="display:none; padding:5px 15px;">
<p>
We would like to collect data about how Ninja Forms is used so that we can improve the experience for everyone. This data will not include ANY submission data or personally identifiable information.
</p>
<p>
Please check out our <a href="https://ninjaforms.com/privacy-policy/" target="_blank">privacy policy</a> for additional clarification.
</p>
<p>
<input id="optin-send-email" type="checkbox" style="margin:7px;"><label for="optin-send-email"> Yes, please send me occasional emails about Ninja Forms.</label>
</p>
<?php
$current_user = wp_get_current_user();
?>
<p id="optin-block" style="padding-top:10px; display:none;">
<input type="text" id="optin-email-address" value="<?php echo $current_user->user_email; ?>" style="width:100%; font-size:16px;">
</p>
<span id="optin-spinner" class="spinner"></span>
<div id="optin-buttons" style="padding-top:15px; width:100%; clear:both;">
<button id="optout" class="button-secondary" style="margin-bottom:10px; font-size:18px;">Not Now</button>
<button id="optin" class="button-primary" style="margin-bottom:10px; font-size:18px; float:right;">Yes, I agree!</button>
</div>
</div>
<div id="optin-thankyou" style="display:none; padding: 10px 15px; font-size:120%;">
Thank you for opting in!
</div>
\ No newline at end of file
-->
\ No newline at end of file
jQuery(document).ready(function($) {
/**
* Show an opt-in modal if the user isn't currently opted in.
*/
if ( 0 == nfThreeUpgrade.optedIn ) {
var optinModal = new jBox( 'Modal', {
content: jQuery( '#optin-modal' ),
closeOnEsc: false,
closeOnClick: false,
title: jQuery( '#optin-modal-title' )
} );
optinModal.open();
// Show/Hide email field, based on the opt-in checkbox.
jQuery( '#optin-send-email' ).click( function( e ) {
if( jQuery( this ).is( ':checked' ) ) {
jQuery( '#optin-block' ).show();
} else {
jQuery( '#optin-block' ).hide();
}
} );
jQuery( '#optin' ).click( function( e ) {
var sendEmail;
if ( jQuery( '#optin-send-email' ).attr( 'checked' ) ) {
sendEmail = 1;
userEmail = jQuery( '#optin-email-address' ).val();
} else {
sendEmail = 0;
userEmail = '';
}
// Show spinner
jQuery( '#optin-spinner' ).css( 'visibility', 'visible' );
jQuery( '#optin-buttons' ).css( 'visibility', 'hidden' );
// Hit AJAX endpoint and opt-in.
jQuery.post( ajaxurl, { action: 'ninja_forms_optin', send_email: sendEmail, user_email: userEmail }, function( response ) {
jQuery( '#optin-spinner' ).css( 'visibility', 'hidden' );
optinModal.setTitle( '<h2 style="font-size:150%;">Keep being awesome!</h2>' );
optinModal.setContent( jQuery( '#optin-thankyou' ) );
/**
* When we get a response from our endpoint, show a thank you and set a timeout
* to close the modal.
*/
setTimeout (
function(){
optinModal.close();
},
2000
);
} );
} );
jQuery( '#optout' ).click( function( e ) {
// Show spinner
jQuery( '#optin-spinner' ).css( 'visibility', 'visible' );
jQuery( '#optin-buttons' ).css( 'visibility', 'hidden' );
// Hit AJAX endpoint and opt-in.
jQuery.post( ajaxurl, { action: 'ninja_forms_optout' }, function( response ) {
jQuery( '#optin-spinner' ).css( 'visibility', 'hidden' );
// When we get a response from our endpoint, close the modal.
optinModal.close();
} );
} );
}
/*
|--------------------------------------------------------------------------
| Ninja Forms THREE Upgrade App
......
......@@ -202,6 +202,7 @@ final class NF_Dispatcher
/**
* Email address of the current user.
* (if one was provided)
*/
$email = isset( $data[ 'user_email' ] ) ? $data[ 'user_email' ] : '';
......
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