Plugin Directory

Changeset 3234819


Ignore:
Timestamp:
02/04/2025 02:50:13 PM (5 weeks ago)
Author:
sarankumar
Message:

removed unwanted codes and optimised

Location:
wc-messaging/trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • wc-messaging/trunk/admin/abandoned/class-wcm-abandoned-checker.php

    r3223474 r3234819  
    6565                } else {
    6666                    // error logging if failed to initialise or get the order meta of woom_abandonment_order_created
    67                     error_log(print_r(__("Failed to create meta data of woom_abandonment_order_created", 'wc-messaging'), true));
     67                    // error_log(print_r(__("Failed to create meta data of woom_abandonment_order_created", 'wc-messaging'), true));
    6868                }
    6969            }
  • wc-messaging/trunk/admin/class-wc-messaging-admin.php

    r3223474 r3234819  
    7272         * class.
    7373         */
    74         wp_enqueue_style('chosen', 'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css', array(), '1.8.7', 'all');
     74        wp_enqueue_style('chosen', plugin_dir_url(__FILE__) . 'packages/chosen/chosen.min.css', array(), '1.8.7', 'all');
    7575        wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wc-messaging-admin.css', array(), $this->version, 'all');
    7676        if (!wp_style_is('sgits-admin-common-css', 'enqueued')) {
     
    9797         * class.
    9898         */
    99         wp_enqueue_script('chosen', 'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js', array('jquery'), '1.8.7', true);
     99        wp_enqueue_script('chosen', plugin_dir_url(__FILE__) . 'packages/chosen/chosen.jquery.min.js', array('jquery'), '1.8.7', true);
    100100        wp_enqueue_script($this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'js/wc-messaging-admin.js', array('jquery'), $this->version, true);
    101101        wp_localize_script($this->plugin_name . '-admin', 'woom_ajax', array('url' => admin_url('admin-ajax.php'), 'woom_post_nonce' => wp_create_nonce('woom-ajax-post')));
     
    129129    {
    130130        if ($this->woom_checkbox_valid(get_option('woom_enable_report_error'))) {
    131             error_log(print_r($error, true));
     131            // error_log(print_r($error, true));
    132132        }
    133133    }
     
    824824            $woom_sidebar = '';
    825825            if (isset($field['sidebar'])) {
    826                 $woom_sidebar = wp_kses(apply_filters('woom_settings_sidebar', $field['sidebar']), array(
    827                     'div' => array('class' => array()),
    828                     'p' => array('class' => array()),
    829                     'a' => array('class' => array()),
    830                     'ul' => array(
    831                         'class' => array()
    832                     ),
    833                     'li' => array('class' => array()),
    834                     'a' => array(
    835                         'href' => array(),
    836                         'target' => array(),
    837                         'class' => array(),
    838                     ),
    839                     'br' => array(),
    840                 ));
     826                $woom_sidebar = apply_filters('woom_settings_sidebar', $field['sidebar']);
    841827            }
    842828            $description = '';
     
    862848                    ))
    863849                ),
    864                 $woom_sidebar
     850                wp_kses($woom_sidebar, array(
     851                    'div' => array('class' => array()),
     852                    'p' => array('class' => array()),
     853                    'a' => array('class' => array()),
     854                    'ul' => array(
     855                        'class' => array()
     856                    ),
     857                    'li' => array('class' => array()),
     858                    'a' => array(
     859                        'href' => array(),
     860                        'target' => array(),
     861                        'class' => array(),
     862                    ),
     863                    'br' => array(),
     864                ))
    865865            );
    866866        }
     
    901901                        <?php
    902902                        if (isset($fields['name'])) {
    903                             esc_html_e($fields['name']);
     903                            echo esc_html($fields['name']);
    904904                        }
    905905
    906906
    907907                        if ($fields['desc_tip'] === true) {
    908                             echo wc_help_tip($fields['desc']);
     908                            echo wp_kses(wc_help_tip($fields['desc']), array(
     909                                'div' => array('class' => array()),
     910                                'p' => array('class' => array()),
     911                                'a' => array(
     912                                    'href' => array(),
     913                                    'target' => array(),
     914                                    'class' => array(),
     915                                )
     916                            ));
    909917                        }
    910918                        ?></th>
    911919                    <td class="forminp forminp-checkbox ">
    912920                        <fieldset>
    913                             <legend class="screen-reader-text"><span><?php esc_html_e($fields['name']); ?></span></legend>
     921                            <legend class="screen-reader-text"><span><?php echo esc_html($fields['name']); ?></span></legend>
    914922                            <label for="woom_abandoned_cart_enable_webhook">
    915923                                <?php
     
    938946                                        ?>
    939947                                            <input
    940                                                 type="<?php esc_attr_e($field['type']); ?>"
    941                                                 name="<?php esc_attr_e($field['id']); ?>"
    942                                                 id="<?php esc_attr_e($field['id']); ?>"
    943                                                 value="<?php esc_attr_e($field_val); ?>">
     948                                                type="<?php echo esc_attr($field['type']); ?>"
     949                                                name="<?php echo esc_attr($field['id']); ?>"
     950                                                id="<?php echo esc_attr($field['id']); ?>"
     951                                                value="<?php echo esc_attr($field_val); ?>">
    944952
    945953                                <?php
     
    14031411            if (wp_verify_nonce(sanitize_key($_POST['data']['woom_nonce']), 'woom-ajax-post')) {
    14041412                $key = sanitize_text_field(sanitize_key($_POST['data']['key']));
    1405                 $key_arr = get_option(sanitize_text_field($_POST['data']['actions_key']), array('action_1'));
    1406                 array_push($key_arr, $key);
    1407                 update_option(sanitize_text_field($_POST['data']['actions_key']), $key_arr);
    1408                 $result = array("status" => 'success', "message" => __('New row added successfully', 'wc-messaging'));
     1413                $actions_key = (!empty(sanitize_text_field(wp_unslash($_POST['data']['actions_key'])))) ? sanitize_text_field(wp_unslash($_POST['data']['actions_key'])) : '';
     1414                if (!empty($actions_key)) {
     1415                    $key_arr = get_option($actions_key, array('action_1'));
     1416                    array_push($key_arr, $key);
     1417                    update_option($actions_key, $key_arr);
     1418                    $result = array("status" => 'success', "message" => __('New row added successfully', 'wc-messaging'));
     1419                } else {
     1420                    $result = array("status" => 'failed', "message" => __('something went wrong', 'wc-messaging'));
     1421                }
    14091422            }
    14101423        endif;
     
    14291442        if (isset($_POST)) :
    14301443            if (wp_verify_nonce(sanitize_key(wp_unslash($_POST['data']['woom_nonce'])), 'woom-ajax-post')) {
    1431                 $actions_container = sanitize_text_field(wp_unslash($_POST['data']['container']));
    1432                 $prefix = sanitize_text_field(wp_unslash($_POST['data']['prefix']));
    1433                 $action_name = sanitize_text_field(wp_unslash($_POST['data']['item']));
    1434                 $woom_trigger_actions = get_option($actions_container, array('action_1'));
    1435 
    1436                 $opts = array('_label', '_enabled', '_template', '_sent_admin', '_header_params', '_body_params', '_remove');
    1437                 foreach ($opts as $opt) {
    1438                     delete_option($prefix . '_' . $action_name . $opt);
    1439                 }
    1440                 update_option($actions_container, array_diff($woom_trigger_actions, array($action_name)));
    1441                 $result = array('status' => 'success', 'message' => "trigger action $action_name removed");
     1444                $actions_container = (!empty(sanitize_text_field(wp_unslash($_POST['data']['container'])))) ? sanitize_text_field(wp_unslash($_POST['data']['container'])) : null;
     1445
     1446                if (!empty($actions_container)) {
     1447                    $prefix = sanitize_text_field(wp_unslash($_POST['data']['prefix']));
     1448                    $action_name = (!empty(sanitize_text_field(wp_unslash($_POST['data']['item'])))) ? sanitize_text_field(wp_unslash($_POST['data']['item'])) : null;
     1449                    $woom_trigger_actions = get_option($actions_container, array('action_1'));
     1450
     1451                    $opts = array('_label', '_enabled', '_template', '_sent_admin', '_header_params', '_body_params', '_remove');
     1452                    foreach ($opts as $opt) {
     1453                        delete_option($prefix . '_' . $action_name . $opt);
     1454                    }
     1455                    update_option($actions_container, array_diff($woom_trigger_actions, array($action_name)));
     1456                    $result = array('status' => 'success', 'message' => "trigger action $action_name removed");
     1457                } else {
     1458                    $result = array('status' => 'error', 'message' => __("Something went wrong", 'wc-messaging'));
     1459                }
    14421460                return wp_send_json($result);
    14431461            }
     
    14601478        return $result;
    14611479    }
    1462 
    1463     /**
    1464      * facilitates the retrieval of specific parameters  for WooCommerce orders.
    1465      *
    1466      * @param string $type
    1467      * @param string $method
    1468      * @since 1.0.0
    1469      */
    1470     function woom_get_mparams($type = "keys", $method = "string", $order = null, $options = '')
    1471     {
    1472         $param_keys = array();
    1473         $param_values = array();
    1474         $additional_params = apply_filters("woom_additional_template_params", array(), $order);
    1475         $params_list = array(
    1476             "site_title" => get_bloginfo('name'),
    1477             "site_address" => get_bloginfo('wpurl'),
    1478             "site_url" => get_bloginfo('url'),
    1479         );
    1480         if ($order === null) {
    1481 
    1482 
    1483             $order_data =
    1484                 array(
    1485                     'order_id' => '',
    1486                     'order_status' => '',
    1487                     'order_prices_include_tax' => '',
    1488                     'order_discount_total' => '',
    1489                     'order_discount_tax' => '',
    1490                     'order_shipping_total' => '',
    1491                     'order_shipping_tax' => '',
    1492                     'order_cart_tax' => '',
    1493                     'order_total' => '',
    1494                     'order_total_tax' => '',
    1495                     'order_customer_id' => '',
    1496                     'order_order_key' => '',
    1497                     'order_billing_full_name' => '',
    1498                     'order_shipping_full_name' => '',
    1499                     'order_billing_first_name' => '',
    1500                     'order_billing_last_name' => '',
    1501                     'order_billing_company' => '',
    1502                     'order_billing_address_1' => '',
    1503                     'order_billing_address_2' => '',
    1504                     'order_billing_city' => '',
    1505                     'order_billing_state' => '',
    1506                     'order_billing_postcode' => '',
    1507                     'order_billing_country' => '',
    1508                     'order_billing_email' => '',
    1509                     'order_billing_phone' => '',
    1510                     'order_shipping_first_name' => '',
    1511                     'order_shipping_last_name' => '',
    1512                     'order_shipping_company' => '',
    1513                     'order_shipping_address_1' => '',
    1514                     'order_shipping_address_2' => '',
    1515                     'order_shipping_city' => '',
    1516                     'order_shipping_state' => '',
    1517                     'order_shipping_postcode' => '',
    1518                     'order_shipping_country' => '',
    1519                     'order_shipping_phone' => '',
    1520                     'order_payment_method' => '',
    1521                     'order_payment_method_title' => '',
    1522                     'order_transaction_id' => '',
    1523                     'order_created_via' => '',
    1524                     'order_number' => '',
    1525                     'order_date_created' => '',
    1526                     'order_date_modified' => '',
    1527                     'order_date_completed' => '',
    1528                     'order_date_paid' => ''
    1529                 );
    1530         } else {
    1531             $order_data = array();
    1532             $order_data_prefix = "order_";
    1533 
    1534             foreach ($order->get_data() as $order_key => $order_val) {
    1535                 if (in_array(gettype($order_val), ['object', 'array'])) {
    1536                     $order_data = $this->get_params_from_object($order_val, $order_data_prefix . $order_key . "_", $order_data);
    1537                 } else {
    1538                     $order_data[$order_data_prefix . $order_key] = $order_val;
    1539                 }
    1540             }
    1541             $order_data['order_billing_full_name'] = $order->get_formatted_billing_full_name();
    1542             $order_data['order_shipping_full_name'] = $order->get_formatted_shipping_full_name();
    1543             if (!empty($order->get_date_created())) {
    1544                 $order_data['order_date_created'] = $order->get_date_created()->date("F j, Y");
    1545             }
    1546             if (!empty($order->get_date_modified())) {
    1547                 $order_data['order_date_modified'] = $order->get_date_modified()->date("F j, Y");
    1548             }
    1549             if (!empty($order->get_date_completed())) {
    1550                 $order_data['order_date_completed'] = $order->get_date_completed()->date("F j, Y");
    1551             }
    1552             if (!empty($order->get_date_paid())) {
    1553                 $order_data['order_date_paid'] = $order->get_date_paid()->date("F j, Y");
    1554             }
    1555         }
    1556         $params_list = array_merge($params_list, $order_data, $additional_params);
    1557         if ($options !== '') {
    1558             $avail_param_list = array();
    1559             if (!is_array($options)) {
    1560                 $options = explode(',', $options);
    1561             }
    1562             foreach ($options as $param) {
    1563                 $param = str_replace(' ', '', $param);
    1564                 $avail_param_list[$param] = $params_list[$param];
    1565             }
    1566             $params_list = $avail_param_list;
    1567         }
    1568         switch ($type) {
    1569             case 'keys':
    1570                 $param_keys = array_keys($params_list);
    1571                 if ($method === 'string') {
    1572                     return implode(", ", $param_keys);
    1573                 }
    1574                 return $param_keys;
    1575                 break;
    1576             case 'values':
    1577                 $param_values = array_values($params_list);
    1578                 if ($method === 'string') {
    1579                     return implode(", ", $param_values);
    1580                 }
    1581                 return $param_values;
    1582                 break;
    1583 
    1584             default:
    1585 
    1586                 if ($method === 'string') {
    1587                     $param = "";
    1588                     foreach ($params_list as $p_key => $p_value) {
    1589                         if ($param !== '') {
    1590                             $param .= ",";
    1591                         }
    1592                         $param .= $p_key . '=' . $p_value;
    1593                     }
    1594                     return $param;
    1595                 }
    1596                 return $params_list;
    1597                 break;
    1598         }
    1599         if ($method === 'string') {
    1600             return implode(", ", $param_values);
    1601         }
    1602         return $param_values;
    1603     }
    1604 
    16051480
    16061481    /**
     
    16321507                    }
    16331508                    if ($this->woom_checkbox_valid(get_option($prefix . '_enabled', 'no'))) {
    1634                         $token = get_option('woom_whatsapp_api', '');
    16351509                        if (!empty(get_option($prefix . '_params', array()))) {
    16361510                            delete_option($prefix . '_params');
     
    18001674                    $contact_numbers[] = str_replace([' ', '+'], '', $order->get_shipping_phone());
    18011675                }
    1802                 do_action('woom_trigger_wa_msg', $order_id, $slug_prefix, array(), array_unique($contact_numbers));
     1676                do_action('woom_trigger_wa_msg', $order_id, $slug_prefix, '', array_unique($contact_numbers));
    18031677                return wp_send_json($result);
    18041678            }
     
    20581932    }
    20591933
    2060 
    2061     function woom_get_whatsapp_template_by_name($template_name = '', $args = array())
    2062     {
    2063         $templates = get_option('woom_wa_templates', array());
    2064         $template = array();
    2065         $templateHTML = '';
    2066         foreach ($templates as $template_key => $template_value) {
    2067             if ($template_value['name'] === $template_name) {
    2068                 if (array_key_exists('header_params_count', $template_value) && $template_value['header_params_count'] > 0) {
    2069                     $header_parameters = array();
    2070 
    2071                     for ($i = 0; $i < $template_value['header_params_count']; $i++) {
    2072                         $header_parameters['{{' . ($i + 1) . '}}'] = array_values($args['header'])[$i];
    2073                     }
    2074                     foreach ($header_parameters as $param_key => $param_val) {
    2075                         $template_value['Header'] = str_replace($param_key, $param_val, $template_value['Header']);
    2076                     }
    2077                 }
    2078                 if (array_key_exists('body_params_count', $template_value) && $template_value['body_params_count'] > 0) {
    2079                     $body_parameters = array();
    2080 
    2081                     for ($i = 0; $i < $template_value['body_params_count']; $i++) {
    2082                         $body_parameters['{{' . ($i + 1) . '}}'] = array_values($args['body'])[$i];
    2083                     }
    2084                     foreach ($body_parameters as $param_key => $param_val) {
    2085                         $template_value['Body'] = str_replace($param_key, $param_val, $template_value['Body']);
    2086                     }
    2087                 }
    2088                 if (array_key_exists('footer_params_count', $template_value) && $template_value['footer_params_count'] > 0) {
    2089                     $footer_parameters = array();
    2090 
    2091                     for ($i = 0; $i < $template_value['footer_params_count']; $i++) {
    2092                         $footer_parameters['{{' . ($i + 1) . '}}'] = array_values($args['footer'])[$i];
    2093                     }
    2094                     foreach ($footer_parameters as $param_key => $param_val) {
    2095                         $template_value['Footer'] = str_replace($param_key, $param_val, $template_value['Footer']);
    2096                     }
    2097                 }
    2098                 $template = $template_value;
    2099             }
    2100         }
    2101         if (count($template) > 0) {
    2102             if (array_key_exists('Header', $template)) {
    2103                 $templateHTML .= sprintf('<h3 class="woom-template-header">%s</h3>', $template['Header']);
    2104             }
    2105             if (array_key_exists('Body', $template)) {
    2106                 $templateHTML .= sprintf('<div class="woom-template-body">%s</div>', $template['Body']);
    2107             }
    2108             if (array_key_exists('Footer', $template)) {
    2109                 $templateHTML .= sprintf('<small class="woom-template-footer">%s</small>', $template['Footer']);
    2110             }
    2111         }
    2112         return $templateHTML;
    2113     }
    21141934    /**
    21151935     *  Callback function to fetch health status and display widget content
     
    23222142        $schedules['every_five_minutes'] = array(
    23232143            'interval'  => 300,
    2324             'display'   => __('Every 5 Minutes', 'wc-messaging-pro')
     2144            'display'   => __('Every 5 Minutes', 'wc-messaging')
    23252145        );
    23262146        return $schedules;
     
    24612281        }
    24622282    }
     2283
     2284    /**
     2285     * Function for deleting system user
     2286     */
     2287    function woom_delete_wa_system_user()
     2288    {
     2289        if (!get_option('wa_system_user_deleted')) {
     2290            $username = 'wa-system-user';
     2291            $user = get_user_by('login', $username);
     2292
     2293            if ($user) {
     2294                wp_delete_user($user->ID);
     2295                delete_option('wa-system-user');
     2296            }
     2297
     2298            // Set an option to ensure it runs only once
     2299            update_option('wa_system_user_deleted', true);
     2300        }
     2301        return;
     2302    }
    24632303}
    24642304?>
  • wc-messaging/trunk/admin/partials/sidebar/premium-features.php

    r3218094 r3234819  
    44}
    55$settings =  array(
    6     'title' => __('Upgrade', 'wc-messaging-pro'),
    7     'description' => __('Get a bundle of features with an upgrade to WC Messaging Pro', 'wc-messaging-pro'),
     6    'title' => __('Upgrade', 'wc-messaging'),
     7    'description' => __('Get a bundle of features with an upgrade to WC Messaging Pro', 'wc-messaging'),
    88    'features' => array(
    99        __('Email support is available exclusively for WC Messaging Pro users', 'wc-messaging'),
  • wc-messaging/trunk/includes/class-wc-messaging-activator.php

    r3040529 r3234819  
    3333    public static function activate()
    3434    {
    35         $username = 'wa-system-user';
    36         if (!username_exists($username)) {
    37             $userData = array(
    38                 'user_login' => $username,
    39                 'first_name' => 'wa-system-user',
    40                 'user_pass' => 'wa-system-user',
    41                 'user_email' => '[email protected]',
    42             );
    43             $system_user = wp_insert_user($userData);
    44             if ($system_user) {
    45                 $user_data = get_user_by('login', $username);
    46                 $user_id = $user_data->ID;
    47                 update_option('wa-system-user', $user_id);
    48             }
    49         }
    5035    }
    5136}
  • wc-messaging/trunk/includes/class-wc-messaging.php

    r3223474 r3234819  
    227227        $this->loader->add_filter('woom_additional_template_params', $plugin_admin, 'woom_abandoned_wa_params', 20, 3);
    228228
     229
     230
     231        //hook for delete existing system user
     232        $this->loader->add_action('admin_init',$plugin_admin, 'woom_delete_wa_system_user',25);
     233
     234
    229235        // auto delete cron callback
    230236        $this->loader->add_action('wcm_delete_coupons_weekly', $plugin_admin, 'delete_abandoned_coupons');
  • wc-messaging/trunk/includes/class-whatsapp.php

    r3217519 r3234819  
    5353        }
    5454
    55 
    56 
    57 
    58         /**
    59          * Send Whatsapp text Message
    60          */
    61 
    62         public  function send_text_message($mobile, $text_message)
    63         {
    64             $mobile = $this->clean_phone_number($mobile);
    65             $wam_id = 0;
    66             $data = array(
    67                 "messaging_product" => "whatsapp",
    68                 "recipient_type" => "individual",
    69                 "to" => $mobile,
    70                 "type" => "text",
    71                 "text" => array(
    72                     "preview_url" => true,
    73                     "body" => $text_message,
    74                 ),
    75             );
    76 
    77 
    78             $response = wp_remote_post($this->base_url, array(
    79                 'body'    => wp_json_encode($data),
    80                 'headers' => array(
    81                     'Authorization' => 'Bearer ' . $this->access_token,
    82                     'content-type' => 'application/json',
    83                 ),
    84             ));
    85 
    86             if (is_wp_error($response)) {
    87                 $error_message = $response->get_error_message();
    88             } else {
    89                 $api_response = json_decode(wp_remote_retrieve_body($response), true);
    90                 if (isset($api_response['messages']['0']['id'])) {
    91                     $wam_id = $api_response['messages']['0']['id'];
    92                 } else {
    93                 }
    94             }
    95 
    96             return $wam_id;
    97         }
    98         public function is_unsubcribed($mobile)
    99         {
    100             $woom_unsubscribed_numbers = get_option('woom_unsubscribed_numbers', array());
    101             if (in_array($mobile, $woom_unsubscribed_numbers)) {
    102                 return true;
    103             } else {
    104                 return false;
    105             }
    106         }
    10755
    10856        function sync_message_templates()
     
    12977                $response = wp_remote_retrieve_body($request);
    13078                $templates = json_decode($response);
    131                 return array("data" => json_decode($response), "success" => true, "message" => __(''));
    132             }
    133         }
     79                return array("data" => json_decode($response), "success" => true, "message" => __('Templates fetched successfully', 'wc-messaging'));
     80            }
     81        }
     82
     83
    13484
    13585        public function get_message_template($template_type = 'template', $template_id = null)
     
    367317
    368318
    369         public function upload_file($file)
    370         {
    371             // Define the maximum file size (100MB in bytes).
    372             $max_file_size = 100 * 1024 * 1024; // 100 MB
    373 
    374             // Check if the file size exceeds the maximum allowed size.
    375             if ($file['size'] > $max_file_size) {
    376                 return array(
    377                     "success" => false,
    378                     "message" => __("File size exceeds the maximum allowed limit of 100MB.", "wc-messaging")
    379                 );
    380             }
    381             $file_data = file_get_contents($file['tmp_name']);
    382             $boundary = wp_generate_password(24, false);
    383 
    384             $body = "--$boundary\r\n";
    385             $body .= "Content-Disposition: form-data; name=\"file\"; filename=\"{$file['name']}\"\r\n";
    386             $body .= "Content-Type: {$file['type']}\r\n\r\n";
    387             $body .= $file_data . "\r\n";
    388             $body .= "--$boundary\r\n";
    389             $body .= "Content-Disposition: form-data; name=\"messaging_product\"\r\n\r\n";
    390             $body .= "whatsapp\r\n";
    391             $body .= "--$boundary--";
    392             $params = array(
    393                 'body'    => $body,
    394                 'headers' => array(
    395                     'Authorization' => 'Bearer ' . $this->access_token,
    396                     'Content-Type' => "multipart/form-data; boundary=$boundary",
    397 
    398                 ),
    399             );
    400             $response = wp_remote_post($this->get_wa_baseurl('media'), $params);
    401             $result = wp_remote_retrieve_body($response);
    402             if (is_wp_error($response)) {
    403                 $result = array(
    404                     "success" => false,
    405                     'message' => $response->get_error_message()
    406                 );
    407             } else if (isset(json_decode($result)->error)) {
    408                 $error = json_decode($result)->error;
    409                 $result = array(
    410                     "success" => false,
    411                     'message' => $error->message
    412                 );
    413             } else {
    414                 $result = json_decode($result);
    415                 $result = array(
    416                     "data" => (array)$result,
    417                     "success" => true,
    418                     "message" => __("File uploaded succefully", "wc-messaging")
    419                 );
    420             }
    421 
    422             return $result;
    423         }
    424         public function send_document($mobile = null, $media_id = null, $message = '')
    425         {
    426             $params = array(
    427                 "messaging_product" =>  "whatsapp",
    428                 "to" => floatval($mobile),
    429                 "type" => "document",
    430                 "document" => array(
    431                     'id' => $media_id,
    432                     "caption" => $message,
    433                 )
    434             );
    435             $result = array();
    436             if (!is_null($media_id)) {
    437                 $response = wp_remote_post($this->base_url, array(
    438                     'body'    => wp_json_encode($params),
    439                     'headers' => array(
    440                         'Authorization' => 'Bearer ' . $this->access_token,
    441                         'content-type' => 'application/json',
    442                     ),
    443                 ));
    444             } else {
    445                 return rest_ensure_response(array('status' => "error", "message" => __('document is missing', 'wc-messaging')));
    446             }
    447 
    448             if (is_wp_error($response)) {
    449                 $result = array(
    450                     "data" => [],
    451                     "success" => false,
    452                     "message" => $response->get_error_message()
    453                 );
    454                 $result = $response->get_error_message();
    455             } else {
    456                 $result = wp_remote_retrieve_body($response);
    457                 $result = array(
    458                     "data" => (array)json_decode($result),
    459                     "success" => true,
    460                     "message" => __("File sent", "wc-messaging")
    461                 );
    462             }
    463             return $result;
    464         }
    465 
    466         public function retrieve_document($media_id)
    467         {
    468             $params = array(
    469                 'headers' => array(
    470                     'Authorization' => 'Bearer ' . $this->access_token,
    471                 )
    472             );
    473             $response = wp_remote_get($this->get_wa_baseurl($media_id, "v21.0", false), $params);
    474             if (is_wp_error($response)) {
    475                 $error_message = $response->get_error_message();
    476                 $result = array(
    477                     "success" => false,
    478                     'message' => $error_message,
    479                     'data' => []
    480                 );
    481                 return $result;
    482             }
    483             $data = json_decode(wp_remote_retrieve_body($response));
    484             if (isset($data->url)) {
    485                 $params = array(
    486                     'headers' => array(
    487                         'Authorization' => 'Bearer ' . $this->access_token,
    488                     )
    489                 );
    490                 $file_response = wp_remote_get($data->url, $params);
    491                 if (is_wp_error($file_response)) {
    492                     $result = array(
    493                         "success" => false,
    494                         'message' => 'Error downloading file: ' . $file_response->get_error_message(),
    495                         'data' => []
    496                     );
    497                     return $result;
    498                 }
    499 
    500                 $upload_dir = wp_upload_dir();
    501                 $file_path = $upload_dir['basedir'] . '/wc-messaging-pro';
    502                 $file_url = $upload_dir['baseurl'] . '/wc-messaging-pro';
    503                 $file_data = wp_remote_retrieve_body($file_response);
    504                 $filename = wp_remote_retrieve_header($file_response, 'content-disposition');
    505                 $filename = explode(';', $filename)[1];
    506                 $filename = explode('=', $filename)[1];
    507                 $extension = explode('.', $filename)[1];
    508                 $filename = current_time('timestamp') . ".$extension";
    509                 if (! file_exists($file_path)) {
    510                     wp_mkdir_p($file_path);
    511                 }
    512                 $file_path = "$file_path/" . current_time('timestamp') . ".$extension";
    513                 if (file_put_contents($file_path, $file_data)) {
    514                     $result = array(
    515                         "success" => true,
    516                         'message' => __('File downloaded successfully:', "wc-messaging") . " $file_path",
    517                         'data' => array("image" => "$file_url/$filename")
    518                     );
    519                 } else {
    520                     $result = array(
    521                         "success" => false,
    522                         'message' => __('Error saving the file.', "wc-messaging"),
    523                         'data' => []
    524                     );
    525                 }
    526             }
    527             return $result;
    528         }
    529 
    530         // function for marking messages read
    531         public function mark_message_read($woom_params)
    532         {
    533 
    534             $response = wp_remote_post($this->base_url, array(
    535                 'body'    => json_encode($woom_params),
    536                 'headers' => array(
    537                     'Authorization' => 'Bearer ' . $this->access_token,
    538                     'Content-Type'  => 'application/json', // Correct MIME type
    539                 ),
    540             ));
    541 
    542             $result = json_decode(wp_remote_retrieve_body($response));
    543             return $result;
    544         }
    545319
    546320        /**
     
    707481            return $param_values;
    708482        }
    709 
    710         public function send_message_flow($comment_agent, $template_name, $language)
    711         {
    712             $mobile = $this->clean_phone_number($comment_agent);
    713 
    714             $data = [
    715                 'messaging_product' => 'whatsapp',
    716                 'to' => $mobile,
    717                 'type' => 'template',
    718                 'template' => [
    719                     'name' => $template_name,
    720                     'language' => [
    721                         'code' => $language,
    722                     ],
    723                     'components' => [
    724                         [
    725                             'type' => 'button',
    726                             'sub_type' => 'flow',
    727                             'index' => '0',
    728                             'parameters' => [
    729                                 [
    730                                     'type' => 'action',
    731                                     'action' => [
    732                                         'flow_token' => $template_name, // Optional, can be "unused"
    733                                     ],
    734                                 ],
    735                             ],
    736                         ],
    737                     ],
    738                 ],
    739             ];
    740 
    741             // Set up headers
    742             $headers = [
    743                 'Authorization' => 'Bearer ' . $this->access_token,
    744                 'Content-Type'  => 'application/json',
    745             ];
    746 
    747             // Make the POST request
    748             $response = wp_remote_post($this->base_url, [
    749                 'headers' => $headers,
    750                 'body'    => json_encode($data),
    751                 'method'  => 'POST',
    752             ]);
    753 
    754             // Check for errors
    755             if (is_wp_error($response)) {
    756                 $error_message = $response->get_error_message();
    757                 return array(
    758                     "success" => false,
    759                     'message' => $error_message
    760                 );
    761             } else {
    762                 $body = wp_remote_retrieve_body($response);
    763                 $decoded_body = json_decode($body, true);
    764 
    765                 // Check if message status is "accepted"
    766                 if (!empty($decoded_body['messages'][0]['message_status']) && $decoded_body['messages'][0]['message_status'] === 'accepted') {
    767 
    768                     $message_id = $decoded_body['messages'][0]['id'] ?? 'unknown';
    769 
    770                     // Build success response
    771                     $success_response = [
    772                         "success" => true,
    773                         "message_id" => $message_id,
    774                         "message_status" => __('accepted', 'wc-messaging')
    775                     ];
    776                     return $success_response;
    777                 }
    778 
    779                 // If status is not "accepted"
    780                 return [
    781                     "success" => false,
    782                     "message" => __('Message not accepted by API.', 'wc-messaging'),
    783                     "response" => $decoded_body
    784                 ];
    785             }
    786         }
    787483    } // End Class
    788484}//
  • wc-messaging/trunk/readme.txt

    r3233658 r3234819  
    55Requires at least: 4.0
    66Tested up to: 6.7
    7 Stable tag: 1.3.4
     7Stable tag: 1.3.5
    88Requires PHP: 5.4
    99License: GPL-2.0+
     
    172172== Changelog ==
    173173
     174**1.3.5 - 04 FEB 2025**
     175
     176* **Improvement:** Security updates
     177* **Improvement:** Code cleaning for improve performance and maintainability
     178
    174179**1.3.4 - 03 FEB 2025**
    175180
  • wc-messaging/trunk/wc-messaging.php

    r3233658 r3234819  
    1010 * Plugin URI:        https://sevengits.com/plugin/wc-messaging-pro
    1111 * Description:       Send WhatsApp notifications for Woocommerce orders using  official WhatsApp Cloud APIs.
    12  * Version:           1.3.4
     12 * Version:           1.3.5
    1313 * Author:            Sevengits
    1414 * Author URI:        https://sevengits.com/
     
    4040}
    4141if (!defined('woom_version')) {
    42     define('woom_version', '1.3.4');
     42    define('woom_version', '1.3.5');
    4343}
    4444
Note: See TracChangeset for help on using the changeset viewer.