Plugin Directory

Changeset 2561870


Ignore:
Timestamp:
07/10/2021 01:05:10 PM (5 years ago)
Author:
affiliatenetworks
Message:

add version 1.0.7

Location:
yektanet-affiliate/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • yektanet-affiliate/trunk/includes/aw_plugin-database.php

    r2560031 r2561870  
    2424function yektanetaffiliate_create_table () {
    2525    if (get_option('yektanetaffiliate_version') === false) {
    26         update_option('yektanetaffiliate_version', '1.0.6');
     26        update_option('yektanetaffiliate_version', '1.0.7');
    2727    }
    2828    if (get_option('yektanetaffiliate_db_version') === false) {
  • yektanet-affiliate/trunk/readme.txt

    r2560031 r2561870  
    44Requires at least: 5.4
    55Tested up to: 5.7
    6 Stable tag: 1.0.6
     6Stable tag: 1.0.7
    77Requires PHP: 7.0
    88License: GPL v2 or later
  • yektanet-affiliate/trunk/yektanet-affiliate.php

    r2560031 r2561870  
    66Requires at least: 5.4
    77Requires PHP: 7.0
    8 Version: 1.0.6
     8Version: 1.0.7
    99License: GPL v2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4242
    4343    if (!defined('YEKTANETAFFILIATE_VERSION')) {
    44         define('YEKTANETAFFILIATE_VERSION', '1.0.6');
     44        define('YEKTANETAFFILIATE_VERSION', '1.0.7');
    4545    }
    4646    if (!defined('YEKTANETAFFILIATE_DB_VERSION')) {
     
    7070
    7171    add_action('woocommerce_thankyou', 'yektanetaffiliate_success_page', 10, 1);
     72
     73    add_action('woocommerce_checkout_order_processed', 'yektanetaffiliate_process', 10, 1);
     74
     75    add_action('woocommerce_before_cart', 'yektanetaffiliate_cart', 10, 1);
     76
     77    add_action('woocommerce_review_order_before_payment', 'yektanetaffiliate_checkout', 10, 0);
    7278
    7379    // update check
     
    130136
    131137    function yektanetaffiliate_send_data($order, $partial, $datetime, $type, $status, $new_status) {
    132         global $wp;
     138        global $wp;
    133139        $raw_cookies = (array_reduce(
    134140            explode(';', $_SERVER['HTTP_COOKIE'] ?? ''),
     
    207213            $field['paid_at'] = $datetime->format('Y-m-d\TH:i:sP');
    208214        }
    209         $user_id = wp_get_current_user()->ID;
    210         $field['user_id'] = $user_id;
    211         $roles = [];
    212         foreach (get_user_meta($user_id, 'wp_capabilities', true) as $role => $exist) {
    213             if ($exist) {
    214                 array_push($roles, $role);
    215             }
    216         }
    217         $field['user_roles'] = $roles;
     215        global $current_user;
     216        $field['user_id'] = wp_get_current_user()->ID;
     217        $field['user_roles'] = $current_user->roles;
    218218        $field['items'] = $items_data;
    219219        $fields = array();
     
    247247    }
    248248
     249    function yektanetaffiliate_send_temp_data($status) {
     250        global $wp;
     251        $raw_cookies = (array_reduce(
     252            explode(';', $_SERVER['HTTP_COOKIE'] ?? ''),
     253            function($carry, $item) {
     254                $pair_arr = explode('=', $item);
     255                $carry[ trim($pair_arr[0]) ] = trim($pair_arr[1]);
     256                return $carry;
     257            },
     258            []
     259        ) ?: []);
     260
     261        if (!isset($_COOKIE["_yngt"]) || empty($_COOKIE["_yngt"])) {
     262            $yngt = '';
     263        } else {
     264            $yngt = $raw_cookies["_yngt"];
     265        }
     266        if (isset($_COOKIE["analytics_campaign"]) && !empty($_COOKIE["analytics_campaign"])) {
     267            $ynsrc = $raw_cookies["analytics_campaign"];
     268        } else if (isset($_COOKIE["_ynsrc"]) && !empty($_COOKIE["_ynsrc"])) {
     269            $ynsrc = $raw_cookies["_ynsrc"];
     270        } else {
     271            $ynsrc = '';
     272        }
     273        $field = [
     274            'ip'         => $_SERVER['REMOTE_ADDR'],
     275            'user_agent'         => $_SERVER['HTTP_USER_AGENT'],
     276            'status'         => $status,
     277            'current_url' => add_query_arg($wp->query_vars, home_url( $wp->request )),
     278            'cookies_count' => count($_COOKIE),
     279            'yn_ch_test' => $_COOKIE['yn_ch_test'],
     280            'ynsrc'         => $ynsrc,
     281            'yngt'         => $yngt,
     282            'paid_at'  => $_SERVER['REQUEST_TIME']
     283        ];
     284        global $current_user;
     285        $field['user_id'] = wp_get_current_user()->ID;
     286        $field['user_roles'] = $current_user->roles;
     287        $fields = array();
     288        array_push($fields, $field);
     289        $token=get_option('yektanetaffiliate_settings')['yektanetaffiliate_token'];
     290        $url = 'https://trk.chavosh.org/api/v1/event/';
     291        $header = array();
     292        $header['Content-type'] = 'application/json';
     293        $header['Authorization'] = 'Token ' . $token;
     294        $args = array(
     295            'body'        => json_encode($fields),
     296            'headers'     => $header,
     297        );
     298        $response = wp_remote_post($url ,$args);
     299    }
     300
     301    function yektanetaffiliate_checkout() {
     302        yektanetaffiliate_send_temp_data('checkout');
     303    }
     304
     305    function yektanetaffiliate_cart($temp) {
     306        yektanetaffiliate_send_temp_data('cart');
     307    }
     308
     309    function yektanetaffiliate_process($order_id) {
     310        $order = wc_get_order($order_id);
     311        $datetime = $order->get_date_paid();
     312        yektanetaffiliate_send_data($order, False, $datetime, 'process', 'pending', 'process');
     313    }
     314
    249315    function yektanetaffiliate_success_page($order_id) {
    250316        $order = wc_get_order($order_id);
Note: See TracChangeset for help on using the changeset viewer.