Plugin Directory

Changeset 1755082


Ignore:
Timestamp:
10/30/2017 09:56:23 AM (8 years ago)
Author:
freshchat
Message:

Restore user implementation

Location:
freshchat
Files:
4 edited
3 copied

Legend:

Unmodified
Added
Removed
  • freshchat/tags/2.1.0/Readme.txt

    r1750349 r1755082  
    66Tested up to: 4.8.2
    77Requires PHP: 5.2.4
    8 Stable tag: 2.0.0
     8Stable tag: 2.1.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7474== 2.0.2 ==
    7575README update
     76
     77== 2.1.0 ==
     78Restore user implementation
  • freshchat/tags/2.1.0/freshchat.php

    r1750349 r1755082  
    22/*
    33Plugin Name: Freshchat
    4 Version: 2.0.2
     4Version: 2.1.0
    55Author: Freshchat
    66Description: Modern messaging software that your sales and customer engagement teams will love.
     
    2020add_action('admin_enqueue_scripts', 'add_admin_style');
    2121
     22function update_restore_id() {
     23  $current_user = wp_get_current_user();
     24  update_user_meta($current_user->ID, "restore_id", $_POST['restoreId']);
     25  if ( is_wp_error( $current_user->ID) ) {
     26    die( "Fail" );
     27  } else {
     28    die( "Success" );
     29  }
     30}
     31add_action( 'wp_ajax_update_restore_id', 'update_restore_id' );
     32
    2233require_once(FRESHCHAT_DIR . 'widget-settings/main.php');
    2334require_once(FRESHCHAT_DIR . 'widget-settings/menu.php');
  • freshchat/tags/2.1.0/widget-settings/add_to_page.php

    r1736154 r1755082  
    88{
    99  $current_user = wp_get_current_user();
    10   echo '<script>';
    11   echo 'console.log('. json_encode( $current_user ) .')';
    12   echo '</script>';
     10  $user_meta = get_user_meta($current_user->ID, "restore_id");
    1311  if ($current_user->user_email) {
    1412    $sanitized_email = sanitize_email($current_user->user_email);
    15     $null = "NULL";
    1613    echo "<script>\n";
    17     echo 'console.log('. json_encode( $sanitized_email ) .');';
    18     echo "window.fcSettings.siteId ='".(sanitize_text_field($current_user->user_url) ? sanitize_text_field($current_user->user_url) : $null)."';\n";
    19     echo "window.fcSettings.externalId ='".(sanitize_text_field($current_user->user_pass) ? sanitize_text_field($current_user->user_pass) : $null)."';\n";
    20     echo "window.fcSettings.firstName ='".(sanitize_text_field($current_user->display_name) ? sanitize_text_field($current_user->display_name) : $null)."';\n";
    21     echo "window.fcSettings.email ='".($sanitized_email ? $sanitized_email : $null)."';\n";
     14    echo "window.fcSettings.externalId ='".sanitize_text_field($current_user->user_pass)."';\n";
     15    echo "window.fcSettings.restoreId ='".sanitize_text_field($user_meta[0])."';\n";
     16    echo "window.fcSettings.onInit = function() {
     17          window.fcWidget.on('widget:loaded', function() {
     18            window.fcWidget.user.get().then(function(resp) {
     19              var status = resp && resp.status,
     20              data = resp && resp.data;
     21              if (status === 200) {
     22                if (data.restoreId) {
     23                  jQuery.post( ajaxurl, {         
     24                    action: 'update_restore_id',     
     25                    restoreId: data.restoreId                 
     26                  }, function() { 
     27                    console.log('Restore id is updated successfully');
     28                  });
     29                }
     30              }
     31            }, function(err){
     32              var status = err && err.status;
     33              if((status === 401 || status === 403 || status === 404) && !window.fcSettings.restoreId){
     34                window.fcWidget.user.create().then(function(resp){
     35                  var data = resp && resp.data;
     36                  if (data.restoreId) {
     37                    jQuery.post( ajaxurl, {         
     38                      action: 'update_restore_id',     
     39                      restoreId: data.restoreId                 
     40                    }, function() { 
     41                      console.log('Restore id is updated successfully');
     42                    });
     43                  }
     44                },function(err){
     45                  console.log('User creation is failed', err);
     46                })
     47              }else if((status === 401 || status === 404 && status === 409) && window.fcSettings.restoreId){
     48                window.fcSettings.restoreId = undefined;
     49                window.fcWidget.user.create().then(function(resp){
     50                  var data = resp && resp.data;
     51                  if (data.restoreId) {
     52                    jQuery.post( ajaxurl, {         
     53                      action: 'update_restore_id',     
     54                      restoreId: data.restoreId                 
     55                    }, function() { 
     56                      console.log('Restore id is updated successfully');
     57                    });
     58                  }
     59                },function(err){
     60                  console.log('User creation is failed', err);
     61                })
     62              }
     63            });
     64          });
     65        };\n";
     66    echo "window.fcSettings.firstName ='".sanitize_text_field($current_user->display_name)."';\n";
     67    echo "window.fcSettings.email ='".$sanitized_email."';\n";
    2268    echo "</script>\n";
    2369  }
     
    2672function add_fc()
    2773{
     74  echo "<script>\n";
     75  echo "var ajaxurl = '".admin_url('admin-ajax.php')."';\n";
     76  echo "</script>\n";
    2877  // Ignore admin, feed, robots or trackbacks
    2978  if ( is_feed() || is_robots() || is_trackback() )
  • freshchat/trunk/Readme.txt

    r1750349 r1755082  
    66Tested up to: 4.8.2
    77Requires PHP: 5.2.4
    8 Stable tag: 2.0.0
     8Stable tag: 2.1.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7474== 2.0.2 ==
    7575README update
     76
     77== 2.1.0 ==
     78Restore user implementation
  • freshchat/trunk/freshchat.php

    r1750349 r1755082  
    22/*
    33Plugin Name: Freshchat
    4 Version: 2.0.2
     4Version: 2.1.0
    55Author: Freshchat
    66Description: Modern messaging software that your sales and customer engagement teams will love.
     
    2020add_action('admin_enqueue_scripts', 'add_admin_style');
    2121
     22function update_restore_id() {
     23  $current_user = wp_get_current_user();
     24  update_user_meta($current_user->ID, "restore_id", $_POST['restoreId']);
     25  if ( is_wp_error( $current_user->ID) ) {
     26    die( "Fail" );
     27  } else {
     28    die( "Success" );
     29  }
     30}
     31add_action( 'wp_ajax_update_restore_id', 'update_restore_id' );
     32
    2233require_once(FRESHCHAT_DIR . 'widget-settings/main.php');
    2334require_once(FRESHCHAT_DIR . 'widget-settings/menu.php');
  • freshchat/trunk/widget-settings/add_to_page.php

    r1736154 r1755082  
    88{
    99  $current_user = wp_get_current_user();
    10   echo '<script>';
    11   echo 'console.log('. json_encode( $current_user ) .')';
    12   echo '</script>';
     10  $user_meta = get_user_meta($current_user->ID, "restore_id");
    1311  if ($current_user->user_email) {
    1412    $sanitized_email = sanitize_email($current_user->user_email);
    15     $null = "NULL";
    1613    echo "<script>\n";
    17     echo 'console.log('. json_encode( $sanitized_email ) .');';
    18     echo "window.fcSettings.siteId ='".(sanitize_text_field($current_user->user_url) ? sanitize_text_field($current_user->user_url) : $null)."';\n";
    19     echo "window.fcSettings.externalId ='".(sanitize_text_field($current_user->user_pass) ? sanitize_text_field($current_user->user_pass) : $null)."';\n";
    20     echo "window.fcSettings.firstName ='".(sanitize_text_field($current_user->display_name) ? sanitize_text_field($current_user->display_name) : $null)."';\n";
    21     echo "window.fcSettings.email ='".($sanitized_email ? $sanitized_email : $null)."';\n";
     14    echo "window.fcSettings.externalId ='".sanitize_text_field($current_user->user_pass)."';\n";
     15    echo "window.fcSettings.restoreId ='".sanitize_text_field($user_meta[0])."';\n";
     16    echo "window.fcSettings.onInit = function() {
     17          window.fcWidget.on('widget:loaded', function() {
     18            window.fcWidget.user.get().then(function(resp) {
     19              var status = resp && resp.status,
     20              data = resp && resp.data;
     21              if (status === 200) {
     22                if (data.restoreId) {
     23                  jQuery.post( ajaxurl, {         
     24                    action: 'update_restore_id',     
     25                    restoreId: data.restoreId                 
     26                  }, function() { 
     27                    console.log('Restore id is updated successfully');
     28                  });
     29                }
     30              }
     31            }, function(err){
     32              var status = err && err.status;
     33              if((status === 401 || status === 403 || status === 404) && !window.fcSettings.restoreId){
     34                window.fcWidget.user.create().then(function(resp){
     35                  var data = resp && resp.data;
     36                  if (data.restoreId) {
     37                    jQuery.post( ajaxurl, {         
     38                      action: 'update_restore_id',     
     39                      restoreId: data.restoreId                 
     40                    }, function() { 
     41                      console.log('Restore id is updated successfully');
     42                    });
     43                  }
     44                },function(err){
     45                  console.log('User creation is failed', err);
     46                })
     47              }else if((status === 401 || status === 404 && status === 409) && window.fcSettings.restoreId){
     48                window.fcSettings.restoreId = undefined;
     49                window.fcWidget.user.create().then(function(resp){
     50                  var data = resp && resp.data;
     51                  if (data.restoreId) {
     52                    jQuery.post( ajaxurl, {         
     53                      action: 'update_restore_id',     
     54                      restoreId: data.restoreId                 
     55                    }, function() { 
     56                      console.log('Restore id is updated successfully');
     57                    });
     58                  }
     59                },function(err){
     60                  console.log('User creation is failed', err);
     61                })
     62              }
     63            });
     64          });
     65        };\n";
     66    echo "window.fcSettings.firstName ='".sanitize_text_field($current_user->display_name)."';\n";
     67    echo "window.fcSettings.email ='".$sanitized_email."';\n";
    2268    echo "</script>\n";
    2369  }
     
    2672function add_fc()
    2773{
     74  echo "<script>\n";
     75  echo "var ajaxurl = '".admin_url('admin-ajax.php')."';\n";
     76  echo "</script>\n";
    2877  // Ignore admin, feed, robots or trackbacks
    2978  if ( is_feed() || is_robots() || is_trackback() )
Note: See TracChangeset for help on using the changeset viewer.