public function vtprd_license_count_check()
 {
     $vtprd_license_count = get_option('vtprd_license_count');
     if (!$vtprd_license_count) {
         return;
     }
     //if PRO **not active** but installed, and VERSION ERROR, still do the messaging
     //can only do this AFTER or as part of admin_init
     global $vtprd_license_options;
     if (!$vtprd_license_options) {
         $vtprd_license_options = get_option('vtprd_license_options');
     }
     if ($vtprd_license_options['state'] == 'suspended-by-vendor') {
         return;
     }
     //VTPRD_PRO_VERSION only exists if PRO version is installed and active
     if (!defined('VTPRD_PRO_VERSION')) {
         return;
     }
     //if fatal counts exceed limit, never allow pro plugin to be activated
     if ($vtprd_license_count >= 5) {
         vtprd_deactivate_pro_plugin();
         $vtprd_license_options['state'] = 'suspended-by-vendor';
         $vtprd_license_options['status'] = 'invalid';
         $vtprd_license_options['diagnostic_msg'] = 'suspended until contact with vendor';
         update_option('vtprd_license_options', $vtprd_license_options);
     }
     return;
 }
 function vtprd_validate_setup_input($input)
 {
     //error_log( print_r(  'Begin  vtprd_validate_setup_input' , true ) );
     //Get the existing settings!
     $existing_license_options = get_option('vtprd_license_options');
     /*  COMMENTED FOR TESTING ONLY!  
         //*********************************
         // BAIL if suspended 
         //*********************************
         if ($existing_license_options['state'] == 'suspended-by-vendor') {
           $admin_errorMsg = $existing_license_options['msg'] . ' - no action possible without contacting Vendor';
           $admin_errorMsgTitle = 'License Key Suspended';
           add_settings_error( 'vtprd Options', $admin_errorMsgTitle , $admin_errorMsg , 'error' );
           return $existing_license_options;  
         }
         //***************************************
      */
     $new_combined_options = array_merge($existing_license_options, $input);
     //did this come from on of the secondary buttons?
     $activate = !empty($input['activate']) ? true : false;
     $deactivate = !empty($input['deactivate']) ? true : false;
     $nuke_info = !empty($input['nuke-info']) ? true : false;
     $reset_fatal_counter = !empty($input['reset_fatal_counter']) ? true : false;
     //global $vtprd_license_options;
     if ($nuke_info) {
         $license_options = $this->vtprd_set_default_options();
         update_option('vtprd_last_license_check_ts', null);
         return $license_options;
     }
     if ($reset_fatal_counter) {
         //if an unlicensed customer needs to clear the error state after license purchase
         update_option('vtprd_license_count', 0);
         delete_option('vtprd_rego_clock');
         $license_options = $this->vtprd_set_default_options();
         return $license_options;
     }
     $settings_error = false;
     if (isset($new_combined_options['key']) && $new_combined_options['key'] > ' ') {
         $carry_on = true;
     } else {
         $admin_errorMsg = 'License Key required';
         $admin_errorMsgTitle = 'License Key required';
         add_settings_error('vtprd Options', $admin_errorMsgTitle, $admin_errorMsg, 'error');
         $settings_error = true;
     }
     if (isset($new_combined_options['email']) && $new_combined_options['email'] > ' ') {
         $carry_on = true;
     } else {
         $admin_errorMsg = 'Registered purchaser email address required';
         $admin_errorMsgTitle = 'Registered purchaser email address';
         add_settings_error('vtprd Options', $admin_errorMsgTitle, $admin_errorMsg, 'error');
         $settings_error = true;
     }
     //Pick up RADIO button
     $new_combined_options['prod_or_test'] = $_REQUEST['prod_or_test'];
     //$new_combined_options['url'] = 'test.staging.wpengine.anything.com';
     /* defaults to PROD, not necessary
        if ( (isset($new_combined_options['prod_or_test'])) &&
        */
     if ($new_combined_options['prod_or_test'] == 'test') {
         if (isset($new_combined_options['prod_url_supplied_for_test_site']) && $new_combined_options['prod_url_supplied_for_test_site'] > ' ') {
             //*****************************************
             //TEST URL MUST HAVE '.demo.' '.test.' '.stage.' '.staging.' '.beta.'
             //*****************************************
             //current site IS a TEST site
             //v1.1.6.3  staging[number].prod url need for SITEGROUND
             //  needs to be added to   vark-software-licenses.php  !!!
             if (strpos($new_combined_options['url'], 'test.') !== false || strpos($new_combined_options['url'], 'dev.') !== false || strpos($new_combined_options['url'], 'development') !== false || strpos($new_combined_options['url'], 'demo.') !== false || strpos($new_combined_options['url'], 'beta.') !== false || strpos($new_combined_options['url'], 'stage.') !== false || strpos($new_combined_options['url'], 'staging') !== false) {
                 //v1.1.6.3 chg - no period at end
                 $carry_on = true;
             } else {
                 $admin_errorMsg = 'This Test site Does NOT meet naming requirements, must be a production subdomain and have "test." or "dev." or "development" or "beta." or "demo." or "stage." or "staging" in the URL!';
                 $admin_errorMsgTitle = 'TEST site registration';
                 add_settings_error('vtprd Options', $admin_errorMsgTitle, $admin_errorMsg, 'error');
                 $settings_error = true;
             }
             if (!$settings_error) {
                 //*****************************************
                 //Require TEST URL to be a SUBDOMAIN of PROD URL
                 //  last 2 nodes XXXXX.com  must be the SAME
                 //*****************************************
                 //remove slashes
                 $test_url_no_slashes = str_replace('/', '', $new_combined_options['url']);
                 //explode parts
                 $test_url = explode('.', $test_url_no_slashes);
                 $test_url_last_piece = array_pop($test_url);
                 //gets last entry, reduces source array
                 $test_url_2nd_to_last_piece = array_pop($test_url);
                 //LAST 2 NODES OF URL FOR COMPARISON
                 $test_url_last2 = $test_url_2nd_to_last_piece . '.' . $test_url_last_piece;
                 //error_log( print_r(  '$test_url_2nd_to_last_piece= ' .$test_url_2nd_to_last_piece, true  ) );
                 //error_log( print_r(  '$test_url_2nd_to_last_piece= ' .$test_url_last_piece, true  ) );
                 //remove slashes
                 $prod_url = str_replace('/', '', $new_combined_options['prod_url_supplied_for_test_site']);
                 //explode parts
                 $prod_url_array = explode('.', $prod_url);
                 $prod_url_last_piece = array_pop($prod_url_array);
                 //gets last entry, reduces source array
                 //only 1 other piece left
                 if (sizeof($prod_url_array) == 1) {
                     $prod_url_2nd_to_last_piece = $prod_url_array[0];
                 } else {
                     $prod_url_2nd_to_last_piece = array_pop($prod_url_array);
                 }
                 //error_log( print_r(  '$prod_url_2nd_to_last_piece= ' .$prod_url_2nd_to_last_piece, true  ) );
                 //error_log( print_r(  '$prod_url_2nd_to_last_piece= ' .$prod_url_last_piece, true  ) );
                 //LAST 2 NODES OF URL FOR COMPARISON
                 $prod_url_last2 = $prod_url_2nd_to_last_piece . '.' . $prod_url_last_piece;
                 //error_log( print_r(  '$test_url_last2= ' .$test_url_last2 .'x', true  ) );
                 // error_log( print_r(  '$prod_url_last2= ' .$prod_url_last2 .'x', true  ) );
                 //error_log( print_r(  'URL = ' .$new_combined_options['url'], true  ) );
                 //v1.1.6 begin
                 //***********************************************
                 // ALLOW ANY '.staging.wpengine.' NAME
                 //***********************************************
                 if (strpos($new_combined_options['url'], '.staging.wpengine.') !== false) {
                     $all_good = true;
                 } else {
                     //v1.1.6 END
                     if ($test_url_last2 != $prod_url_last2) {
                         $admin_errorMsg = 'Test site Does NOT meet naming requirements - last 2 nodes of the TEST URL (this site) and the PROD URL (supplied) Must be the same!';
                         $admin_errorMsgTitle = 'TEST site registration';
                         add_settings_error('vtprd Options', $admin_errorMsgTitle, $admin_errorMsg, 'error');
                         $settings_error = true;
                     }
                 }
             }
         } else {
             $admin_errorMsg = 'TEST site registration ALSO requires the PROD site URL';
             $admin_errorMsgTitle = 'TEST site registration';
             add_settings_error('vtprd Options', $admin_errorMsgTitle, $admin_errorMsg, 'error');
             $settings_error = true;
         }
     } else {
         //if PROD, clear out test site data
         $new_combined_options['prod_url_supplied_for_test_site'] = null;
     }
     if ($settings_error) {
         $new_combined_options['status'] = 'invalid';
         $new_combined_options['state'] = 'pending';
         $new_combined_options['msg'] = $admin_errorMsg;
         return $new_combined_options;
     }
     switch (true) {
         case $activate === true:
             //if already active, no action required
             if ($new_combined_options['state'] == 'active') {
                 return $new_combined_options;
             }
             $action = 'activate_license';
             //Only possible when the PRO PLUGIN is INSTALLED AND ACTIVE
             $new_combined_options = $this->vtprd_license_phone_home($new_combined_options, $action);
             //TEST    $new_combined_options['msg'] = 'License Activated';
             /*
             //clear out plugin version fields for new activation:
             $new_combined_options['pro_plugin_version_status'] = null;
             $new_combined_options['pro_version'] = null;
             */
             //*****
             // MESSAGING handled in main plugin file, in function vtprd_maybe_pro_license_error
             //*****
             /*  INVALID  done in main file
                 If ($new_combined_options['status'] == 'invalid') {
                   $vtprd_license_options = $new_combined_options; //OVERWRITE temporarily so that admin_notices can pick up the text          
                   add_action( 'admin_notices', 'vtprd_license_error_notice' );        
                 }
                 */
             if ($new_combined_options['status'] == 'valid') {
                 //MESSAGE, built-in perhaps ===>>> always displays status
             }
             break;
         case $deactivate === true:
             //if already deactivated, no action required
             if ($new_combined_options['state'] == 'deactivated') {
                 return $new_combined_options;
             }
             //Only possible when the PRO PLUGIN is INSTALLED AND ACTIVE
             $action = 'deactivate_license';
             $new_combined_options = $this->vtprd_license_phone_home($new_combined_options, $action);
             /*
             //clear out plugin version fields for new activation:
             $new_combined_options['pro_plugin_version_status'] = null;
             $new_combined_options['pro_version'] = null;
             $new_combined_options['msg'] = 'License Deactivated';
             */
             //*****
             // MESSAGING handled in main plugin file, in function vtprd_maybe_pro_license_error
             //*****
             /* INVALID done in main file
                add_action( 'admin_notices', 'vtprd_license_error_notice' );
                */
             break;
         default:
             //standard update button hit...
             break;
     }
     /*
           CLIENT tracks these statuses:
         $failure_msg = 'License Not Found'
               $failure_msg = 'Email Not Supplied';
               $failure_msg = 'Prod_or_Test value Not Supplied';
               $failure_msg = 'Test URL Not Supplied';
               $failure_msg = 'IP Address Not Supplied';
               $failure_msg = 'Prod URL not supplied for Test URL registration';
               
               $vark_args['verify_response'] = 'test_name_invalid'
               $vark_args['verify_response'] = 'license_invalid'
               $vark_args['verify_response'] = 'email_mismatch'
               $vark_args['verify_response'] = 'test_already_activated'; //info only, not a strike
               $vark_args['verify_response'] = 'prod_already_activated'; //info only, not a strike
     */
     //SUSPEND LOCALLY ONLY for THESE issues
     if ($new_combined_options['status'] == 'invalid') {
         if ($new_combined_options['msg'] == 'Email supplied does not match email address for License' || $new_combined_options['msg'] == 'License Not Found' || $new_combined_options['msg'] == 'Email Not Supplied' || $new_combined_options['msg'] == 'Prod_or_Test value Not Supplied' || $new_combined_options['msg'] == 'Test URL Not Supplied' || $new_combined_options['msg'] == 'IP Address Not Supplied' || $new_combined_options['msg'] == 'Prod URL not supplied for Test URL registration' || $new_combined_options['diagnostic_msg'] == 'different_test_site_already_registered' || $new_combined_options['diagnostic_msg'] == 'test_name_invalid' || $new_combined_options['diagnostic_msg'] == 'license_invalid' || $new_combined_options['diagnostic_msg'] == 'item_name_mismatch' || $new_combined_options['diagnostic_msg'] == 'email_mismatch' || $new_combined_options['diagnostic_msg'] == 'demo_license_expired') {
             //strikes are NOT increased at the HOST, only HERE
             if ($existing_license_options['strikes'] > $new_combined_options['strikes']) {
                 $new_combined_options['strikes'] = $existing_license_options['strikes'];
             }
             $new_combined_options['strikes']++;
             if ($new_combined_options['strikes'] >= 5) {
                 $new_combined_options['state'] = 'suspended-by-vendor';
                 $new_combined_options['status'] = 'invalid';
                 $new_combined_options['diagnostic_msg'] = 'suspended after 5 strikes!';
                 vtprd_deactivate_pro_plugin();
                 vtprd_increment_license_count();
                 //not needed, taken care of elsewhere here...
                 //$new_combined_options['msg']    = 'License Suspended by Vendor.  Please contact <a href="https://www.varktech.com/support"  title="Support">VarkTech Support</a> for more Information.';
             }
             $new_combined_options['strikes_possible'] = 5;
         } else {
             $new_combined_options['strikes_possible'] = 3;
         }
     }
     return $new_combined_options;
 }