function vtprd_validate_setup_input($input) { //did this come from on of the secondary buttons? $reset = !empty($input['options-reset']) ? true : false; $repair = !empty($input['rules-repair']) ? true : false; $nuke_rules = !empty($input['rules-nuke']) ? true : false; $nuke_cats = !empty($input['cats-nuke']) ? true : false; $nuke_hist = !empty($input['hist-nuke']) ? true : false; $nuke_log = !empty($input['log-nuke']) ? true : false; $nuke_session = !empty($input['session-nuke']) ? true : false; $nuke_cart = !empty($input['cart-nuke']) ? true : false; $cleanup = !empty($input['cleanup']) ? true : false; //v1.1.5 $output = get_option('vtprd_setup_options'); //v1.1.6 switch (true) { case $reset === true: //reset options $output = $this->vtprd_set_default_options(); //load up the defaults //error_log( print_r( 'DEFAULT Options before UPDATE= ', true ) ); //error_log( var_export($output, true ) ); //as default options are set, no further action, just return return apply_filters('vtprd_validate_setup_input', $output, $input); break; case $repair === true: //repair rules $vtprd_nuke = new vtprd_Rule_delete(); $vtprd_nuke->vtprd_repair_all_rules(); //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; case $nuke_rules === true: $vtprd_nuke = new vtprd_Rule_delete(); $vtprd_nuke->vtprd_nuke_all_rules(); //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; case $nuke_cats === true: $vtprd_nuke = new vtprd_Rule_delete(); $vtprd_nuke->vtprd_nuke_all_rule_cats(); //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; case $nuke_hist === true: $vtprd_nuke = new vtprd_Rule_delete(); $vtprd_nuke->vtprd_nuke_lifetime_purchase_history(); // $output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; case $nuke_log === true: $vtprd_nuke = new vtprd_Rule_delete(); $vtprd_nuke->vtprd_nuke_audit_trail_logs(); //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; case $nuke_session === true: //clear any session variables $this->vtprd_destroy_session(); //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; //v1.1.5 begin //v1.1.5 begin case $cleanup === true: update_option('vtprd_license_count', 0); //v1.1.6.1 delete_option('vtprd_rego_clock'); //v1.1.6.1 delete_option('vtprd_license_options'); global $vtprd_license_options; $vtprd_license_options = null; //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 //error_log( print_r( 'deleted $vtprd_license_options', true ) ); break; //v1.1.5 end //v1.1.5 end case $nuke_cart === true: if (defined('WPSC_VERSION') && VTPRD_PARENT_PLUGIN_NAME == 'WP E-Commerce') { global $wpsc_cart; $wpsc_cart->empty_cart(false); } //$output = get_option( 'vtprd_setup_options' ); //v1.1.6 break; default: //standard update button hit... //$output = get_option( 'vtprd_setup_options' ); //v1.0.7.2 changed from array initialize //v1.1.6 foreach ($input as $key => $value) { if (isset($input[$key])) { $output[$key] = strip_tags(stripslashes($input[$key])); } // end if } // end foreach $this->vtprd_destroy_session(); //v1.0.9.3 break; } //V1.0.9.0 Begin // if "discount_taken_where" changed global $vtprd_setup_options; if ($vtprd_setup_options['discount_taken_where'] != $output['discount_taken_where']) { if ($vtprd_setup_options['discount_taken_where'] == 'discountCoupon') { //always check if the manually created coupon codes are there - if not create them. //error_log( print_r( 'vtprd_woo_maybe_create_coupon_types SETUP OPTIONS', true ) ); vtprd_woo_maybe_create_coupon_types(); } else { //error_log( print_r( 'vtprd_woo_maybe_DELETE_coupon_types SETUP OPTIONS', true ) ); vtprd_woo_maybe_delete_coupon_types(); //v1.1.6 ADDED to remove coupon if using UNIT PRICE - otherwise it can be applied to DOUBLE the discount taken!!! } //clear any session variables which could affect things after this update... // $this->vtprd_destroy_session(); v1.0.9.3 now done with all updates } //V1.0.9.0 end //one of these switches must be on if (isset($input['use_lifetime_max_limits']) && ($input['use_lifetime_max_limits'] == 'no' || $output['use_lifetime_max_limits'] == 'no') && ($input['max_purch_rule_lifetime_limit_by_ip'] == 'yes' || $input['max_purch_rule_lifetime_limit_by_email'] == 'yes' || $input['max_purch_rule_lifetime_limit_by_billto_name'] == 'yes' || $input['max_purch_rule_lifetime_limit_by_billto_addr'] == 'yes' || $input['max_purch_rule_lifetime_limit_by_shipto_name'] == 'yes' || $input['max_purch_rule_lifetime_limit_by_shipto_addr'] == 'yes' || ($output['max_purch_rule_lifetime_limit_by_ip'] == 'yes' || $output['max_purch_rule_lifetime_limit_by_email'] == 'yes' || $output['max_purch_rule_lifetime_limit_by_billto_name'] == 'yes' || $output['max_purch_rule_lifetime_limit_by_billto_addr'] == 'yes' || $output['max_purch_rule_lifetime_limit_by_shipto_name'] == 'yes' || $output['max_purch_rule_lifetime_limit_by_shipto_addr'] == 'yes'))) { $input['use_lifetime_max_limits'] = 'yes'; //manually set the switch //v1.0.7.9 $output['use_lifetime_max_limits'] = 'yes'; //v1.0.7.9 /* $admin_errorMsg = __(' As one of the following switches has been set to "yes": ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by IP" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by Email" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by BillTo Name" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by BillTo Address" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by ShipTo Name" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by ShipTo Address" ', 'vtprd') .'<br>'. __('The "Use Customer Rule Limits" must also be set to "yes" ', 'vtprd'); $admin_errorMsgTitle = __('Use Max Customer Rule Limit', 'vtprd'); add_settings_error( 'vtprd Options', $admin_errorMsgTitle , $admin_errorMsg , 'error' ); */ } //one of these switches must be on if (isset($input['use_lifetime_max_limits']) && $input['use_lifetime_max_limits'] == 'yes' && ($input['max_purch_rule_lifetime_limit_by_ip'] == 'no' && $input['max_purch_rule_lifetime_limit_by_email'] == 'no' && $input['max_purch_rule_lifetime_limit_by_billto_name'] == 'no' && $input['max_purch_rule_lifetime_limit_by_billto_addr'] == 'no' && $input['max_purch_rule_lifetime_limit_by_shipto_name'] == 'no' && $input['max_purch_rule_lifetime_limit_by_shipto_addr'] == 'no')) { $input['use_lifetime_max_limits'] = 'no'; //manually set the switch //v1.0.7.9 $output['use_lifetime_max_limits'] = 'no'; //manually set the switch //v1.0.7.9 /* $admin_errorMsg = __(' The "Use Customer Rule Limits" has been set to "no" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by IP" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by Email" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by BillTo Name" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by BillTo Address" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by ShipTo Name" ', 'vtprd') .'<br>'. __('"Check Customer against Rule Purchase History, by ShipTo Address" ', 'vtprd'); $admin_errorMsgTitle = __('Use Max Customer Rule Limit', 'vtprd'); add_settings_error( 'vtprd Options', $admin_errorMsgTitle , $admin_errorMsg , 'error' ); */ } $input['discount_floor_pct_per_single_item'] = preg_replace('/[^0-9.]+/', '', $input['discount_floor_pct_per_single_item']); //remove leading/trailing spaces, percent sign, dollar sign $tempMsg = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $input['lifetime_purchase_button_error_msg']); $input['lifetime_purchase_button_error_msg'] = $tempMsg; /* //In this situation, this 'id or class Selector' may not be blank, supply wpsc checkout default - must include '.' or '#' if ( $input['show_error_before_checkout_products_selector'] <= ' ' ) { $input['show_error_before_checkout_products_selector'] = VTPRD_CHECKOUT_PRODUCTS_SELECTOR_BY_PARENT; } //In this situation, this 'id or class Selector' may not be blank, supply wpsc checkout default - must include '.' or '#' if ( $input['show_error_before_checkout_address_selector'] <= ' ' ) { $input['show_error_before_checkout_address_selector'] = VTPRD_CHECKOUT_ADDRESS_SELECTOR_BY_PARENT; } */ //NO Object-based code on the apply_filters statement needed or wanted!!!!!!!!!!!!! return apply_filters('vtprd_validate_setup_input', $output, $input); }
function vtprd_check_for_deactivation_action() { //moved here from vt-pricing-deals.php, so it can run at admin init time if (!is_plugin_active(VTPRD_PLUGIN_SLUG)) { return; } global $wp_version, $vtprd_setup_options; $earliest_allowed_wp_version = 3.3; if (version_compare(strval($earliest_allowed_wp_version), strval($wp_version), '>') == 1) { //'==1' = 2nd value is lower $message = '<strong>' . __('Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.3 to use the Varktech Pricing Deals plugin.', 'vtprd') . '</strong>'; $message .= '<br>' . __('Current Wordpress Version = ', 'vtprd') . $wp_version; $admin_notices = '<div id="message" class="error fade" style="background-color: #FFEBE8 !important;"><p>' . $message . ' </p></div>'; add_action('admin_notices', create_function('', "echo '{$admin_notices}';")); if (get_option('vtprd_deferred_admin_notices')) { delete_option('vtprd_deferred_admin_notices'); } deactivate_plugins(VTPRD_PLUGIN_SLUG); return; } if (version_compare(PHP_VERSION, VTPRD_EARLIEST_ALLOWED_PHP_VERSION) < 0) { //'<0' = 1st value is lower $message = '<strong>' . __('Looks like you\'re running an older version of PHP. - your PHP version = ', 'vtprd') . PHP_VERSION . '</strong>'; $message .= '<br>' . __('You need to be running **at least PHP version 5** to use this plugin. Please contact your host and request an upgrade to PHP 5+ . Once that has been installed, you can activate this plugin.', 'vtprd'); $admin_notices = '<div id="message" class="error fade" style="background-color: #FFEBE8 !important;"><p>' . $message . ' </p></div>'; add_action('admin_notices', create_function('', "echo '{$admin_notices}';")); if (get_option('vtprd_deferred_admin_notices')) { delete_option('vtprd_deferred_admin_notices'); } deactivate_plugins(VTPRD_PLUGIN_SLUG); return; } if (defined('WOOCOMMERCE_VERSION') && VTPRD_PARENT_PLUGIN_NAME == 'WooCommerce') { $new_version = VTPRD_EARLIEST_ALLOWED_PARENT_VERSION; $current_version = WOOCOMMERCE_VERSION; if (version_compare(strval($new_version), strval($current_version), '>') == 1) { //'==1' = 2nd value is lower $message = '<strong>' . __('Looks like you\'re running an older version of WooCommerce. You need to be running at least ** WooCommerce 2.0 **, to use the Varktech Pricing Deals plugin', 'vtprd') . '</strong>'; $message .= '<br>' . __('Your current WooCommerce version = ', 'vtprd') . WOOCOMMERCE_VERSION; $admin_notices = '<div id="message" class="error fade" style="background-color: #FFEBE8 !important;"><p>' . $message . ' </p></div>'; add_action('admin_notices', create_function('', "echo '{$admin_notices}';")); if (get_option('vtprd_deferred_admin_notices')) { delete_option('vtprd_deferred_admin_notices'); } deactivate_plugins(VTPRD_PLUGIN_SLUG); return; } } /* else if (VTPRD_PARENT_PLUGIN_NAME == 'WooCommerce') { $message = '<strong>' . __('Varktech Pricing Deals for WooCommerce requires that WooCommerce be installed and activated. ' , 'vtprd') . '</strong>' ; $message .= '<br>' . __('It looks like WooCommerce is either not installed, or not activated. ' , 'vtprd'); $admin_notices = '<div id="message" class="error fade" style="background-color: #FFEBE8 !important;"><p>' . $message . ' </p></div>'; add_action( 'admin_notices', create_function( '', "echo '$admin_notices';" ) ); if (get_option('vtprd_deferred_admin_notices')) { delete_option('vtprd_deferred_admin_notices'); } deactivate_plugins( VTPRD_PLUGIN_SLUG ); return; } */ //error_log( print_r( ' PARENT FUNCTIONS $vtprd_setup_options= ', true ) ); //error_log( var_export($vtprd_setup_options, true ) ); if ($vtprd_setup_options['discount_taken_where'] == 'discountCoupon' || $vtprd_setup_options['discount_taken_where'] <= ' ') { //v1.0.9.3 doesn't apply if 'discountUnitPrice' //v1.0.7.4 begin //**************************************** //INSIST that coupons be enabled in woo, in order for this plugin to work!! //**************************************** //always check if the manually created coupon codes are there - if not create them. vtprd_woo_maybe_create_coupon_types(); //error_log( print_r( 'vtprd_woo_maybe_create_coupon_types PARENT FUNCTIONS', true ) ); $coupons_enabled = get_option('woocommerce_enable_coupons') == 'no' ? false : true; if (!$coupons_enabled) { $message = '<strong>' . __('In order for the "Pricing Deals" plugin to function successfully when the "Coupon Discount" setting is selected, the Woo Coupons Setting must be on, and it is currently off.', 'vtprd') . '</strong>'; $message .= '<br><br>' . __('Please go to the Woocommerce/Settings page. Under the "Checkout" tab, check the box next to "Enable the use of coupons" and click on the "Save Changes" button.', 'vtprd'); $admin_notices = '<div id="message" class="error fade" style="background-color: #FFEBE8 !important;"><p>' . $message . ' </p></div>'; add_action('admin_notices', create_function('', "echo '{$admin_notices}';")); } } else { //error_log( print_r( 'vtprd_woo_maybe_DELETE_coupon_types PARENT FUNCTIONS', true ) ); vtprd_woo_maybe_delete_coupon_types(); //v1.1.6 added } }