Plugin Directory

Changeset 3386951


Ignore:
Timestamp:
10/30/2025 09:29:51 AM (5 months ago)
Author:
akashmalik
Message:

PHP version 8.4 release compatibility

Location:
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/grconnect.php

    r3274273 r3386951  
    33/**
    44 * @package Gratisfaction Connect
    5  * @version 4.5.1
     5 * @version 4.5.2
    66 */
    77/*
     
    99  Plugin URI: http://appsmav.com
    1010  Description: Loyalty + Referral + Rewards + Birthdays and Anniversaries + Giveaways + Sweepstakes.
    11   Version: 4.5.1
     11  Version: 4.5.2
    1212  Author: Appsmav
    1313  Author URI: http://appsmav.com
     
    3232define('GR_PLUGIN_BASE_PATH', dirname(__FILE__));
    3333
     34// Load PHP compatibility polyfills for older versions
     35if (!function_exists('array_column')) {
     36    include_once(GR_PLUGIN_BASE_PATH . '/includes/compat/array_column.php');
     37}
     38if (!function_exists('hash_equals')) {
     39    include_once(GR_PLUGIN_BASE_PATH . '/includes/compat/hash_equals.php');
     40}
     41
    3442if(!class_exists('GR_Connect'))
    3543{
     
    3947        const REDEEM_COUPON = 'GRPAYPOINTS';
    4048
    41         public static $_plugin_version  = '4.5.1';
     49        public static $_plugin_version  = '4.5.2';
    4250        public static $_callback_url = 'https://gratisfaction.appsmav.com/';
    4351        public static $_api_version  = 'newapi/v2/';
     
    119127                                // Validate API response
    120128                                if (empty($response) || !empty($response['error'])) {
    121                                     throw new Exception('API request failed: ' . ($response['message'] ?? 'Unknown error'));
     129                                    throw new Exception('API request failed: ' . (isset($response['message']) ? $response['message'] : 'Unknown error'));
    122130                                }
    123131                            }
     
    167175                    return $message;
    168176
    169                 $coupon = strtolower($coupon->get_code());
    170                 $redeem_coupon = strtolower(WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON));
     177                $coupon = appsmav_strtolower($coupon->get_code());
     178                $redeem_coupon = appsmav_strtolower(WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON));
    171179                if($coupon === $redeem_coupon)
    172180                    return __('', 'gratisfaction');
     
    182190                    return $message;
    183191
    184                 $coupon = strtolower($coupon->get_code());
     192                $coupon = appsmav_strtolower($coupon->get_code());
    185193                $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON);
    186                 if ($coupon === strtolower($redeem_coupon)) {
     194                if ($coupon === appsmav_strtolower($redeem_coupon)) {
    187195                    if (WC_Coupon::WC_COUPON_SUCCESS === $message_code)
    188196                        return __(WC()->session->get('gr_redeemed_status_msg'), 'gratisfaction');
     
    207215
    208216                $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON);
    209                 if(strstr(strtolower($label), strtolower($redeem_coupon)) && !empty(WC()->session))
     217                if(appsmav_strstr(appsmav_strtolower($label), appsmav_strtolower($redeem_coupon)) && !empty(WC()->session))
    210218                {
    211219                    $deduct_points_str  =   '';
    212                     $deduct_points  =   WC()->session->get('gr_user_deduct_points');
     220                    $deduct_points  =   WC()->session->get('gr_user_deduct_points', 0);
    213221
    214222                    if(!empty($deduct_points))
    215223                    {
    216                         $point_lable = ($deduct_points > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
     224                        $point_lable = ($deduct_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
    217225                        $deduct_points_str  =   ' (' . esc_html($deduct_points) . ' ' . esc_html($point_lable) . ')';
    218226                    }
     
    254262
    255263                $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON);
    256                 if (strtolower($coupon_code) != strtolower($redeem_coupon))
     264                if (appsmav_strtolower($coupon_code) != appsmav_strtolower($redeem_coupon))
    257265                    return $coupon;
    258266
     
    281289
    282290                // Set redeem points in descriptions
    283                 $coupon_discount = WC()->session->get('gr_user_applied_discount')/$ratio;
     291                $coupon_discount = WC()->session->get('gr_user_applied_discount', 0)/$ratio;
    284292                $points = WC()->session->get('gr_user_deduct_points', 0);
    285293
     
    595603
    596604                $param = [];
    597                 $param['status'] = $param['order_status'] = strtolower($order->get_status());
     605                $param['status'] = $param['order_status'] = appsmav_strtolower($order->get_status());
    598606
    599607                $user_email = '';
     
    619627                if (!empty($gr_applied_points))
    620628                {
    621                     $points = explode('_', $gr_applied_points);
     629                    $points = appsmav_explode('_', $gr_applied_points);
    622630                    $param['redeem_points']  = empty($points['1']) ? 0 : $points['1'];
    623631                    $param['redeem_charges'] = empty($points['2']) ? 0 : $points['2'];
     
    626634                $param['line_items'] = [];
    627635                foreach ($order->get_items('line_item') as $key => $item) {
    628                     $param['line_items'][] = $item->get_data(); // Only product_id & total are required now
     636                    $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data()); // Only product_id & total are required now
    629637                }
    630638
     
    645653                // Set refund data for order change also
    646654                $refundData = array();
    647                 foreach ($order->get_refunds() as $key => $refund) {
    648                     $refundData[$key]['refund'] = $refund->get_data();
    649                     foreach ($refund->get_items() as $item_id => $item) {
    650                         $refundData[$key]['line_items'][$item_id] = $item->get_data();
     655                $refunds = $order->get_refunds();
     656                if (!empty($refunds) && is_array($refunds)) {
     657                    foreach ($refunds as $key => $refund) {
     658                        if (empty($refund) || !is_object($refund)) {
     659                            continue;
     660                        }
     661                        $refundData[$key]['refund'] = self::sanitize_refund_data_for_api($refund->get_data());
     662                        $refund_items = $refund->get_items();
     663                        if (!empty($refund_items) && is_array($refund_items)) {
     664                            foreach ($refund_items as $item_id => $item) {
     665                                if (empty($item) || !is_object($item)) {
     666                                    continue;
     667                                }
     668                                $refundData[$key]['line_items'][$item_id] = self::sanitize_refund_data_for_api($item->get_data());
     669                            }
     670                        }
    651671                    }
    652672                }
     
    701721                    {
    702722
    703                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){
     723                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){
    704724                            $param['comment'] = 'Main WCMp Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total'];
    705725                            $param['total'] = 0;
     
    712732                    if(class_exists('WeDevs_Dokan'))
    713733                    {
    714                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){
     734                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){
    715735                            $param['comment'] = 'Main Dokan Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total'];
    716736                            $param['total'] = 0;
     
    750770
    751771                $param = [];
    752                 $param['status'] = $param['order_status'] = strtolower($order->get_status());
     772                $param['status'] = $param['order_status'] = appsmav_strtolower($order->get_status());
    753773
    754774                $user_email = '';
     
    778798                $param['line_items'] = [];
    779799                foreach ($order->get_items('line_item') as $key => $item) {
    780                     $param['line_items'][] = $item->get_data();
     800                    $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data());
    781801                }
    782802
     
    793813                        {
    794814                            $redeem_coupon = empty(WC()->session) ? '' : WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON);
    795                             if(!empty($item_data['name']) && !empty($item_data['discount'])
    796                                 && strtolower($item_data['name']) == strtolower($redeem_coupon))
    797                                 $points_discount_val    =   $item_data['discount'];
     815                           
     816                            // Backward compatibility: Use method calls for WC 3.0+, array access for older versions
     817                            if(version_compare( WC_VERSION, '3.0', '>=' ))
     818                            {
     819                                $coupon_name = $item_data->get_name();
     820                                $coupon_discount = $item_data->get_discount();
     821                            }
     822                            else
     823                            {
     824                                $coupon_name = isset($item_data['name']) ? $item_data['name'] : '';
     825                                $coupon_discount = isset($item_data['discount']) ? $item_data['discount'] : 0;
     826                            }
     827                           
     828                            if(!empty($coupon_name) && !empty($coupon_discount)
     829                                && appsmav_strtolower($coupon_name) == appsmav_strtolower($redeem_coupon))
     830                                $points_discount_val = $coupon_discount;
    798831                        }
    799832                    }
     
    817850                }
    818851
    819                if(strtolower($param['order_status']) == 'pending' && empty($param['redeem_points']))
     852               if(appsmav_strtolower($param['order_status']) == 'pending' && empty($param['redeem_points']))
    820853                   return;
    821854
     
    868901                    {
    869902
    870                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){
     903                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){
    871904                            $param['comment'] = 'Main WCMp Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total'];
    872905                            $param['total'] = 0;
     
    879912                    if(class_exists('WeDevs_Dokan'))
    880913                    {
    881                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){
     914                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){
    882915                            $param['comment'] = 'Main Dokan Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total'];
    883916                            $param['total'] = 0;
     
    10221055                $grCampId  = get_option('grconnect_secret');
    10231056                $grPayload = get_option('grconnect_payload');
    1024                 if (empty($grShopId) || empty($grAppId) || empty($grCampId) || empty($grPayload))
    1025                     return;
     1057               
     1058                if (empty($grShopId) || empty($grAppId) || empty($grCampId) || empty($grPayload)) {
     1059                    return;
     1060                }
    10261061
    10271062                // Set up the settings for this plugin
    1028                 if(!empty($_REQUEST['action']) && sanitize_text_field($_REQUEST['action']) == 'woocommerce_delete_refund')
     1063                $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
     1064                if(!empty($action) && $action == 'woocommerce_delete_refund')
    10291065                {
    10301066                    $refund = new WC_Order_Refund($refund_id);
    1031                     $order = new WC_Order($refund->post->post_parent);
     1067                    if (empty($refund) || !is_object($refund)) {
     1068                        return;
     1069                    }
     1070                    $parent_id = appsmav_get_parent_id($refund);
     1071                    if (empty($parent_id)) {
     1072                        return;
     1073                    }
     1074                    $order = new WC_Order($parent_id);
     1075                    if (empty($order) || !is_object($order)) {
     1076                        return;
     1077                    }
    10321078
    10331079                    $param['discount'] = $order->get_total_discount();
     
    10641110                    $param['customer_id'] = $order->get_user_id();
    10651111                    $param['order'] = 0;
    1066                     $param['id_order'] = $refund->post->post_parent;
     1112                    $param['id_order'] = appsmav_get_parent_id($refund);
    10671113                    $param['payload'] = $grPayload;
    10681114                    $param['plugin_version'] = self::$_plugin_version;
     
    10881134                    }
    10891135
    1090                     $param['comment'] = 'Order Id Refund Restore - ' . $refund->post->post_parent . ' From ' . get_option('siteurl');
     1136                    $param['comment'] = 'Order Id Refund Restore - ' . appsmav_get_parent_id($refund) . ' From ' . get_option('siteurl');
    10911137                    $param['status'] = 'Add';
    10921138                    $param['order_status'] = $order->get_status();
     
    11461192                // Set up the settings for this plugin
    11471193                $order = new WC_Order($order_id);
     1194                if (empty($order) || !is_object($order)) {
     1195                    return;
     1196                }
    11481197
    11491198                try {
     
    11511200                    if(class_exists('WCMp'))
    11521201                    {
    1153                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1')
     1202                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1')
    11541203                            return;
    11551204                    }
    11561205                    if(class_exists('WeDevs_Dokan'))
    11571206                    {
    1158                         if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1')
     1207                        if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1')
    11591208                            return;
    11601209                    }
     
    11721221                $param['line_items'] = [];
    11731222                foreach ($order->get_items('line_item') as $key => $item) {
    1174                     $param['line_items'][] = $item->get_data(); // TODO: Only product_id & total are required now
     1223                    $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data()); // TODO: Only product_id & total are required now
    11751224                }
    11761225
    11771226                $refundData = array();
    1178                 foreach ($order->get_refunds() as $key => $refund) {
    1179                     $refundData[$key]['refund'] = $refund->get_data();
    1180                     foreach ($refund->get_items() as $item_id => $item) {
    1181                         $refundData[$key]['line_items'][$item_id] = $item->get_data();
     1227                $refunds = $order->get_refunds();
     1228                if (!empty($refunds) && is_array($refunds)) {
     1229                    foreach ($refunds as $key => $refund) {
     1230                        if (empty($refund) || !is_object($refund)) {
     1231                            continue;
     1232                        }
     1233                        $refundData[$key]['refund'] = self::sanitize_refund_data_for_api($refund->get_data());
     1234                        $refund_items = $refund->get_items();
     1235                        if (!empty($refund_items) && is_array($refund_items)) {
     1236                            foreach ($refund_items as $item_id => $item) {
     1237                                if (empty($item) || !is_object($item)) {
     1238                                    continue;
     1239                                }
     1240                                $refundData[$key]['line_items'][$item_id] = self::sanitize_refund_data_for_api($item->get_data());
     1241                            }
     1242                        }
    11821243                    }
    11831244                }
     
    12351296                $param['comment'] = 'Order Id Refunded - ' . $order_id . ' From ' . get_option('siteurl');
    12361297                $param['status'] = 'partial_refund';
    1237                 $param['order_status'] = strtolower($order->get_status());
     1298                $param['order_status'] = appsmav_strtolower($order->get_status());
    12381299
    12391300                $param['plugin_version'] = self::$_plugin_version;
    12401301                $param['payload'] = $grPayload;
    12411302                $urlApi = self::$_callback_url . self::$_api_version . 'removeEntryNew';
    1242                 $this->callGrConnectApi($param, $urlApi);
     1303               
     1304                // Sanitize refund data to handle WC_DateTime objects
     1305                $param = self::sanitize_refund_data_for_api($param);
     1306               
     1307                $api_response = $this->callGrConnectApi($param, $urlApi);
     1308               
    12431309            }
    12441310            catch(Exception $ex)
     
    12741340                    //add_action('woocommerce_order_edit_status', [$this, 'send_connect_init']);
    12751341                    add_action('woocommerce_order_status_changed', [$this, 'send_status_init']);
    1276                     add_action('before_delete_post', [$this, 'send_refund_delete_post_init']);
     1342                    add_action('before_delete_post', [$this, 'send_refund_delete_post_init'], 20);
    12771343                    //add_action('woocommerce_order_status_refunded', [$this, 'send_refund_init']);
    1278                     add_action('woocommerce_order_refunded', [$this, 'send_refund_init']);
     1344                    add_action('woocommerce_order_refunded', [$this, 'send_refund_init'], 20);
    12791345                    add_action('woocommerce_created_customer', [$this, 'send_customer_init']);
    12801346                    add_action('profile_update', [$this, 'customer_profile_update']);
     
    13741440                            {
    13751441                                $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON);
    1376                                 if(strtolower($coupon_code) === strtolower($redeem_coupon))
     1442                                if(appsmav_strtolower($coupon_code) === appsmav_strtolower($redeem_coupon))
    13771443                                {
    13781444                                    WC()->session->set('gr_applied_points', '');
     
    13891455                $cart_count = 0;
    13901456                if (!empty(WC()->cart)) {
    1391                     $cart_count =  count(WC()->cart->get_cart());
     1457                    $cart_items = WC()->cart->get_cart();
     1458                    $cart_count = (is_array($cart_items) || $cart_items instanceof Countable) ? count($cart_items) : 0;
    13921459
    13931460                    //Reset the session values if discount is not there
     
    14821549                    if (strpos($url,$template_name) !== false) {
    14831550                        $start = strpos($url,$template_name);
    1484                         $first_part = substr($url, $start+strlen($template_name));
     1551                        $first_part = substr($url, $start+appsmav_strlen($template_name));
    14851552                        $order_id = substr($first_part, 0, strpos($first_part, '/'));
    14861553                    }
     
    16101677                $rtype = isset($atts['rtype']) ? sanitize_text_field($atts['rtype']) : '';
    16111678                $patternAlphaNum = '/^[a-zA-Z0-9]+$/';
    1612                 if (empty($id) || !preg_match($patternAlphaNum, $id) || strlen($id) > 10) {
     1679                if (empty($id) || !preg_match($patternAlphaNum, $id) || appsmav_strlen($id) > 10) {
    16131680                    return '';
    16141681                }
    1615                 if (!empty($rtype) && (!preg_match($patternAlphaNum, $rtype) || strlen($rtype) > 10)) {
     1682                if (!empty($rtype) && (!preg_match($patternAlphaNum, $rtype) || appsmav_strlen($rtype) > 10)) {
    16161683                    return '';
    16171684                }
     
    21012168                }
    21022169
    2103                 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable');
     2170                $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable', '');
    21042171
    21052172                $items = WC()->cart->get_cart();
     
    21112178                    WC()->session->set('gr_discount_applied', 0);
    21122179                }
    2113                 else if(WC()->session->get('gr_user_applied_discount') <= 0 || empty($items))
     2180                else if(WC()->session->get('gr_user_applied_discount', 0) <= 0 || empty($items))
    21142181                {
    21152182                    WC()->cart->remove_coupon($redeem_coupon);
     
    21242191                if(WC()->session->get('gr_user_max_discount', 0) > 0 && WC()->session->get('gr_user_deduct_points', 0) >= 1)
    21252192                {
    2126                     $discount = WC()->session->get('gr_user_max_discount');
    2127                     $points = WC()->session->get('gr_user_deduct_points');
     2193                    $discount = WC()->session->get('gr_user_max_discount', 0);
     2194                    $points = WC()->session->get('gr_user_deduct_points', 0);
    21282195                    $redeem_point_lable = str_replace('{points}', $points, $redeem_point_lable);
    21292196                    $redeem_point_lable = str_replace('{points_value}', wc_price($discount), $redeem_point_lable);
    21302197
    2131                     $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
     2198                    $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
    21322199                    $redeem_point_lable = '<p class="grPointsRedeem" id="gr_checkout_lable_top">' . str_replace('{points_label}', $point_lable, $redeem_point_lable);
    21332200
     
    21392206                        $extra_pay_apply = 'display:none;';
    21402207                        $extra_pay_confirm = '';
    2141                         $extra_point_lable = ($extra_pay_points > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
     2208                        $extra_point_lable = ($extra_pay_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
    21422209
    21432210                        $extra_points_info = WC()->session->get('gr_redeem_extra_point_info', '');
     
    21502217
    21512218                    // add 'Apply Discount' button
    2152                     if(WC()->session->get('gr_user_applied_discount') == 0)
     2219                    if(WC()->session->get('gr_user_applied_discount', 0) == 0)
    21532220                    {
    21542221                        $btn_agree = WC()->session->get('gr_btn_redeem_confirm', '');
     
    21562223                        $redeem_point_lable .= '<input type="hidden" name="gr_rewards_apply_discount" class="gr_rewards_apply_discount" value="1" />';
    21572224                        $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount_confirm" style="'.$extra_pay_confirm.'" value="'.$btn_agree.'" />';
    2158                         $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount" style="'.$extra_pay_apply.'" value="' . WC()->session->get('gr_redeem_btn_text') . '" />';
     2225                        $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount" style="'.$extra_pay_apply.'" value="' . WC()->session->get('gr_redeem_btn_text', '') . '" />';
    21592226                        $redeem_point_lable .= '</form>';
    21602227
     
    21662233                        $redeem_point_lable = '';
    21672234
    2168                         if(WC()->session->get('gr_user_applied_discount') != $discount)
     2235                        if(WC()->session->get('gr_user_applied_discount', 0) != $discount)
    21692236                        {
    21702237                            WC()->session->set('gr_user_max_discount', $discount);
    21712238                            WC()->session->set('gr_user_deduct_points', $points);
    21722239
    2173                             $gr_user_max_discount = WC()->session->get('gr_user_max_discount');
     2240                            $gr_user_max_discount = WC()->session->get('gr_user_max_discount', 0);
    21742241                            WC()->session->set('gr_user_applied_discount', (!empty($gr_user_max_discount) ? $gr_user_max_discount : 0));
    21752242                        }
     
    22752342                if(WC()->session->get('gr_user_max_discount', 0) > 0 && WC()->session->get('gr_user_deduct_points', 0) >= 1)
    22762343                {
    2277                     $discount = WC()->session->get('gr_user_max_discount');
     2344                    $discount = WC()->session->get('gr_user_max_discount', 0);
    22782345                    if(WC()->session->get('gr_user_applied_discount') != $discount)
    22792346                    {
     
    23252392                }
    23262393
    2327                 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable');
     2394                $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable', '');
    23282395
    23292396                self::gr_calc_point_value();
     
    23332400                $redeem_point_lable = str_replace('{points}', $points, $redeem_point_lable);
    23342401                $redeem_point_lable = str_replace('{points_value}', wc_price($discount), $redeem_point_lable);
    2335                 $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
     2402                $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
    23362403                $redeem_point_lable = str_replace('{points_label}', $point_lable, $redeem_point_lable);
    23372404                $res['msg'] = $redeem_point_lable;
     
    23622429                    'discounted_amount'   => WC()->session->get('gr_user_max_discount', 0),
    23632430                    'points'              => WC()->session->get('gr_user_deduct_points', 0),
    2364                     'cart_count'          => count(WC()->cart->get_cart()),
     2431                    'cart_count'          => (is_array(WC()->cart->get_cart()) || WC()->cart->get_cart() instanceof Countable) ? count(WC()->cart->get_cart()) : 0,
    23652432                    'is_discount_applied' => 0,
    23662433                    'extra_pbp'           => WC()->session->get('gr_user_extra_pay_points', 0)
     
    24832550                    }
    24842551
    2485                     if ( is_array($list_products) && count($list_products)>0 )
     2552                    if ( (is_array($list_products) || $list_products instanceof Countable) && count($list_products)>0 )
    24862553                    {
    24872554                        $product_price_range = array();
     
    25482615                $redeem_point_lable = WC()->session->get('gr_redeem_point_product_per_dollar_lable');
    25492616                $redeem_point_lable = str_replace('{points}', $discount, $redeem_point_lable);
    2550                 $point_lable = ($max_points > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
     2617                $point_lable = ($max_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
    25512618                $redeem_point_lable = str_replace('{points_label}', $point_lable, $redeem_point_lable);
    25522619
     
    26022669                $earn_exclude_products = array();
    26032670                if(!empty(WC()->session->get('gr_earn_exclude_products', ''))){
    2604                     $earn_exclude_products = explode(',', trim(WC()->session->get('gr_earn_exclude_products', '')));
     2671                    $earn_exclude_products = appsmav_explode(',', appsmav_trim(WC()->session->get('gr_earn_exclude_products', '')));
    26052672                    $earn_exclude_products = array_map('trim', $earn_exclude_products);
    26062673                }
     
    26482715                    }
    26492716
    2650                     if ( is_array($list_products) && count($list_products)>0 )
     2717                    if ( (is_array($list_products) || $list_products instanceof Countable) && count($list_products)>0 )
    26512718                    {
    26522719                        $product_price_range = array();
     
    27082775                    return;
    27092776
    2710                 $point_lable = ($point_earn > 1) ? WC()->session->get('gr_points_lable') : WC()->session->get('gr_point_lable');
    2711 
    2712                 $earn_point_lable = WC()->session->get('gr_earn_point_per_dollar_lable');
     2777                $point_lable = ($point_earn > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', '');
     2778
     2779                $earn_point_lable = WC()->session->get('gr_earn_point_per_dollar_lable', '');
    27132780                $earn_point_lable = str_replace('{points}', $point_earn, $earn_point_lable);
    27142781                $earn_point_lable = str_replace('{points_label}', $point_lable, $earn_point_lable);
     
    27442811                WC()->session->set('gr_user_extra_pay_points', 0);
    27452812
    2746                 $redeem_point = WC()->session->get('gr_redeem_point_per_dollar')/$ratio;
     2813                $redeem_point = WC()->session->get('gr_redeem_point_per_dollar', 0)/$ratio;
    27472814                $cart_total = WC()->cart->subtotal;
    2748                 $discount = floor(WC()->session->get('gr_user_points') / $redeem_point);
     2815                $discount = floor(WC()->session->get('gr_user_points', 0) / $redeem_point);
    27492816
    27502817                $applied_coupons = WC()->cart->applied_coupons;
     
    27532820                    foreach($applied_coupons as $cart_coupon)
    27542821                    {
    2755                         if (strtolower($cart_coupon) != strtolower($redeem_coupon))
     2822                        if (appsmav_strtolower($cart_coupon) != appsmav_strtolower($redeem_coupon))
    27562823                            $cart_total -= WC()->cart->get_coupon_discount_amount($cart_coupon);
    27572824                    }
     
    28472914                    WC()->session->set('gr_user_deduct_points', $points);
    28482915
    2849                     if(WC()->cart->has_discount($redeem_coupon) && WC()->session->get('gr_user_applied_discount') != $discount)
     2916                    if(WC()->cart->has_discount($redeem_coupon) && WC()->session->get('gr_user_applied_discount', 0) != $discount)
    28502917                    {
    28512918                        WC()->session->set('gr_user_applied_discount', (empty($discount) ? 0 : $discount));
     
    28712938                    return;
    28722939
    2873                 WC()->session->set('gr_api_sess', $app_config['date_updated']);
    2874                 WC()->session->set('gr_loyalty_campaign_enabled', $app_config['points']['loyalty_campaign_enabled']);
    2875                 WC()->session->set('earn_point_enabled', $app_config['points']['earn_point_enabled']);
    2876                 WC()->session->set('gr_purchase_theme_status', $app_config['points']['purchase_theme_status']);
    2877                 WC()->session->set('redeem_point_enabled', $app_config['points']['redeem_purchase_status']);
    2878                 WC()->session->set('gr_roundoff_type', $app_config['points']['gr_roundoff_type']);
    2879                 WC()->session->set('gr_redeem_point_per_dollar', $app_config['points']['redeem_point_per_dollar']);
    2880                 WC()->session->set('gr_redeem_theme_status', $app_config['points']['redeem_theme_status']);
    2881                 WC()->session->set('minimum_order_value', $app_config['points']['minimum_order_value']);
    2882                 WC()->session->set('gr_redeem_point_per_dollar_lable', stripslashes($app_config['lang']['redeem_point_per_dollar_lable']));
    2883                 WC()->session->set('gr_redeem_point_product_per_dollar_lable', stripslashes($app_config['lang']['redeem_point_product_per_dollar_lable']));
    2884                 WC()->session->set('gr_earn_point_per_dollar', stripslashes($app_config['points']['earn_point_per_dollar']));
    2885                 WC()->session->set('gr_earn_point_per_dollar_lable', stripslashes($app_config['lang']['earn_point_per_dollar_lable']));
    2886                 WC()->session->set('gr_point_lable', $app_config['lang']['point_lable']);
    2887                 WC()->session->set('gr_points_lable', $app_config['lang']['points_lable']);
    2888                 WC()->session->set('gr_redeem_btn_text', $app_config['lang']['redeem_btn_text']);
    2889                 WC()->session->set('gr_redeemed_btn_text', $app_config['lang']['redeemed_btn_text']);
    2890                 WC()->session->set('gr_redeemed_status_msg', $app_config['lang']['redeemed_status_msg']);
    2891                 WC()->session->set('label_redeemed_points', $app_config['lang']['label_redeemed_points']);
    2892                 WC()->session->set('label_life_time_points', $app_config['lang']['label_life_time_points']);
    2893                 WC()->session->set('label_available_points', $app_config['lang']['label_available_points']);
    2894                 WC()->session->set('error_more_points_required', $app_config['lang']['error_more_points_required']);
    2895                 WC()->session->set('label_exclusion_points', $app_config['lang']['label_exclusion_points']);
    2896                 WC()->session->set('label_total_points', $app_config['lang']['label_total_points']);
    2897                 WC()->session->set('no_records_found', $app_config['lang']['no_records_found']);
    2898                 WC()->session->set('gr_loyalty_menu_name', stripslashes($app_config['lang']['loyalty_menu_name']));
    2899                 WC()->session->set('gr_loyalty_date_start', $app_config['loyalty']['date_start']);
    2900                 WC()->session->set('gr_loyalty_date_end', $app_config['loyalty']['date_end']);
    2901                 WC()->session->set('gr_loyalty_timezone', $app_config['loyalty']['timezone']);
    2902                 WC()->session->set('gr_loyalty_is_open', $app_config['loyalty']['is_open']);
    2903                 WC()->session->set('gr_global_review_enabled', $app_config['reviews']['global_review_enabled']);
    2904                 WC()->session->set('gr_global_review_points', $app_config['reviews']['global_review_points']);
    2905                 WC()->session->set('gr_global_review_lable_enabled', $app_config['reviews']['global_review_lable_enabled']);
    2906                 WC()->session->set('gr_global_review_lable', $app_config['reviews']['global_review_lable']);
     2940                WC()->session->set('gr_api_sess', empty($app_config['date_updated']) ? 0 : $app_config['date_updated']);
     2941                WC()->session->set('gr_loyalty_campaign_enabled', empty($app_config['points']['loyalty_campaign_enabled']) ? 0 : $app_config['points']['loyalty_campaign_enabled']);
     2942                WC()->session->set('earn_point_enabled', empty($app_config['points']['earn_point_enabled']) ? 0 : $app_config['points']['earn_point_enabled']);
     2943                WC()->session->set('gr_purchase_theme_status', empty($app_config['points']['purchase_theme_status']) ? 0 : $app_config['points']['purchase_theme_status']);
     2944                WC()->session->set('redeem_point_enabled', empty($app_config['points']['redeem_purchase_status']) ? 0 : $app_config['points']['redeem_purchase_status']);
     2945                WC()->session->set('gr_roundoff_type', empty($app_config['points']['gr_roundoff_type']) ? 'ROUND' : $app_config['points']['gr_roundoff_type']);
     2946                WC()->session->set('gr_redeem_point_per_dollar', empty($app_config['points']['redeem_point_per_dollar']) ? 0 : $app_config['points']['redeem_point_per_dollar']);
     2947                WC()->session->set('gr_redeem_theme_status', empty($app_config['points']['redeem_theme_status']) ? 0 : $app_config['points']['redeem_theme_status']);
     2948                WC()->session->set('minimum_order_value', empty($app_config['points']['minimum_order_value']) ? 0 : $app_config['points']['minimum_order_value']);
     2949                WC()->session->set('gr_redeem_point_per_dollar_lable', empty($app_config['lang']['redeem_point_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['redeem_point_per_dollar_lable']));
     2950                WC()->session->set('gr_redeem_point_product_per_dollar_lable', empty($app_config['lang']['redeem_point_product_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['redeem_point_product_per_dollar_lable']));
     2951                WC()->session->set('gr_earn_point_per_dollar', empty($app_config['points']['earn_point_per_dollar']) ? 0 : $app_config['points']['earn_point_per_dollar']);
     2952                WC()->session->set('gr_earn_point_per_dollar_lable', empty($app_config['lang']['earn_point_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['earn_point_per_dollar_lable']));
     2953                WC()->session->set('gr_point_lable', empty($app_config['lang']['point_lable']) ? '' : $app_config['lang']['point_lable']);
     2954                WC()->session->set('gr_points_lable', empty($app_config['lang']['points_lable']) ? '' : $app_config['lang']['points_lable']);
     2955                WC()->session->set('gr_redeem_btn_text', empty($app_config['lang']['redeem_btn_text']) ? '' : $app_config['lang']['redeem_btn_text']);
     2956                WC()->session->set('gr_redeemed_btn_text', empty($app_config['lang']['redeemed_btn_text']) ? '' : $app_config['lang']['redeemed_btn_text']);
     2957                WC()->session->set('gr_redeemed_status_msg', empty($app_config['lang']['redeemed_status_msg']) ? '' : $app_config['lang']['redeemed_status_msg']);
     2958                WC()->session->set('label_redeemed_points', empty($app_config['lang']['label_redeemed_points']) ? '' : $app_config['lang']['label_redeemed_points']);
     2959                WC()->session->set('label_life_time_points', empty($app_config['lang']['label_life_time_points']) ? '' : $app_config['lang']['label_life_time_points']);
     2960                WC()->session->set('label_available_points', empty($app_config['lang']['label_available_points']) ? '' : $app_config['lang']['label_available_points']);
     2961                WC()->session->set('error_more_points_required', empty($app_config['lang']['error_more_points_required']) ? '' : $app_config['lang']['error_more_points_required']);
     2962                WC()->session->set('label_exclusion_points', empty($app_config['lang']['label_exclusion_points']) ? '' : $app_config['lang']['label_exclusion_points']);
     2963                WC()->session->set('label_total_points', empty($app_config['lang']['label_total_points']) ? '' : $app_config['lang']['label_total_points']);
     2964                WC()->session->set('no_records_found', empty($app_config['lang']['no_records_found']) ? '' : $app_config['lang']['no_records_found']);
     2965                WC()->session->set('gr_loyalty_menu_name', appsmav_stripslashes($app_config['lang']['loyalty_menu_name']));
     2966                WC()->session->set('gr_loyalty_date_start', empty($app_config['loyalty']['date_start']) ? 0 : $app_config['loyalty']['date_start']);
     2967                WC()->session->set('gr_loyalty_date_end', empty($app_config['loyalty']['date_end']) ? 0 : $app_config['loyalty']['date_end']);
     2968                WC()->session->set('gr_loyalty_timezone', empty($app_config['loyalty']['timezone']) ? 'America/Chicago' : $app_config['loyalty']['timezone']);
     2969                WC()->session->set('gr_loyalty_is_open', empty($app_config['loyalty']['is_open']) ? 0 : $app_config['loyalty']['is_open']);
     2970                WC()->session->set('gr_global_review_enabled', empty($app_config['reviews']['global_review_enabled']) ? 0 : $app_config['reviews']['global_review_enabled']);
     2971                WC()->session->set('gr_global_review_points', empty($app_config['reviews']['global_review_points']) ? 0 : $app_config['reviews']['global_review_points']);
     2972                WC()->session->set('gr_global_review_lable_enabled', empty($app_config['reviews']['global_review_lable_enabled']) ? 0 : $app_config['reviews']['global_review_lable_enabled']);
     2973                WC()->session->set('gr_global_review_lable', empty($app_config['reviews']['global_review_lable']) ? '' : $app_config['reviews']['global_review_lable']);
    29072974                WC()->session->set('gr_restricted_user_roles', empty($app_config['points']['gr_restricted_user_roles'])?array():$app_config['points']['gr_restricted_user_roles'] );
    29082975                WC()->session->set('gr_roles_restrict_type', empty($app_config['points']['gr_roles_restrict_type'])?'restrict':$app_config['points']['gr_roles_restrict_type'] );
     
    29182985                WC()->session->set('gr_pay_exclude_categories', empty($app_config['points']['gr_pay_exclude_categories'])?array():$app_config['points']['gr_pay_exclude_categories'] );
    29192986                WC()->session->set('gr_pay_redeem_restrict_terms', empty($app_config['points']['gr_pay_redeem_restrict_terms'])?'':$app_config['points']['gr_pay_redeem_restrict_terms'] );
    2920                 WC()->session->set('gr_label_redeem_restriction_apply', empty($app_config['lang']['gr_label_redeem_restriction_apply'])?'':stripslashes($app_config['lang']['gr_label_redeem_restriction_apply']) );
    2921                 WC()->session->set('gr_btn_redeem_confirm', empty($app_config['lang']['gr_btn_redeem_confirm'])?'':stripslashes($app_config['lang']['gr_btn_redeem_confirm']) );
    2922                 WC()->session->set('gr_redeem_extra_point_info', empty($app_config['lang']['gr_redeem_extra_point_info'])?'':stripslashes($app_config['lang']['gr_redeem_extra_point_info']) );
     2987                WC()->session->set('gr_label_redeem_restriction_apply', empty($app_config['lang']['gr_label_redeem_restriction_apply'])?'':appsmav_stripslashes($app_config['lang']['gr_label_redeem_restriction_apply']) );
     2988                WC()->session->set('gr_btn_redeem_confirm', empty($app_config['lang']['gr_btn_redeem_confirm'])?'':appsmav_stripslashes($app_config['lang']['gr_btn_redeem_confirm']) );
     2989                WC()->session->set('gr_redeem_extra_point_info', empty($app_config['lang']['gr_redeem_extra_point_info'])?'':appsmav_stripslashes($app_config['lang']['gr_redeem_extra_point_info']) );
    29232990                WC()->session->set('gr_pbp_auto_apply', empty($app_config['points']['gr_pbp_auto_apply'])?0:$app_config['points']['gr_pbp_auto_apply'] );
    29242991                WC()->session->set('gr_earn_exclude_products', empty($app_config['points']['gr_earn_exclude_products'])?'':$app_config['points']['gr_earn_exclude_products'] );
     
    30573124                                            'gr_label_redeem_restriction_apply' => $ret['gr_label_redeem_restriction_apply'],
    30583125                                            'gr_btn_redeem_confirm' => $ret['gr_btn_redeem_confirm'],
    3059                                             'loyalty_menu_name' =>  empty($ret['loyalty_menu_name']) ? 'GR Loyalty' : stripslashes($ret['loyalty_menu_name'])
     3126                                            'loyalty_menu_name' =>  empty($ret['loyalty_menu_name']) ? 'GR Loyalty' : appsmav_stripslashes($ret['loyalty_menu_name'])
    30603127                                        ),
    30613128                                        'reviews' => array(
     
    34723539                {
    34733540                    $blocked_roles = array_intersect ($roles, $app_config['points']['gr_restricted_user_roles']);
    3474                     if ($restrict_type == 'restrict' && !empty($blocked_roles) && count($blocked_roles) > 0)
     3541                    if ($restrict_type == 'restrict' && !empty($blocked_roles) && (is_array($blocked_roles) || $blocked_roles instanceof Countable) && count($blocked_roles) > 0)
    34753542                        $is_restricted = true;
    3476                     else if ($restrict_type == 'allow' && empty($blocked_roles) && count($blocked_roles) == 0)
     3543                    else if ($restrict_type == 'allow' && empty($blocked_roles) && (is_array($blocked_roles) || $blocked_roles instanceof Countable) && count($blocked_roles) == 0)
    34773544                        $is_restricted = true;
    34783545                }
     
    35013568                {
    35023569                    $app_config = gr_get_app_config();
    3503                     $ex_products = empty($app_config['points']['gr_pay_exclude_products']) ? array() : explode(',', $app_config['points']['gr_pay_exclude_products']);
    3504                     $ex_category = empty($app_config['points']['gr_pay_exclude_categories']) ? array() : explode(',', $app_config['points']['gr_pay_exclude_categories']);
     3570                    $ex_products = empty($app_config['points']['gr_pay_exclude_products']) ? array() : appsmav_explode(',', $app_config['points']['gr_pay_exclude_products']);
     3571                    $ex_category = empty($app_config['points']['gr_pay_exclude_categories']) ? array() : appsmav_explode(',', $app_config['points']['gr_pay_exclude_categories']);
    35053572
    35063573                    // Check this product is restricted
     
    38083875
    38093876                    // Check the user applied their own referral code
    3810                     if (!empty(WC()->session) && strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == strtolower($coupon_code))
     3877                    if (!empty(WC()->session) && appsmav_strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == appsmav_strtolower($coupon_code))
    38113878                        return false;
    38123879
     
    38543921
    38553922                        // Check the user applied their own referral code
    3856                         if (!empty(WC()->session) && strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == strtolower($coupon_code)) {
     3923                        if (!empty(WC()->session) && appsmav_strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == appsmav_strtolower($coupon_code)) {
    38573924                            wc_add_notice(__("Coupon is not valid."), 'error');
    38583925                            return false;
     
    38693936
    38703937                // Validate the points availabe if "pay by points" applied
    3871                 if(!empty(WC()->session) && WC()->session->get('gr_user_applied_discount') > 0)
     3938                if(!empty(WC()->session) && WC()->session->get('gr_user_applied_discount', 0) > 0)
    38723939                {
    38733940
     
    39113978                    ) );
    39123979
    3913                     if (count($customer_orders) > 0)  {
     3980                    if ((is_array($customer_orders) || $customer_orders instanceof Countable) && count($customer_orders) > 0)  {
    39143981                        return TRUE;
    39153982                    }
     
    39263993                        'numberposts' => -1
    39273994                    ));
    3928                     if (count($customer_orders) > 0)  {
     3995                    if ((is_array($customer_orders) || $customer_orders instanceof Countable) && count($customer_orders) > 0)  {
    39293996                        return TRUE;
    39303997                    }
     
    39654032            // Possibly do additional admin_init tasks
    39664033        }// END public static function activate
     4034
     4035        /**
     4036         * Sanitize refund data to handle WC_DateTime objects and other non-serializable data
     4037         */
     4038        public static function sanitize_refund_data_for_api($data) {
     4039            if (is_array($data)) {
     4040                foreach ($data as $key => $value) {
     4041                    if (is_object($value)) {
     4042                        // Handle WC_DateTime objects
     4043                        if (is_a($value, 'WC_DateTime')) {
     4044                            $data[$key] = $value->format('c'); // ISO 8601 format
     4045                        }
     4046                        // Handle other WooCommerce objects
     4047                        elseif (method_exists($value, 'get_data')) {
     4048                            $data[$key] = self::sanitize_refund_data_for_api($value->get_data());
     4049                        }
     4050                        // Handle other objects by converting to string
     4051                        else {
     4052                            $data[$key] = (string) $value;
     4053                        }
     4054                    }
     4055                    elseif (is_array($value)) {
     4056                        $data[$key] = self::sanitize_refund_data_for_api($value);
     4057                    }
     4058                }
     4059            }
     4060            return $data;
     4061        }
    39674062    }// END class GR_Connect
    39684063} // END if(!class_exists('GR_Connect'))
     4064
     4065/**
     4066 * Wrapper functions for PHP 8.1+ compatibility
     4067 * Handles null values to prevent deprecation warnings
     4068 * Compatible with PHP 5.4 to 8.4
     4069 */
     4070
     4071 if (!function_exists('appsmav_stripslashes')) {
     4072    /**
     4073     * Wrapper for stripslashes() that handles null values
     4074     * @param mixed $value The value to strip slashes from
     4075     * @return string The value with slashes stripped, or empty string if null
     4076     */
     4077    function appsmav_stripslashes($value) {
     4078        if (is_null($value) || !is_string($value)) {
     4079            return '';
     4080        }
     4081        return stripslashes($value);
     4082    }
     4083}
     4084
     4085if (!function_exists('appsmav_strtolower')) {
     4086    /**
     4087     * Wrapper for strtolower() that handles null values
     4088     * @param mixed $value The value to convert to lowercase
     4089     * @return string The lowercase string, or empty string if null
     4090     */
     4091    function appsmav_strtolower($value) {
     4092        if (is_null($value) || !is_string($value)) {
     4093            return '';
     4094        }
     4095        return strtolower($value);
     4096    }
     4097}
     4098
     4099if (!function_exists('appsmav_strtoupper')) {
     4100    /**
     4101     * Wrapper for strtoupper() that handles null values
     4102     * @param mixed $value The value to convert to uppercase
     4103     * @return string The uppercase string, or empty string if null
     4104     */
     4105    function appsmav_strtoupper($value) {
     4106        if (is_null($value) || !is_string($value)) {
     4107            return '';
     4108        }
     4109        return strtoupper($value);
     4110    }
     4111}
     4112
     4113if (!function_exists('appsmav_strlen')) {
     4114    /**
     4115     * Wrapper for strlen() that handles null values
     4116     * @param mixed $value The value to get length of
     4117     * @return int The string length, or 0 if null
     4118     */
     4119    function appsmav_strlen($value) {
     4120        if (is_null($value) || !is_string($value)) {
     4121            return 0;
     4122        }
     4123        return strlen($value);
     4124    }
     4125}
     4126
     4127if (!function_exists('appsmav_trim')) {
     4128    /**
     4129     * Wrapper for trim() that handles null values
     4130     * @param mixed $value The value to trim
     4131     * @return string The trimmed string, or empty string if null
     4132     */
     4133    function appsmav_trim($value) {
     4134        if (is_null($value) || !is_string($value)) {
     4135            return '';
     4136        }
     4137        return trim($value);
     4138    }
     4139}
     4140
     4141if (!function_exists('appsmav_explode')) {
     4142    /**
     4143     * Wrapper for explode() that handles null/empty values
     4144     * @param string $separator The boundary string
     4145     * @param mixed $string The input string
     4146     * @param int $limit Maximum number of elements (optional)
     4147     * @return array Array of strings, or empty array if input is null/empty
     4148     */
     4149    function appsmav_explode($separator, $string, $limit = PHP_INT_MAX) {
     4150        if (is_null($string) || !is_string($string) || $string === '') {
     4151            return array();
     4152        }
     4153        if ($limit === PHP_INT_MAX) {
     4154            return explode($separator, $string);
     4155        }
     4156        return explode($separator, $string, $limit);
     4157    }
     4158}
     4159
     4160if (!function_exists('appsmav_strstr')) {
     4161    /**
     4162     * Wrapper for strstr() that handles null values
     4163     * @param mixed $haystack The input string
     4164     * @param mixed $needle The string to search for
     4165     * @param bool $before_needle Return part before needle (optional)
     4166     * @return string|false The portion of string, or false if needle is not found
     4167     */
     4168    function appsmav_strstr($haystack, $needle, $before_needle = false) {
     4169        if (is_null($haystack) || !is_string($haystack)) {
     4170            return false;
     4171        }
     4172        if (is_null($needle)) {
     4173            return false;
     4174        }
     4175        return strstr($haystack, $needle, $before_needle);
     4176    }
     4177
     4178    /**
     4179     * Wrapper for substr() that handles null values
     4180     * @param mixed $string The input string
     4181     * @param int $offset The starting position
     4182     * @param int|null $length The maximum length
     4183     * @return string The substring or empty string if null
     4184     */
     4185    function appsmav_substr($string, $offset, $length = null) {
     4186        if (is_null($string) || !is_string($string)) {
     4187            return '';
     4188        }
     4189        return $length === null ? substr($string, $offset) : substr($string, $offset, $length);
     4190    }
     4191
     4192    /**
     4193     * Wrapper for str_replace() that handles null values
     4194     * @param mixed $search The value being searched for
     4195     * @param mixed $replace The replacement value
     4196     * @param mixed $subject The string or array being searched and replaced on
     4197     * @return mixed The result string or array
     4198     */
     4199    function appsmav_str_replace($search, $replace, $subject) {
     4200        if (is_null($subject)) {
     4201            return '';
     4202        }
     4203        return str_replace($search, $replace, $subject);
     4204    }
     4205
     4206    /**
     4207     * Wrapper for preg_match() that handles null values
     4208     * @param string $pattern The pattern to search for
     4209     * @param mixed $subject The input string
     4210     * @param array|null $matches Array to store matches
     4211     * @return bool|int Returns 1 if pattern matches, 0 if not, false on error
     4212     */
     4213    function appsmav_preg_match($pattern, $subject, &$matches = null) {
     4214        if (is_null($subject) || !is_string($subject)) {
     4215            return false;
     4216        }
     4217        return $matches === null ? preg_match($pattern, $subject) : preg_match($pattern, $subject, $matches);
     4218    }
     4219}
     4220
     4221if (!function_exists('appsmav_get_parent_id')) {
     4222    /**
     4223     * Backward compatible get_parent_id for WC < 3.0 and WC >= 3.0
     4224     */
     4225    function appsmav_get_parent_id($object) {
     4226        if (empty($object)) {
     4227            return 0;
     4228        }
     4229        if (method_exists($object, 'get_parent_id')) {
     4230            return $object->get_parent_id();  // WC 3.0+
     4231        }
     4232        if (isset($object->post->post_parent)) {
     4233            return $object->post->post_parent;  // WC < 3.0
     4234        }
     4235        return 0;
     4236    }
     4237}
    39694238
    39704239if(class_exists('GR_Connect'))
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-api.php

    r3269635 r3386951  
    319319        {
    320320            $cat_args = array(
     321                'taxonomy'   => 'product_cat',
    321322                'orderby'    => 'name',
    322323                'order'      => 'asc',
    323324                'hide_empty' => false,
    324325            );
    325             $categories = get_terms( 'product_cat', $cat_args );
     326            $categories = get_terms( $cat_args );
    326327
    327328            $data = array(
     
    357358            }
    358359
    359             if (empty($_POST['first_name']) || strlen($_POST['first_name']) > 50) {
     360            if (empty($_POST['first_name']) || appsmav_strlen($_POST['first_name']) > 50) {
    360361                throw new Exception("Invalid first name");
    361362            }
    362363
    363             if (!empty($_POST['last_name']) && strlen($_POST['last_name']) > 50) {
     364            if (!empty($_POST['last_name']) && appsmav_strlen($_POST['last_name']) > 50) {
    364365                throw new Exception("Invalid last name");
    365366            }
     
    452453                    foreach($coupons_data as $item_data)
    453454                    {
    454                         $coupons[] = [
    455                             'code' => $item_data['code'],
    456                             'discount_tax' => $item_data['discount_tax'],
    457                             'discount' => $item_data['discount']
    458                         ];
     455                        // Backward compatibility: Use method calls for WC 3.0+, array access for older versions
     456                        if(version_compare( WC_VERSION, '3.0', '>=' ))
     457                        {
     458                            $coupons[] = [
     459                                'code' => $item_data->get_code(),
     460                                'discount_tax' => $item_data->get_discount_tax(),
     461                                'discount' => $item_data->get_discount()
     462                            ];
     463                        }
     464                        else
     465                        {
     466                            $coupons[] = [
     467                                'code' => $item_data['code'],
     468                                'discount_tax' => $item_data['discount_tax'],
     469                                'discount' => $item_data['discount']
     470                            ];
     471                        }
    459472                    }
    460473                }
     
    510523            $data = array(
    511524                'error' => 0,
    512                 'order' => $order->get_data(),
     525                'order' => GR_Connect::sanitize_refund_data_for_api($order->get_data()),
    513526                'currency' => $curShop,
    514527                'total' => $total,
     
    528541            $param['line_items'] = [];
    529542            foreach ($order->get_items('line_item') as $key => $item) {
    530                 $param['line_items'][] = $item->get_data();
     543                $param['line_items'][] = GR_Connect::sanitize_refund_data_for_api($item->get_data());
    531544            }
    532545
    533546            $refundData = array();
    534             foreach ($order->get_refunds() as $key => $refund) {
    535                 $refundData[$key]['refund'] = $refund->get_data();
    536                 foreach ($refund->get_items() as $item_id => $item) {
    537                     $refundData[$key]['line_items'][$item_id] = $item->get_data();
     547            $refunds = $order->get_refunds();
     548            if (!empty($refunds) && is_array($refunds)) {
     549                foreach ($refunds as $key => $refund) {
     550                    if (empty($refund) || !is_object($refund)) {
     551                        continue;
     552                    }
     553                    $refundData[$key]['refund'] = GR_Connect::sanitize_refund_data_for_api($refund->get_data());
     554                    $refund_items = $refund->get_items();
     555                    if (!empty($refund_items) && is_array($refund_items)) {
     556                        foreach ($refund_items as $item_id => $item) {
     557                            if (empty($item) || !is_object($item)) {
     558                                continue;
     559                            }
     560                            $refundData[$key]['line_items'][$item_id] = GR_Connect::sanitize_refund_data_for_api($item->get_data());
     561                        }
     562                    }
    538563                }
    539564            }
     
    563588
    564589            $product_ids1 = sanitize_text_field($_POST['product_ids']);
    565             $product_ids = explode(',', $product_ids1);
     590            $product_ids = appsmav_explode(',', $product_ids1);
    566591
    567592            foreach($product_ids as $product_id) {
     
    624649                    'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
    625650                    'currency' => $order->get_currency(),
    626                     'coupon' => $order->get_used_coupons(),
     651                    'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(),
    627652                    'status' => $order->get_status()
    628653                );
     
    904929            );
    905930
    906             $id = wp_insert_post( $new_page, $wp_error = false );
     931            $id = wp_insert_post( $new_page, true );
    907932
    908933            if(is_wp_error($id)) {
     
    957982            }
    958983
    959             $id = wp_update_post( $params, $wp_error = true );
     984            $id = wp_update_post( $params, true );
    960985
    961986            if(is_wp_error($id))
     
    10901115
    10911116            $coupon = new WC_Coupon($coupon_code);
    1092             if (!empty($coupon->id))
     1117            $coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0);
     1118            if (!empty($coupon_id))
    10931119            {
    10941120                $data['msg'] = 'Yes';
     
    11251151
    11261152            $coupon = new WC_Coupon($new_coupon_code);
    1127             if (!empty($coupon->id))
     1153            $new_coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0);
     1154            if (!empty($new_coupon_id))
    11281155                throw new Exception('Coupon code already exists. Please check and enter a new unique coupon code');
    11291156
    11301157            $coupon = new WC_Coupon($old_coupon_code);
    1131             if (empty($coupon->id))
     1158            $old_coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0);
     1159            if (empty($old_coupon_id))
    11321160                throw new Exception('Coupon code not found. Please check and try again');
    11331161
    11341162            // Update coupon details starts
    11351163            $my_post = array(
    1136                 'ID'         => $coupon->id,
     1164                'ID'         => $old_coupon_id,
    11371165                'post_title' => $new_coupon_code
    11381166            );
     
    11691197            $coupon_code = sanitize_text_field($_POST['coupon_code']);
    11701198            $coupon = new WC_Coupon($coupon_code);
    1171             if (!empty($coupon->id))
     1199            $coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0);
     1200            if (!empty($coupon_id))
    11721201            {
    11731202                $validate_usage = empty($_POST['validate_usage']) ? 0 : sanitize_text_field($_POST['validate_usage']);
    1174                 if(!empty($validate_usage) && (!isset($coupon->usage_count) || $coupon->usage_count != 0))
     1203                $usage_count = is_callable(array($coupon, 'get_usage_count')) ? $coupon->get_usage_count() : (isset($coupon->usage_count) ? $coupon->usage_count : 0);
     1204                if(!empty($validate_usage) && $usage_count != 0)
    11751205                {
    1176                     $data['id'] = $coupon->id;
    1177                     $data['usage_count'] = $coupon->usage_count;
     1206                    $data['id'] = $coupon_id;
     1207                    $data['usage_count'] = $usage_count;
    11781208                    throw new Exception('Coupon code already used');
    11791209                }
    11801210
    1181                 $post_id = wp_delete_post($coupon->id, TRUE);
     1211                $post_id = wp_delete_post($coupon_id, TRUE);
    11821212                if ( is_wp_error( $post_id ) ) {
    11831213                    throw new Exception( $post_id->get_error_message());
     
    12301260
    12311261            $order_ids = sanitize_text_field($_POST['order_ids']);
    1232             $order_ids = explode(',', $order_ids);
     1262            $order_ids = appsmav_explode(',', $order_ids);
    12331263
    12341264            foreach( $order_ids as $order_id ){
     
    12501280                    'billing_email' => $order->get_billing_email(),
    12511281                    'currency' => $order->get_currency(),
    1252                     'coupon' => $order->get_used_coupons(),
     1282                    'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(),
    12531283                    'date_created' => $order->get_date_created()->format('c'),
    12541284                    'status' => $order->get_status()
     
    12891319
    12901320            if (!empty($order_status)) {
    1291                 $order_status = explode(',', $order_status);
     1321                $order_status = appsmav_explode(',', $order_status);
    12921322            } else {
    12931323                $order_status = array( 'wc-completed','wc-processing' );
     
    13151345                    'billing_email' => $order->get_billing_email(),
    13161346                    'currency' => $order->get_currency(),
    1317                     'coupon' => $order->get_used_coupons(),
     1347                    'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(),
    13181348                    'date_created' => $order->get_date_created()->format('c'),
    13191349                    'status' => $order->get_status()
     
    13841414            );
    13851415
    1386             $assoc_args['product_ids'] = !empty($assoc_args['product_ids']) ? json_decode($assoc_args['product_ids'], true) : [];
    1387             $assoc_args['exclude_product_ids'] = !empty($assoc_args['exclude_product_ids']) ? json_decode($assoc_args['exclude_product_ids'], true) : [];
    1388             $assoc_args['product_category_ids'] = !empty($assoc_args['product_category_ids']) ? json_decode($assoc_args['product_category_ids'], true) : [];
    1389             $assoc_args['exclude_product_category_ids'] = !empty($assoc_args['exclude_product_category_ids']) ? json_decode($assoc_args['exclude_product_category_ids'], true) : [];
    1390             $assoc_args['customer_emails'] = !empty($assoc_args['customer_emails']) ? json_decode(stripslashes($assoc_args['customer_emails']), true) : [];
     1416            // Safe JSON decode with error handling
     1417            $assoc_args['product_ids'] = $this->safe_json_decode(isset($assoc_args['product_ids']) ? $assoc_args['product_ids'] : '');
     1418            $assoc_args['exclude_product_ids'] = $this->safe_json_decode(isset($assoc_args['exclude_product_ids']) ? $assoc_args['exclude_product_ids'] : '');
     1419            $assoc_args['product_category_ids'] = $this->safe_json_decode(isset($assoc_args['product_category_ids']) ? $assoc_args['product_category_ids'] : '');
     1420            $assoc_args['exclude_product_category_ids'] = $this->safe_json_decode(isset($assoc_args['exclude_product_category_ids']) ? $assoc_args['exclude_product_category_ids'] : '');
     1421            $assoc_args['customer_emails'] = $this->safe_json_decode(appsmav_stripslashes(isset($assoc_args['customer_emails']) ? $assoc_args['customer_emails'] : ''));
    13911422
    13921423            if(!empty($_POST['usage_limit_per_user']))
     
    14721503            );
    14731504
    1474             $id = wp_insert_post($new_coupon, $wp_error = false);
     1505            $id = wp_insert_post($new_coupon, true);
    14751506
    14761507            if(is_wp_error($id))
     
    15021533            if (!empty($_POST['custom_attributes']))
    15031534            {
    1504                 $custom_attributes = stripslashes(sanitize_text_field($_POST['custom_attributes']));
     1535                $custom_attributes = appsmav_stripslashes(sanitize_text_field($_POST['custom_attributes']));
    15051536                $custom_attributes = json_decode($custom_attributes, true);
    15061537                if (!empty($custom_attributes) && is_array($custom_attributes))
     
    15381569        return $result;
    15391570    }
     1571
     1572    /**
     1573     * Safe JSON decode with error handling
     1574     *
     1575     * @param string $json_string The JSON string to decode
     1576     * @return array Returns decoded array or empty array on error
     1577     */
     1578    private function safe_json_decode($json_string) {
     1579        if (empty($json_string)) {
     1580            return array();
     1581        }
     1582       
     1583        $decoded = json_decode($json_string, true);
     1584       
     1585        if (json_last_error() !== JSON_ERROR_NONE) {           
     1586            return array();
     1587        }
     1588       
     1589        return is_array($decoded) ? $decoded : array();
     1590    }
    15401591}
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-checkout.php

    r3207752 r3386951  
    5959     */
    6060    public function coupon_label( $label ) {
    61         if ( strstr( strtoupper( $label ), 'WC_POINTS_REDEMPTION' ) ) {
     61        if ( appsmav_strstr( appsmav_strtoupper( $label ), 'WC_POINTS_REDEMPTION' ) ) {
    6262            $label = esc_html( __( 'Points redemption', 'woocommerce-points-and-rewards' ) );
    6363        }
     
    7474
    7575        foreach ( WC()->cart->get_applied_coupons() as $code ) {
    76             if ( strstr( $code, 'wc_points_redemption_' ) ) {
     76            if ( appsmav_strstr( $code, 'wc_points_redemption_' ) ) {
    7777                $points[] = $code;
    7878            } else {
     
    8989     */
    9090    public function discount_removed( $coupon_code ) {
    91         if ( ! strstr( $coupon_code, 'wc_points_redemption_' ) ) {
     91        if ( ! appsmav_strstr( $coupon_code, 'wc_points_redemption_' ) ) {
    9292            return;
    9393        }
     
    604604            $existing_discount_amounts = version_compare( WC_VERSION, '3.0.0', '<' )
    605605                ? WC()->cart->discount_total
    606                 : WC()->cart->get_cart_discount_total();
     606                : ( version_compare( WC_VERSION, '3.7', '<' )
     607                    ? WC()->cart->get_cart_discount_total()
     608                    : WC()->cart->get_discount_total() );
    607609        }
    608610
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-disount.php

    r1913442 r3386951  
    4444
    4545    public function get_discount_data( $data, $code ) {
    46         if ( strtolower( $code ) != $this->get_discount_code() ) {
     46        if ( appsmav_strtolower( $code ) != $this->get_discount_code() ) {
    4747            return $data;
    4848        }
     
    9595        $discount = 0;
    9696        foreach ( WC()->cart->get_coupons() as $coupon ) {
    97             if ( strtolower( $coupon->get_code() ) === $this->get_discount_code() || ! $coupon->is_type( 'fixed_product' ) ) {
     97            if ( appsmav_strtolower( $coupon->get_code() ) === $this->get_discount_code() || ! $coupon->is_type( 'fixed_product' ) ) {
    9898                continue;
    9999            }
     
    115115
    116116    public function get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
    117             if ( strtolower( $coupon->get_code() ) != $this->get_discount_code() ) {
     117            if ( appsmav_strtolower( $coupon->get_code() ) != $this->get_discount_code() ) {
    118118                return $discount;
    119119            }
     
    176176    public static function get_discount_code() {
    177177        if ( WC()->session !== null ) {
    178             return WC()->session->get( 'gratisfaction_discount_code' );
     178            return WC()->session->get( 'gratisfaction_discount_code', '' );
    179179        }
    180180    }
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-http-request-handler.php

    r3212496 r3386951  
    2727
    2828    private $_error_info = null;
     29
     30    private $_http_code = null;
    2931
    3032    public function setUrl($url)
     
    8284        $this->_info = '';
    8385        $this->_error_info = null;
     86        $this->_http_code = null;
    8487        $this->_headers = array();
    8588
     
    106109
    107110                $this->_resp = $response['body'];
     111                $this->_http_code = wp_remote_retrieve_response_code($response);
    108112            }
    109113            else {
     
    114118
    115119                $this->_resp = $response['body'];
     120                $this->_http_code = wp_remote_retrieve_response_code($response);
    116121
    117122            }
     
    140145        return $this->_error_info;
    141146    }
     147
     148    public function getHttpCode()
     149    {
     150        return $this->_http_code;
     151    }
    142152}
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-product.php

    r1913442 r3386951  
    273273                $variable_points = array();
    274274
    275                 if ( count( $product->get_children() ) > 0 ) {
     275                $children = $product->get_children();
     276                if ( (is_array($children) || $children instanceof Countable) && count( $children ) > 0 ) {
    276277                    foreach ( $product->get_children() as $child ) {
    277278                        $earned = get_post_meta( $child, '_wc_points_earned', true );
     
    282283                }
    283284
    284                 if ( count( $variable_points ) > 0 ) {
     285                if ( (is_array($variable_points) || $variable_points instanceof Countable) && count( $variable_points ) > 0 ) {
    285286                    $wc_min_points_earned = min( $variable_points );
    286287                }
     
    448449        $category_points_array = array();
    449450
    450         if ( $category_points_data && count( $category_points_data ) > 0 ) {
     451        if ( $category_points_data && (is_array($category_points_data) || $category_points_data instanceof Countable) && count( $category_points_data ) > 0 ) {
    451452            foreach ( $category_points_data as $category ) {
    452453                $category_points_array[ $category->category_id ] = $category->points;
     
    604605        $category_discount_array = array();
    605606
    606         if ( $category_discount_data && count( $category_discount_data ) > 0 ) {
     607        if ( $category_discount_data && (is_array($category_discount_data) || $category_discount_data instanceof Countable) && count( $category_discount_data ) > 0 ) {
    607608            foreach ( $category_discount_data as $category ) {
    608609                $category_discount_array[ $category->category_id ] = $category->max_discount;
  • gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/readme.txt

    r3362178 r3386951  
    55Requires at least: 3.0.1
    66Tested up to: 6.8
    7 Stable tag: 4.5.1
     7Stable tag: 4.5.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    254254
    255255== Changelog ==
     256= 4.5.2 =
     257PHP version 8.4 release compatibility
     258
    256259= 4.5.1 =
    257260WordPress version 6.8 release compatibility
     
    617620
    618621== Upgrade Notice ==
    619 = 4.5.1 =
    620 WordPress version 6.8 release compatibility
     622= 4.5.2 =
     623PHP version 8.4 release compatibility
Note: See TracChangeset for help on using the changeset viewer.