[FRAMEWORK] Xây dựng page Setting (ok)

Language, Notifications, Change Password, Logout

Language

C:\xampp\htdocs\reset4\wp-content\themes\addframwork\framework\controllers\Account.php

<?php
class BJ_Account_Controller extends Pv_Controller {
  function __construct() {
    if (isset($_GET['action'])):
      switch ($_GET['action']) {
      case "edit-info":
        $this->update_info();
        break;
      case "followers":
        $this->followers();
        break;
      case "following":
        $this->following();
        break;
      case "add-deal":
        $this->adddeal();
      break;
      case "add-event":
        $this->addevent();
      break;
      case "add-post":
        $this->addposts();
      break;
      case "settings":
        $this->settings();
      break;
      case "language":
        $this->language();
      break;
      default:
        $this->index();
      } else :
      $this->index();
    endif;
  }
  private function get_user_id() {
    if (isset($_GET["id"]) && is_user_exist(strip_tags($_GET["id"]))) {
      return $_GET["id"];
    } else {
      return get_current_user_id();
    }
  }
  public function index() {
    $data                         = array();
    $user_id                      = $this->get_user_id();
    $user_obj                     = get_userdata($user_id);
    $data['id']                   = $user_id;
    $data['display_name']         = $user_obj->display_name;
    $data['date_registered']      = date_i18n(__('jS F Y', 'umm'), strtotime($user_obj->user_registered));
    $data['avatar']               = get_url_avatar($user_id);
    $data['province_address_arr'] = atw_load_province_address($user_id);
    $this->load()->View("account", $data, "account");
  }
  public function update_info() {
    $data = array();
    $this->load()->View("update-info", $data, "account");
  }
  public function followers() {
    $current_user_id       = $this->get_user_id();
    $data                  = array();
    $data['list_follower'] = get_list_follower($current_user_id);
    $this->load()->View("followers", $data, "account");
  }
  public function following() {
    $user_id             = $this->get_user_id();
    $data                = array();
    $data['list_follow'] = list_user_follow($user_id);
    $this->load()->View("following", $data, "account");
  }
  public function adddeal() {
    $this->load()->View("add-deal", '', "deal"); 
  }
  public function addevent() {
    $this->load()->View("add-event", '', "event"); 
  }
  public function addposts() {
    $this->load()->View("add-post", '', "post"); 
  }
  public function settings() {
    $data = array();
    $this->load()->View("settings", $data, "account");
  }
  public function language(){
    $data = array();
    $this->load()->View("language", $data, "account");
  }
}
function render_province_option($default = ""){  
  $json = file_get_contents(get_stylesheet_directory()."/json/tinh_tp.json");
  $tinh_thanh = json_decode($json,true);
  foreach ($tinh_thanh as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name"]."</option>";
  }
}
function render_xa_phuong_option($quan_huyen,$default=""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/xa-phuong/".$quan_huyen.".json");
  $xa_phuong = json_decode($json,true);
  foreach ($xa_phuong as $key => $value) {
      if($key == $default){$select = "selected";}else{$select = "";}
      echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
    }
}
function render_quan_huyen_option($tinh_thanh,$default = ""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/quan-huyen/".$tinh_thanh.".json");
  $quan_huyen = json_decode($json,true);  
  foreach ($quan_huyen as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
  }  
}

C:\xampp\htdocs\reset4\wp-content\themes\addframwork\framework\views\account\settings.php

<?php 
$lang_arr = array(
  "en_US" => array(__("English", "umm"), 'american.png'),
  "vi" => array(__("Vietnamese", "umm"), 'vn.png'),
  "ko_KR" => array(__("Korean","umm"),"korea-flag.png"),
);
$current_lang =  get_locale();
?>
<div class="page-settings container">
    <div class="nav-menu">
        <a href="<?php echo SITE_URL ?>account/?action=language&appt=N" class="nav-menu__item menu-language d-flex align-items-center justify-content-between border-b-1">
          <div class="d-flex flex-column flex-fill">
            <span class="size-14"><?php _e('Language', 'umm'); ?></span>
            <span class="present"><?php echo $lang_arr[$current_lang][0] ?></span>
          </div>
          <div class="d-icon">
            <svg width="8" height="14">
              <use href="#icon-right"></use>
            </svg>
          </div>
        </a>
        <a href="<?php echo SITE_URL ?>account/?action=setting-notifi&appt=N" class="nav-menu__item menu-notification d-flex align-items-center justify-content-between border-b-1">
          <div class="d-flex flex-column flex-fill">
            <span class="size-14"><?php _e('Notification setting', 'umm'); ?></span>
            <span class="present">On</span>
          </div>
          <div class="d-icon">
            <svg width="8" height="14">
              <use href="#icon-right"></use>
            </svg>
          </div>
        </a>
        <a href="<?php echo SITE_URL ?>account/?action=update-password&appt=N" class="nav-menu__item menu-change-password d-flex align-items-center justify-content-between border-b-1">
          <div class="d-flex flex-column flex-fill">
            <span class="size-14"><?php _e('Change password', 'umm'); ?></span>
          </div>
          <div class="d-icon">
            <svg width="8" height="14">
              <use href="#icon-right"></use>
            </svg>
          </div>
        </a>
        <a href="#" class="app_logout nav-menu__item menu-log-out d-flex align-items-center justify-content-between border-b-1">
          <div class="d-flex flex-column flex-fill">
            <span class="size-14"><?php _e('Log out', 'umm'); ?></span>
          </div>
          <div class="d-icon">
            <svg width="8" height="14">
              <use href="#icon-right"></use>
            </svg>
          </div>
        </a>
    </div>
</div>

C:\xampp\htdocs\reset4\wp-content\themes\umm\framework\views\account\language.php

<style>
.box-language label{
    padding-left: 2.25rem;
}
.box-language svg{
  position: absolute;
  z-index: 9;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}
</style>
<?php
$lang_arr = array(
  "en_US" => array(__("English", "umm"), 'american.png'),
  "vi" => array(__("Vietnamese", "umm"), 'vn.png'),
  "ko_KR" => array(__("Korean","umm"),"korea-flag.png"),
);
$current_lang =  get_locale();
?>
<div class="page-language box-radio container">
  <div class="box-language mt-4">
    <?php foreach($lang_arr as $key => $lang): ?>
      <label class="box-container"><?php echo $lang[0]; ?>
        <svg width="30" height="20"><use href="#icon-<?php echo $key ?>"></use></svg>
        <input type="radio" name="language"
        <?php if($key == $current_lang) echo 'checked="checked"'; ?>
        value="<?php echo $key ?>">
        <span class="checkmark"></span>
      </label>
    <?php endforeach; ?>
    <?php wp_nonce_field(AT_NONCE_KEY.'language','language-token'); ?>
  </div>
</div>
<div class="hidden">
  <svg id="icon-vi" viewBox="0 0 30 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path d="M30 0H0V20H30V0Z" fill="white"/>
  <path d="M29 1H1V19H29V1Z" fill="#DA251D"/>
  <path d="M14.9992 12.654L11.7502 15L12.9772 11.185L9.74219 8.755H13.7502L14.9992 5L16.2492 8.755H20.2562L17.0212 11.185L18.2482 15L14.9992 12.654Z" fill="#FFFF00"/>
  </svg>
  <svg id="icon-en_US" viewBox="0 0 30 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path d="M29.1 1V0.9H29H1H0.9V1V19V19.1H1H29H29.1V19V1Z" fill="white" stroke="#493E30" stroke-width="0.2"/>
  <path d="M29 8H17V1H13V8H1V12H13V19H17V12H29V8Z" fill="#CE1124"/>
  </svg>
  <svg id="icon-ko_KR" viewBox="0 0 28 18" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M0.1 17.9V0.1H27.9V17.9H0.1Z" fill="white" stroke="black" stroke-width="0.2"/>
    <path d="M13.8786 5.0625C16.1006 5.0625 17.9106 6.8095 18.0216 9.0045C18.0286 9.0745 18.0326 9.1445 18.0326 9.2165C18.0326 9.1445 18.0286 9.0735 18.0216 9.0045C17.9146 7.9575 17.0306 7.1405 15.9556 7.1405C14.8086 7.1395 13.8786 8.0685 13.8786 9.2165C13.8786 10.3635 12.9486 11.2935 11.8016 11.2935C10.7256 11.2935 9.84161 10.4765 9.73561 9.4285C9.72861 9.3585 9.72461 9.2885 9.72461 9.2165C9.72461 6.9225 11.5846 5.0625 13.8786 5.0625Z" fill="#C60C30"/>
    <path d="M13.8786 13.3677C11.6566 13.3677 9.84661 11.6207 9.73561 9.42572C9.72861 9.35572 9.72461 9.28572 9.72461 9.21372C9.72461 9.28572 9.72861 9.35672 9.73561 9.42572C9.84261 10.4727 10.7266 11.2897 11.8016 11.2897C12.9486 11.2907 13.8786 10.3617 13.8786 9.21372C13.8786 8.06672 14.8086 7.13672 15.9556 7.13672C17.0316 7.13672 17.9156 7.95372 18.0216 9.00172C18.0286 9.07172 18.0326 9.14172 18.0326 9.21372C18.0326 11.5077 16.1726 13.3677 13.8786 13.3677Z" fill="#003478"/>
    <path d="M9.07192 4.22497L8.64844 3.98047L6.69344 7.36663L7.11692 7.61113L9.07192 4.22497Z" fill="black"/>
    <path d="M8.22622 3.73278L7.80273 3.48828L5.84773 6.87444L6.27122 7.11894L8.22622 3.73278Z" fill="black"/>
    <path d="M7.37856 3.2445L6.95508 3L5.00008 6.38616L5.42356 6.63066L7.37856 3.2445Z" fill="black"/>
    <path d="M7.11685 10.818L6.69336 11.0625L8.64836 14.4487L9.07185 14.2042L7.11685 10.818Z" fill="black"/>
    <path d="M6.26919 11.3102L5.8457 11.5547L6.7012 13.0365L7.12469 12.792L6.26919 11.3102Z" fill="black"/>
    <path d="M7.37075 13.2125L6.94727 13.457L7.80277 14.9388L8.22625 14.6943L7.37075 13.2125Z" fill="black"/>
    <path d="M5.42349 11.7985L5 12.043L6.955 15.4291L7.37849 15.1846L5.42349 11.7985Z" fill="black"/>
    <path d="M21.9105 11.5526L21.4871 11.3081L20.6316 12.7899L21.0551 13.0344L21.9105 11.5526Z" fill="black"/>
    <path d="M20.8101 13.4574L20.3866 13.2129L19.5311 14.6947L19.9546 14.9392L20.8101 13.4574Z" fill="black"/>
    <path d="M21.0639 11.0648L20.6404 10.8203L19.7849 12.3021L20.2084 12.5466L21.0639 11.0648Z" fill="black"/>
    <path d="M19.9645 12.9686L19.541 12.7241L18.6855 14.2059L19.109 14.4504L19.9645 12.9686Z" fill="black"/>
    <path d="M22.757 12.0414L22.3335 11.7969L21.478 13.2787L21.9015 13.5232L22.757 12.0414Z" fill="black"/>
    <path d="M21.657 13.9462L21.2335 13.7017L20.378 15.1834L20.8015 15.4279L21.657 13.9462Z" fill="black"/>
    <path d="M19.9555 3.4889L19.532 3.7334L21.487 7.11956L21.9105 6.87506L19.9555 3.4889Z" fill="black"/>
    <path d="M20.2089 5.88245L19.7854 6.12695L20.6409 7.60872L21.0644 7.36422L20.2089 5.88245Z" fill="black"/>
    <path d="M19.109 3.97767L18.6855 4.22217L19.541 5.70394L19.9645 5.45944L19.109 3.97767Z" fill="black"/>
    <path d="M21.9019 4.90442L21.4784 5.14893L22.3339 6.6307L22.7574 6.3862L21.9019 4.90442Z" fill="black"/>
    <path d="M20.8015 3.00013L20.3781 3.24463L21.2336 4.7264L21.657 4.4819L20.8015 3.00013Z" fill="black"/>
    </svg>
</div>

C:\xampp\htdocs\reset4\wp-content\themes\addframwork\js\custom.js

jQuery(document).ready(function($) {
  function addLoading() {
    $('#page-load').css({ 'opacity': '1', 'visibility': 'visible' });
  }
  function unLoading() {
    $('#page-load').css({ 'opacity': '0', 'visibility': 'hidden' });
  }
  const boxMessage = $('.notifi__update');
  $("body").on("submit", "form#form-update-info", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-info"));
    fd.append('action', 'app_update_info');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var result = $.parseJSON(output);
        if (result.status === false) {
          setTimeout(() => {
            var currURL = window.location.href;
            var urlReload = replaceUrlParam(currURL, 'appt', 'C');
            window.location.replace(urlReload);
          }, 1500)
        } else {
          boxMessage.text(result.message);
        }
        boxMessage.removeClass('hidden');
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  $("input").blur(function() {
    boxMessage.addClass('hidden');
  });
  $("#event-datepicker").datepicker({
    onSelect: function() {
      let dateObject = $(this).datepicker('getDate');
      $("#date").val($.datepicker.formatDate("yy-mm-dd", dateObject));
    }
  });
  $("body").on("submit", "form#form-update-post", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-post"));
    fd.append('action', 'edit_post_single');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var currURL = window.location.href;
        currURL = currURL.split('?')[0];
        currURL = currURL + "?appt=C";
        window.location.replace(currURL);
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  // For Search
  var typeSearch = $('.filters__item.active').data('type');
  const boxResult = $('.box-results__list');
  $("body").on("click", ".filters__item", function(e) {
    $('.filters__item').removeClass('active');
    $(this).addClass('active');
    typeSearch = $('.filters__item.active').data('type');
    const keyWord = $('#search').val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  })
  $("#search").keyup(function() {
    const keyWord = $(this).val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  });
  function searchFilter(keyWord, typeSearch) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'search_by_filters',
        keyword: keyWord,
        type: typeSearch,
        token: $('#nonce_token').val(),
      },
      beforeSend: function() {
        boxResult.css('opacity', '0.6');
      },
      success: function(output) {
        boxResult.css('opacity', '1');
        boxResult.html(output);
      },
      error: function() { alert('error'); }
    });
  }
  // For App Logout
  $("body").on("click", ".app_logout", function(e) {
    e.preventDefault();
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'app_logout',
        token: $('#nonce_token').val(),
      },
      success: function(output) {
        if (output == "success") {
          window.appBridge.clearCookie();
          var expire = new Date();
          expire.setDate(expire.getDate() + 1000);
          cookies = "APP_LOGIN" + '=' + escape('false') + ';'
          cookies += ';expires=' + expire.toGMTString() + ';';
          document.cookie = cookies;
          location.href = "/login"
        }
      },
    });
  });
  // For set Language
  $('input[type=radio][name=language]').change(function(e) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'at_change_language',
        lang: $(this).val(),
        token: $("#language-token").val(),
      },
      success: function(output) {
        if (output == "1") {
          //window.appBridge.setLanguage(output)
          location.reload(true);
        } else {
          alert('error');
        }
      },
    });
  });
});

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\views\account\settings.php

<?php 
$lang_arr = array(
  "en_US" => array(__("English", "umm"), 'american.png'),
  "vi" => array(__("Vietnamese", "umm"), 'vn.png'),
  "ko_KR" => array(__("Korean","umm"),"korea-flag.png"),
);
$current_lang =  get_locale();
?>
<div class="page-settings container">
  <div class="nav-menu">
    <a href="<?php echo SITE_URL ?>account/?action=language&appt=N" class="nav-menu__item menu-language d-flex align-items-center justify-content-between border-b-1">
      <div class="d-flex flex-column flex-fill">
        <span class="size-14"><?php _e('Language', 'umm'); ?></span>
        <span class="present"><?php echo $lang_arr[$current_lang][0] ?></span>
      </div>
      <div class="d-icon">
        <svg width="8" height="14">
          <use href="#icon-right"></use>
        </svg>
      </div>
    </a>
    <a href="<?php echo SITE_URL ?>account/?action=setting-notifi&appt=N" class="nav-menu__item menu-notification d-flex align-items-center justify-content-between border-b-1">
      <div class="d-flex flex-column flex-fill">
        <span class="size-14"><?php _e('Notification setting', 'umm'); ?></span>
        <span class="present">On</span>
      </div>
      <div class="d-icon">
        <svg width="8" height="14">
          <use href="#icon-right"></use>
        </svg>
      </div>
    </a>
    <a href="<?php echo SITE_URL ?>account/?action=update-password&appt=N" class="nav-menu__item menu-change-password d-flex align-items-center justify-content-between border-b-1">
      <div class="d-flex flex-column flex-fill">
        <span class="size-14"><?php _e('Change password', 'umm'); ?></span>
      </div>
      <div class="d-icon">
        <svg width="8" height="14">
          <use href="#icon-right"></use>
        </svg>
      </div>
    </a>
    <a href="#" class="app_logout nav-menu__item menu-log-out d-flex align-items-center justify-content-between border-b-1">
      <div class="d-flex flex-column flex-fill">
        <span class="size-14"><?php _e('Log out', 'umm'); ?></span>
      </div>
      <div class="d-icon">
        <svg width="8" height="14">
          <use href="#icon-right"></use>
        </svg>
      </div>
    </a>
  </div>
</div>

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\views\account\language.php

<style> 
  .box-language label{
    padding-left: 2.25rem;
  }
  .box-language svg{
    position: absolute;
    z-index: 9;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
  }
</style>
<?php
$lang_arr = array(
    "en_US" => array(__("English", "umm"), 'american.png'),
    "vi" => array(__("Vietnamese", "umm"), 'vn.png'),
    "ko_KR" => array(__("Korean","umm"),"korea-flag.png"),
);
$current_lang =  get_locale();
?>
<div class="page-language box-radio container">
  <div class="box-language mt-4">
    <?php foreach($lang_arr as $key => $lang): ?>
    <label class="box-container">
      <?php echo $lang[0]; ?>
      <svg width="30" height="20">
        <use href="#icon-<?php echo $key ?>"></use>
      </svg>
      <input type="radio" name="language" <?php if($key==$current_lang) echo 'checked="checked"' ; ?> value="
      <?php echo $key ?>"> <span class="checkmark"></span>
    </label>
    <?php endforeach; ?>
    <?php wp_nonce_field(AT_NONCE_KEY.'language','language-token'); ?>
  </div>
</div>
<div class="hidden">
  <svg id="icon-vi" viewBox="0 0 30 20" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M30 0H0V20H30V0Z" fill="white" />
    <path d="M29 1H1V19H29V1Z" fill="#DA251D" />
    <path d="M14.9992 12.654L11.7502 15L12.9772 11.185L9.74219 8.755H13.7502L14.9992 5L16.2492 8.755H20.2562L17.0212 11.185L18.2482 15L14.9992 12.654Z" fill="#FFFF00" />
  </svg>
  <svg id="icon-en_US" viewBox="0 0 30 20" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M29.1 1V0.9H29H1H0.9V1V19V19.1H1H29H29.1V19V1Z" fill="white" stroke="#493E30" stroke-width="0.2" />
    <path d="M29 8H17V1H13V8H1V12H13V19H17V12H29V8Z" fill="#CE1124" />
  </svg>
  <svg id="icon-ko_KR" viewBox="0 0 28 18" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M0.1 17.9V0.1H27.9V17.9H0.1Z" fill="white" stroke="black" stroke-width="0.2" />
    <path d="M13.8786 5.0625C16.1006 5.0625 17.9106 6.8095 18.0216 9.0045C18.0286 9.0745 18.0326 9.1445 18.0326 9.2165C18.0326 9.1445 18.0286 9.0735 18.0216 9.0045C17.9146 7.9575 17.0306 7.1405 15.9556 7.1405C14.8086 7.1395 13.8786 8.0685 13.8786 9.2165C13.8786 10.3635 12.9486 11.2935 11.8016 11.2935C10.7256 11.2935 9.84161 10.4765 9.73561 9.4285C9.72861 9.3585 9.72461 9.2885 9.72461 9.2165C9.72461 6.9225 11.5846 5.0625 13.8786 5.0625Z" fill="#C60C30" />
    <path d="M13.8786 13.3677C11.6566 13.3677 9.84661 11.6207 9.73561 9.42572C9.72861 9.35572 9.72461 9.28572 9.72461 9.21372C9.72461 9.28572 9.72861 9.35672 9.73561 9.42572C9.84261 10.4727 10.7266 11.2897 11.8016 11.2897C12.9486 11.2907 13.8786 10.3617 13.8786 9.21372C13.8786 8.06672 14.8086 7.13672 15.9556 7.13672C17.0316 7.13672 17.9156 7.95372 18.0216 9.00172C18.0286 9.07172 18.0326 9.14172 18.0326 9.21372C18.0326 11.5077 16.1726 13.3677 13.8786 13.3677Z" fill="#003478" />
    <path d="M9.07192 4.22497L8.64844 3.98047L6.69344 7.36663L7.11692 7.61113L9.07192 4.22497Z" fill="black" />
    <path d="M8.22622 3.73278L7.80273 3.48828L5.84773 6.87444L6.27122 7.11894L8.22622 3.73278Z" fill="black" />
    <path d="M7.37856 3.2445L6.95508 3L5.00008 6.38616L5.42356 6.63066L7.37856 3.2445Z" fill="black" />
    <path d="M7.11685 10.818L6.69336 11.0625L8.64836 14.4487L9.07185 14.2042L7.11685 10.818Z" fill="black" />
    <path d="M6.26919 11.3102L5.8457 11.5547L6.7012 13.0365L7.12469 12.792L6.26919 11.3102Z" fill="black" />
    <path d="M7.37075 13.2125L6.94727 13.457L7.80277 14.9388L8.22625 14.6943L7.37075 13.2125Z" fill="black" />
    <path d="M5.42349 11.7985L5 12.043L6.955 15.4291L7.37849 15.1846L5.42349 11.7985Z" fill="black" />
    <path d="M21.9105 11.5526L21.4871 11.3081L20.6316 12.7899L21.0551 13.0344L21.9105 11.5526Z" fill="black" />
    <path d="M20.8101 13.4574L20.3866 13.2129L19.5311 14.6947L19.9546 14.9392L20.8101 13.4574Z" fill="black" />
    <path d="M21.0639 11.0648L20.6404 10.8203L19.7849 12.3021L20.2084 12.5466L21.0639 11.0648Z" fill="black" />
    <path d="M19.9645 12.9686L19.541 12.7241L18.6855 14.2059L19.109 14.4504L19.9645 12.9686Z" fill="black" />
    <path d="M22.757 12.0414L22.3335 11.7969L21.478 13.2787L21.9015 13.5232L22.757 12.0414Z" fill="black" />
    <path d="M21.657 13.9462L21.2335 13.7017L20.378 15.1834L20.8015 15.4279L21.657 13.9462Z" fill="black" />
    <path d="M19.9555 3.4889L19.532 3.7334L21.487 7.11956L21.9105 6.87506L19.9555 3.4889Z" fill="black" />
    <path d="M20.2089 5.88245L19.7854 6.12695L20.6409 7.60872L21.0644 7.36422L20.2089 5.88245Z" fill="black" />
    <path d="M19.109 3.97767L18.6855 4.22217L19.541 5.70394L19.9645 5.45944L19.109 3.97767Z" fill="black" />
    <path d="M21.9019 4.90442L21.4784 5.14893L22.3339 6.6307L22.7574 6.3862L21.9019 4.90442Z" fill="black" />
    <path d="M20.8015 3.00013L20.3781 3.24463L21.2336 4.7264L21.657 4.4819L20.8015 3.00013Z" fill="black" />
  </svg>
</div>

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\inc\functions\function-global.php

<?php
/**
 *
 * @return HTML - option list tỉnh thành
 */
function reder_province_option($default = "") {
  $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $tinh_thanh = json_decode($json, true);
    foreach ($tinh_thanh as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list quận huyện
 */
function reder_quan_huyen_option($tinh_thanh, $default) {
  $default    = sprintf('%02d', intval($default));
  $tinh_thanh = sprintf('%02d', intval($tinh_thanh));
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    foreach ($quan_huyen as $key => $value) {
      if ($key == $default) {
        $select = "selected";
      } else {
        $select = "";
      }
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list xã phường
 */
function reder_xa_phuong_option($quan_huyen, $default) {
  $default    = intval($default);
  $quan_huyen = sprintf('%03d', intval($quan_huyen));
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * AJAX load quận huyện khi select tỉnh thành phố
 */
add_action('wp_ajax_load_quan_huyen', 'load_quan_huyen');
function load_quan_huyen() {
  $tinh_thanh = $_POST['id'];
  $type       = $_POST['type'];
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    echo '<option value="" disabled selected >' . __("Select", "golf") . '</option>';
    foreach ($quan_huyen as $key => $value) {
      if ($type) {
        echo "<option value='" . $value["name_with_type"] . "'>" . $value["name_with_type"] . "</option>";
      } else {
        echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
      }
    }
  }
  die();
}
/**
 * AJAX load danh sách xã phường khi select tỉnh thành phố
 */
add_action('wp_ajax_load_xa_phuong', 'load_xa_phuong');
function load_xa_phuong() {
  $quan_huyen = $_POST['id'];
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
  die();
}
/**
 *
 * Get địa chỉ của user bởi id
 * Nếu chưa update địa chỉ, thì gán mặc định là: '90 Đường Lê Lợi, Phường Bến Thành, Quận 1, Thành phố Hồ Chí Minh'
 */
function get_address_by_id_user($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_user_meta($user_id, "province_address", true);
  if ($province_address) {
    return json_decode($province_address, true);
  }
  return array(
    'province' => 79,
    'district' => 760,
    'ward'     => 26743,
    'street'   => '90 Đường Lê Lợi',
  );
}
/**
 * Get địa chỉ text
 * @return array
 */
function atw_load_province_address($user_id = null) {
  $province = '';
  $district = '';
  $ward     = '';
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_address_by_id_user($user_id);
  if ($province_address && is_array($province_address)) {
    $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
    if (file_exists($json_file)) {
      $json_tinh_tp = file_get_contents($json_file);
      $tinh_thanh   = json_decode($json_tinh_tp, true);
      foreach ($tinh_thanh as $key => $value) {
        if ($key == $province_address['province']) {
          $province = $tinh_thanh[$key]['name'];
          break;
        }
      }
    }
    if ($province_address['province']):
      $json_file = get_stylesheet_directory() . "/json/quan-huyen/" . $province_address['province'] . ".json";
      if (file_exists($json_file)) {
        $json_quan_huyen = file_get_contents($json_file);
        $quan_huyen      = json_decode($json_quan_huyen, true);
        foreach ($quan_huyen as $key => $value) {
          if ($key == $province_address['district']) {
            $district = $quan_huyen[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
    if ($province_address['district']):
      $json_file = get_stylesheet_directory() . "/json/xa-phuong/" . $province_address['district'] . ".json";
      if (file_exists($json_file)) {
        $json_xa_phuong = file_get_contents($json_file);
        $xa_phuong      = json_decode($json_xa_phuong, true);
        foreach ($xa_phuong as $key => $value) {
          if ($key == $province_address['ward']) {
            $ward = $xa_phuong[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
  }
  return array(
    'province' => $province,
    'district' => $district,
    'ward'     => $ward,
    'street'   => $province_address['street'],
  );
}
/**
 *
 * Crop image
 */
function resize_image($method, $image_loc, $new_loc, $width, $height) {
  $exif = exif_read_data($image_loc);
  if (isset($exif['Orientation']) && $exif['Orientation'] === 6) {
    $rotate = -90;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 3) {
    $rotate = 180;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 8) {
    $rotate = 90;
  }
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array();}
  if (!in_array($method, array('force', 'max', 'crop'))) {$GLOBALS['errors'][] = 'Invalid method selected.';}
  if (!$image_loc) {$GLOBALS['errors'][] = 'No source image location specified.';} else {
    if ((substr(strtolower($image_loc), 0, 7) == 'http://') || (substr(strtolower($image_loc), 0, 7) == 'https://')) { /*don't check to see if file exists since it's not local*/} elseif (!file_exists($image_loc)) {$GLOBALS['errors'][] = 'Image source file does not exist.';}
    $extension = strtolower(substr($image_loc, strrpos($image_loc, '.')));
    if (!in_array($extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid source file extension!';}
  }
  if (!$new_loc) {$GLOBALS['errors'][] = 'No destination image location specified.';} else {
    $new_extension = strtolower(substr($new_loc, strrpos($new_loc, '.')));
    if (!in_array($new_extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid destination file extension!';}
  }
  $width = abs(intval($width));
  if (!$width) {$GLOBALS['errors'][] = 'No width specified!';}
  $height = abs(intval($height));
  if (!$height) {$GLOBALS['errors'][] = 'No height specified!';}
  if (count($GLOBALS['errors']) > 0) {echo_errors();return false;}
  if (in_array($extension, array('.jpg', '.jpeg'))) {$image = @imagecreatefromjpeg($image_loc);} elseif ($extension == '.png') {$image = @imagecreatefrompng($image_loc);} elseif ($extension == '.gif') {$image = @imagecreatefromgif($image_loc);} elseif ($extension == '.bmp') {$image = @imagecreatefromwbmp($image_loc);}
  if (!$image) {$GLOBALS['errors'][] = 'Image could not be generated!';} else {
    $current_width  = imagesx($image);
    $current_height = imagesy($image);
    if ((!$current_width) || (!$current_height)) {$GLOBALS['errors'][] = 'Generated image has invalid dimensions!';}
  }
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  if ($method == 'force') {$new_image = resize_image_force($image, $width, $height);} elseif ($method == 'max') {$new_image = resize_image_max($image, $width, $height);} elseif ($method == 'crop') {$new_image = resize_image_crop($image, $width, $height);}
  if ((!$new_image) && (count($GLOBALS['errors'] == 0))) {$GLOBALS['errors'][] = 'New image could not be generated!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  $save_error = false;
  if (in_array($extension, array('.jpg', '.jpeg'))) {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagejpeg($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.png') {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagepng($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.gif') {imagegif($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.bmp') {imagewbmp($new_image, $new_loc) or ($save_error = true);}
  if ($save_error) {$GLOBALS['errors'][] = 'New image could not be saved!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);@imagedestroy($new_image);
    echo_errors();return false;}
  imagedestroy($image);
  imagedestroy($new_image);
  return true;
}
function echo_errors() {
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array('Unknown error!');}
  foreach ($GLOBALS['errors'] as $error) {echo '<p style="color:red;font-weight:bold;">Error: ' . $error . '</p>';}
}
function resize_image_force($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  $image2 = imagecreatetruecolor($width, $height);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $width, $height, $w, $h);
  return $image2;
}
function resize_image_max($image, $max_width, $max_height) {
  $w = imagesx($image); //current width
  $h = imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w <= $max_width) && ($h <= $max_height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $max_width / $w;
  $new_w = $max_width;
  $new_h = $h * $ratio;
  //if that didn't work
  if ($new_h > $max_height) {
    $ratio = $max_height / $h;
    $new_h = $max_height;
    $new_w = $w * $ratio;
  }
  $new_image = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  return $new_image;
}
function resize_image_crop($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $width / $w;
  $new_w = $width;
  $new_h = $h * $ratio;
  //if that created an image smaller than what we wanted, try the other way
  if ($new_h < $height) {
    $ratio = $height / $h;
    $new_h = $height;
    $new_w = $w * $ratio;
  }
  $image2 = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  //check to see if cropping needs to happen
  if (($new_h != $height) || ($new_w != $width)) {
    $image3 = imagecreatetruecolor($width, $height);
    if ($new_h > $height) {
      //crop vertically
      $extra = $new_h - $height;
      $x     = 0; //source x
      $y     = round($extra / 2); //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    } else {
      $extra = $new_w - $width;
      $x     = round($extra / 2); //source x
      $y     = 0; //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    }
    imagedestroy($image2);
    return $image3;
  } else {
    return $image2;
  }
}
function upload_image($file) {
  $targetDir      = wp_upload_dir()["basedir"] . '/image-files/';
  $allowTypes     = array('jpg', 'png', 'jpeg');
  $fileName       = round(microtime(true)) . "_" . basename($file['name']);
  $targetFilePath = $targetDir . $fileName;
  // Check whether file type is valid
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
  if (in_array($fileType, $allowTypes)) {
    if ($file["size"] > 10000000) {
      return array("status" => "error", "content" => "Maximum 10Mb");
    }
    if (move_uploaded_file($file['tmp_name'], $targetFilePath)) {
      resize_image('crop', $targetDir . $fileName, $targetDir . '200x200/' . $fileName, 200, 200);
      $file_id = umm_model_insert_img($fileName);
      return array("status" => "success", "content" => $file_id);
    }
  } else {
    return array("status" => "error", "content" => "Allow jpg, png, jpeg");
  }
}
function umm_model_insert_img($file_name) {
  global $wpdb;
  $table  = $wpdb->prefix . 'images';
  $data   = array('image_name' => $file_name, 'user_id' => get_current_user_id());
  $format = array('%s', '%d');
  $wpdb->insert($table, $data, $format);
  return $wpdb->insert_id;
}
function get_image_url_by_id($id, $size = "full") {
  $url = wp_get_upload_dir()["baseurl"] . "/image-files/";
  if ($size != "full") {
    $url = wp_get_upload_dir()["baseurl"] . "/image-files/200x200/";
  }
  global $wpdb;
  $table  = $wpdb->prefix . "images";
  $result = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $id), ARRAY_A, 1);
  return $url . $result[0]["image_name"];
}
/**
 *
 * Delete uploaded images file, database
 */
function delete_img_by_id($img_id) {
  global $wpdb;
  $table     = $wpdb->prefix . "images";
  $result    = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $img_id), ARRAY_A, 1);
  $file_name = $result[0]["image_name"];
  $folder    = wp_upload_dir()["basedir"] . '/image-files/';
  unlink($folder . $file_name);
  unlink($folder . "200x200/" . $file_name);
  $wpdb->delete($table, array('id' => $img_id), array('%d'));
}
/**
 *
 * Get image url avatar  by user id
 */
function get_url_avatar($user_id = '') {
  if ($user_id === '') {
    $user_id = get_current_user_id();
  }
  $id_avatar = get_user_meta($user_id, 'id_img_avatar', true);
  if ($id_avatar) {
    return get_image_url_by_id($id_avatar, 'thumbnail');
  }
  return AVATAR_DF;
}
/**
 *
 * Check user exists
 * @return boolean
 */
function is_user_exist($user_id) {
  $user       = get_userdata($user_id);
  $user_roles = !empty($user) ? $user->roles[0] : "";
  if ($user === false or $user_roles != USER) {
    return false;
  } else {
    return true;
  }
}
/**
 *
 * Check View other account
 * @return boolean
 */
function is_view_other_account() {
  if (is_page('account') && isset($_GET['id']) && intval($_GET['id']) !== get_current_user_id()) {
    return true;
  }
  return false;
}
/**
 *
 * Get list user follow
 * @return array
 */
function list_user_follow($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $list_user_follow = get_user_meta($user_id, 'list_user_follow', true);
  if (!$list_user_follow) {
    return array();
  }
  return json_decode($list_user_follow, true);
}
/**
 *
 * Nhận danh sách người theo dõi tôi
 * @return array
 */
function get_list_follower($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  $args              = array('role' => USER);
  $users             = get_users($args);
  $list_follower_arr = [];
  foreach ($users as $value) {
    $user_id         = $value->ID;
    $list_follow_arr = list_user_follow($user_id);
    if ($list_follow_arr):
      if (in_array($current_user_id, $list_follow_arr)) {
        $list_follower_arr[] = $user_id;
      }
    endif;
  }
  return $list_follower_arr;
}
/**
 *
 * Nhận tổng số người tôi đang theo dõi
 * @return int
 */
function get_total_following($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  return count(list_user_follow($current_user_id));
}
/**
 * tăng lên 1 so tổng thông báo mới hiện tại của user ID
 */
function update_total_notify_user($user_id){
  $total = (int)get_user_meta( $user_id, 'total_notify', true ) + 1;
  update_user_meta( $user_id, 'total_notify', $total);
}
// ==
function get_market_image_url($img_id){
  $url = wp_get_upload_dir()["baseurl"]."/market-images/";
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $result = $wpdb->get_results ( $wpdb->prepare(" SELECT image_name FROM  {$table} WHERE id = %d ",$img_id) ,ARRAY_A  );
  if(!empty($result)){
    return $url."__".$result[0]["image_name"];
  }else{
    return THEME_URL."assets/images/default.jpg";
  }
}
function market_upload_image($file){
  $targetDir = wp_upload_dir()["basedir"].'/market-images/'; 
  $allowTypes = array( 'jpg', 'png', 'jpeg'); 
  $fileName = round(microtime(true))."_".basename($file['name']);
  $targetFilePath = $targetDir.$fileName; 
    // Check whether file type is valid 
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
  if(in_array($fileType, $allowTypes)){ 
    if($file["size"] > 5000000) return array("status" => "error","content" => "Maximum 5Mb");
    if(move_uploaded_file($file['tmp_name'], $targetFilePath)){ 
      $result = resize_image('max',$targetDir.$fileName,$targetDir.'__'.$fileName,600,4000);
      if($result == true){
        $file_id = add_market_image_to_db($fileName);
        unlink($targetDir.$fileName);
        return array("status" => "success","content" => $file_id);
      }
    }else{
      return array("status" => "error","content" => "Unknow");
    } 
  }else{
    return array("status" => "error","content" => "Allow jpg, png, jpeg");
  }
}
function add_market_image_to_db($file_name){
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $wpdb->insert($table,
    array("image_name" => $file_name),
    array("%s")
  );
  return $wpdb->insert_id;
}
/**
 * 
 * Get role and check member group
 * @return int
 */
function is_member_of_group($group_id = 0,$user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $current_list_member_arr = json_decode(get_term_meta($group_id,"list_member",true),true);
  if(!empty($current_list_member_arr)){
    foreach ($current_list_member_arr as $value) {
      if(isset($value["user_id"]) && $value["user_id"] == $user_id){
        if (isset($value["role"])) return $value["role"];
      }
    }
  }else{
    return false;
  }
}
/**
 * 
 * Get all id group have join
 * @return array
 */
function all_groups_have_joined($user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $list_groups = array();
  $terms = get_terms( ['hide_empty' => false, 'taxonomy'  => 'group', 'meta_key'  => 'list_member'] );
  if ($terms) {
  foreach ($terms as $value) {
      $group_id = $value->term_id;
      $role = is_member_of_group($group_id, $user_id);
      if( $role ) $list_groups[] = $group_id;
    }
  }
  return $list_groups;
}
/**
 * 
 * Get banner group
 * @return string - banner
 */
function get_banner_group($id_gr, $size = 'thumbnail') {
  $id_banner_gr = get_term_meta($id_gr, 'image_cover_group');
  if( $id_banner_gr ) return get_image_url_by_id($id_banner_gr, $size);
  return BANNER_DF;
}
/**
 * Search Filters
 */
add_action( 'wp_ajax_search_by_filters', 'search_by_filters' );
function search_by_filters(){
  $current_user_id = get_current_user_id();
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'ajax-nonce'.$current_user_id)) wp_die();
  $key_word = sanitize_text_field($_POST['keyword']);
  $type = $_POST['type'];
  if ($type == 'people'){
    $args= array(
      'search' => '*'.$key_word.'*', 
      'search_columns' => array( 'display_name','user_email'),
      'exclude' => array($current_user_id),
      'role'  => USER,
    );
    $users = get_users($args); 
    foreach ($users as $value) {
      $data['link'] = SITE_URL."account/?id=".$value->ID."&appt=N";
      $data['name'] = $value->display_name;
      $data['avatar'] = get_url_avatar($value->ID);
      get_template_part( 'layout/searchs/item', 'account', $data);
    }
  } else if ( $type =='group' ) {
    $args = array(
      'taxonomy'      => 'group',
      'hide_empty'    => false,
      'name__like'    => $key_word,
    );
    $terms = get_terms( $args );
    foreach ($terms as $value) {
      $id_gr = $value->term_id;
      $data['id'] = $id_gr;
      $data['link'] = SITE_URL . "community/?action=view-group&id={$id_gr}&appt=N";
      $data['banner'] = get_banner_group($id_gr);
      $data['name'] = get_term($id_gr)->name;
      get_template_part( 'layout/searchs/item', 'group', $data);
    }
  }
  wp_die();
}
/**
 * Change language
 * 
 */
add_action( 'wp_ajax_nopriv_at_change_language', 'at_change_language' );
add_action( 'wp_ajax_at_change_language', 'at_change_language' );
function at_change_language(){
  $lang = sanitize_text_field($_POST['lang']);
  $cookie_name = "app_language";
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'language' )) die("Token");
  echo setcookie($cookie_name, $lang,time()+604800, "/","", 0);
  die();
}

Notifications

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\js\custom.js

jQuery(document).ready(function($) {
  function addLoading() {
    $('#page-load').css({ 'opacity': '1', 'visibility': 'visible' });
  }
  function unLoading() {
    $('#page-load').css({ 'opacity': '0', 'visibility': 'hidden' });
  }
  const boxMessage = $('.notifi__update');
  $("body").on("submit", "form#form-update-info", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-info"));
    fd.append('action', 'app_update_info');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var result = $.parseJSON(output);
        if (result.status === false) {
          setTimeout(() => {
            var currURL = window.location.href;
            var urlReload = replaceUrlParam(currURL, 'appt', 'C');
            window.location.replace(urlReload);
          }, 1500)
        } else {
          boxMessage.text(result.message);
        }
        boxMessage.removeClass('hidden');
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  $("input").blur(function() {
    boxMessage.addClass('hidden');
  });
  $("#event-datepicker").datepicker({
    onSelect: function() {
      let dateObject = $(this).datepicker('getDate');
      $("#date").val($.datepicker.formatDate("yy-mm-dd", dateObject));
    }
  });
  $("body").on("submit", "form#form-update-post", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-post"));
    fd.append('action', 'edit_post_single');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var currURL = window.location.href;
        currURL = currURL.split('?')[0];
        currURL = currURL + "?appt=C";
        window.location.replace(currURL);
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  // For Search
  var typeSearch = $('.filters__item.active').data('type');
  const boxResult = $('.box-results__list');
  $("body").on("click", ".filters__item", function(e) {
    $('.filters__item').removeClass('active');
    $(this).addClass('active');
    typeSearch = $('.filters__item.active').data('type');
    const keyWord = $('#search').val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  })
  $("#search").keyup(function() {
    const keyWord = $(this).val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  });
  function searchFilter(keyWord, typeSearch) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'search_by_filters',
        keyword: keyWord,
        type: typeSearch,
        token: $('#nonce_token').val(),
      },
      beforeSend: function() {
        boxResult.css('opacity', '0.6');
      },
      success: function(output) {
        boxResult.css('opacity', '1');
        boxResult.html(output);
      },
      error: function() { alert('error'); }
    });
  }
  // For App Logout
  $("body").on("click", ".app_logout", function(e) {
    e.preventDefault();
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'app_logout',
        token: $('#nonce_token').val(),
      },
      success: function(output) {
        if (output == "success") {
          window.appBridge.clearCookie();
          var expire = new Date();
          expire.setDate(expire.getDate() + 1000);
          cookies = "APP_LOGIN" + '=' + escape('false') + ';'
          cookies += ';expires=' + expire.toGMTString() + ';';
          document.cookie = cookies;
          location.href = "/login"
        }
      },
    });
  });
  // For set Language
  $('input[type=radio][name=language]').change(function(e) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'at_change_language',
        lang: $(this).val(),
        token: $("#language-token").val(),
      },
      success: function(output) {
        if (output == "1") {
          location.reload(true);
        } else {
          alert('error');
        }
      },
    });
  });
  // For Change Nonce
  $('#checkbox').change(function(e) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'at_change_nonce',
        lang: $(this).val(),
        token: $("#language-nonce").val(),
      },
      success: function(output) {
        if(output == 1) {
          alert("Update Success");
        }else {
          alert("Update Error");
        }
      },
    });
  });
});

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\controllers\Account.php

<?php
class BJ_Account_Controller extends Pv_Controller {
  function __construct() {
    if (isset($_GET['action'])):
      switch ($_GET['action']) {
      case "edit-info":
        $this->update_info();
        break;
      case "followers":
        $this->followers();
        break;
      case "following":
        $this->following();
        break;
      case "add-deal":
        $this->adddeal();
      break;
      case "add-event":
        $this->addevent();
      break;
      case "add-post":
        $this->addposts();
      break;
      case "settings":
        $this->settings();
      break;
      case "language":
        $this->language();
      break;
      case "setting-notifi":
        $this->setting_notifi();
      break;
      default:
        $this->index();
      } else :
      $this->index();
    endif;
  }
  private function get_user_id() {
    if (isset($_GET["id"]) && is_user_exist(strip_tags($_GET["id"]))) {
      return $_GET["id"];
    } else {
      return get_current_user_id();
    }
  }
  public function index() {
    $data                         = array();
    $user_id                      = $this->get_user_id();
    $user_obj                     = get_userdata($user_id);
    $data['id']                   = $user_id;
    $data['display_name']         = $user_obj->display_name;
    $data['date_registered']      = date_i18n(__('jS F Y', 'umm'), strtotime($user_obj->user_registered));
    $data['avatar']               = get_url_avatar($user_id);
    $data['province_address_arr'] = atw_load_province_address($user_id);
    $this->load()->View("account", $data, "account");
  }
  public function update_info() {
    $data = array();
    $this->load()->View("update-info", $data, "account");
  }
  public function followers() {
    $current_user_id       = $this->get_user_id();
    $data                  = array();
    $data['list_follower'] = get_list_follower($current_user_id);
    $this->load()->View("followers", $data, "account");
  }
  public function following() {
    $user_id             = $this->get_user_id();
    $data                = array();
    $data['list_follow'] = list_user_follow($user_id);
    $this->load()->View("following", $data, "account");
  }
  public function adddeal() {
    $this->load()->View("add-deal", '', "deal"); 
  }
  public function addevent() {
    $this->load()->View("add-event", '', "event"); 
  }
  public function addposts() {
    $this->load()->View("add-post", '', "post"); 
  }
  public function settings() {
    $data = array();
    $this->load()->View("settings", $data, "account");
  }
  public function language(){
    $data = array();
    $this->load()->View("language", $data, "account");
  }
  public function setting_notifi(){
    $data = array();
    $this->load()->View("setting-notifi", $data, "account");
  }
}
function render_province_option($default = ""){  
  $json = file_get_contents(get_stylesheet_directory()."/json/tinh_tp.json");
  $tinh_thanh = json_decode($json,true);
  foreach ($tinh_thanh as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name"]."</option>";
  }
}
function render_xa_phuong_option($quan_huyen,$default=""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/xa-phuong/".$quan_huyen.".json");
  $xa_phuong = json_decode($json,true);
  foreach ($xa_phuong as $key => $value) {
      if($key == $default){$select = "selected";}else{$select = "";}
      echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
    }
}
function render_quan_huyen_option($tinh_thanh,$default = ""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/quan-huyen/".$tinh_thanh.".json");
  $quan_huyen = json_decode($json,true);  
  foreach ($quan_huyen as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
  }  
}

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\inc\functions\function-global.php

<?php
/**
 *
 * @return HTML - option list tỉnh thành
 */
function reder_province_option($default = "") {
  $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $tinh_thanh = json_decode($json, true);
    foreach ($tinh_thanh as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list quận huyện
 */
function reder_quan_huyen_option($tinh_thanh, $default) {
  $default    = sprintf('%02d', intval($default));
  $tinh_thanh = sprintf('%02d', intval($tinh_thanh));
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    foreach ($quan_huyen as $key => $value) {
      if ($key == $default) {
        $select = "selected";
      } else {
        $select = "";
      }
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list xã phường
 */
function reder_xa_phuong_option($quan_huyen, $default) {
  $default    = intval($default);
  $quan_huyen = sprintf('%03d', intval($quan_huyen));
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * AJAX load quận huyện khi select tỉnh thành phố
 */
add_action('wp_ajax_load_quan_huyen', 'load_quan_huyen');
function load_quan_huyen() {
  $tinh_thanh = $_POST['id'];
  $type       = $_POST['type'];
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    echo '<option value="" disabled selected >' . __("Select", "golf") . '</option>';
    foreach ($quan_huyen as $key => $value) {
      if ($type) {
        echo "<option value='" . $value["name_with_type"] . "'>" . $value["name_with_type"] . "</option>";
      } else {
        echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
      }
    }
  }
  die();
}
/**
 * AJAX load danh sách xã phường khi select tỉnh thành phố
 */
add_action('wp_ajax_load_xa_phuong', 'load_xa_phuong');
function load_xa_phuong() {
  $quan_huyen = $_POST['id'];
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
  die();
}
/**
 *
 * Get địa chỉ của user bởi id
 * Nếu chưa update địa chỉ, thì gán mặc định là: '90 Đường Lê Lợi, Phường Bến Thành, Quận 1, Thành phố Hồ Chí Minh'
 */
function get_address_by_id_user($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_user_meta($user_id, "province_address", true);
  if ($province_address) {
    return json_decode($province_address, true);
  }
  return array(
    'province' => 79,
    'district' => 760,
    'ward'     => 26743,
    'street'   => '90 Đường Lê Lợi',
  );
}
/**
 * Get địa chỉ text
 * @return array
 */
function atw_load_province_address($user_id = null) {
  $province = '';
  $district = '';
  $ward     = '';
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_address_by_id_user($user_id);
  if ($province_address && is_array($province_address)) {
    $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
    if (file_exists($json_file)) {
      $json_tinh_tp = file_get_contents($json_file);
      $tinh_thanh   = json_decode($json_tinh_tp, true);
      foreach ($tinh_thanh as $key => $value) {
        if ($key == $province_address['province']) {
          $province = $tinh_thanh[$key]['name'];
          break;
        }
      }
    }
    if ($province_address['province']):
      $json_file = get_stylesheet_directory() . "/json/quan-huyen/" . $province_address['province'] . ".json";
      if (file_exists($json_file)) {
        $json_quan_huyen = file_get_contents($json_file);
        $quan_huyen      = json_decode($json_quan_huyen, true);
        foreach ($quan_huyen as $key => $value) {
          if ($key == $province_address['district']) {
            $district = $quan_huyen[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
    if ($province_address['district']):
      $json_file = get_stylesheet_directory() . "/json/xa-phuong/" . $province_address['district'] . ".json";
      if (file_exists($json_file)) {
        $json_xa_phuong = file_get_contents($json_file);
        $xa_phuong      = json_decode($json_xa_phuong, true);
        foreach ($xa_phuong as $key => $value) {
          if ($key == $province_address['ward']) {
            $ward = $xa_phuong[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
  }
  return array(
    'province' => $province,
    'district' => $district,
    'ward'     => $ward,
    'street'   => $province_address['street'],
  );
}
/**
 *
 * Crop image
 */
function resize_image($method, $image_loc, $new_loc, $width, $height) {
  $exif = exif_read_data($image_loc);
  if (isset($exif['Orientation']) && $exif['Orientation'] === 6) {
    $rotate = -90;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 3) {
    $rotate = 180;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 8) {
    $rotate = 90;
  }
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array();}
  if (!in_array($method, array('force', 'max', 'crop'))) {$GLOBALS['errors'][] = 'Invalid method selected.';}
  if (!$image_loc) {$GLOBALS['errors'][] = 'No source image location specified.';} else {
    if ((substr(strtolower($image_loc), 0, 7) == 'http://') || (substr(strtolower($image_loc), 0, 7) == 'https://')) { /*don't check to see if file exists since it's not local*/} elseif (!file_exists($image_loc)) {$GLOBALS['errors'][] = 'Image source file does not exist.';}
    $extension = strtolower(substr($image_loc, strrpos($image_loc, '.')));
    if (!in_array($extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid source file extension!';}
  }
  if (!$new_loc) {$GLOBALS['errors'][] = 'No destination image location specified.';} else {
    $new_extension = strtolower(substr($new_loc, strrpos($new_loc, '.')));
    if (!in_array($new_extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid destination file extension!';}
  }
  $width = abs(intval($width));
  if (!$width) {$GLOBALS['errors'][] = 'No width specified!';}
  $height = abs(intval($height));
  if (!$height) {$GLOBALS['errors'][] = 'No height specified!';}
  if (count($GLOBALS['errors']) > 0) {echo_errors();return false;}
  if (in_array($extension, array('.jpg', '.jpeg'))) {$image = @imagecreatefromjpeg($image_loc);} elseif ($extension == '.png') {$image = @imagecreatefrompng($image_loc);} elseif ($extension == '.gif') {$image = @imagecreatefromgif($image_loc);} elseif ($extension == '.bmp') {$image = @imagecreatefromwbmp($image_loc);}
  if (!$image) {$GLOBALS['errors'][] = 'Image could not be generated!';} else {
    $current_width  = imagesx($image);
    $current_height = imagesy($image);
    if ((!$current_width) || (!$current_height)) {$GLOBALS['errors'][] = 'Generated image has invalid dimensions!';}
  }
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  if ($method == 'force') {$new_image = resize_image_force($image, $width, $height);} elseif ($method == 'max') {$new_image = resize_image_max($image, $width, $height);} elseif ($method == 'crop') {$new_image = resize_image_crop($image, $width, $height);}
  if ((!$new_image) && (count($GLOBALS['errors'] == 0))) {$GLOBALS['errors'][] = 'New image could not be generated!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  $save_error = false;
  if (in_array($extension, array('.jpg', '.jpeg'))) {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagejpeg($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.png') {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagepng($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.gif') {imagegif($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.bmp') {imagewbmp($new_image, $new_loc) or ($save_error = true);}
  if ($save_error) {$GLOBALS['errors'][] = 'New image could not be saved!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);@imagedestroy($new_image);
    echo_errors();return false;}
  imagedestroy($image);
  imagedestroy($new_image);
  return true;
}
function echo_errors() {
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array('Unknown error!');}
  foreach ($GLOBALS['errors'] as $error) {echo '<p style="color:red;font-weight:bold;">Error: ' . $error . '</p>';}
}
function resize_image_force($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  $image2 = imagecreatetruecolor($width, $height);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $width, $height, $w, $h);
  return $image2;
}
function resize_image_max($image, $max_width, $max_height) {
  $w = imagesx($image); //current width
  $h = imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w <= $max_width) && ($h <= $max_height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $max_width / $w;
  $new_w = $max_width;
  $new_h = $h * $ratio;
  //if that didn't work
  if ($new_h > $max_height) {
    $ratio = $max_height / $h;
    $new_h = $max_height;
    $new_w = $w * $ratio;
  }
  $new_image = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  return $new_image;
}
function resize_image_crop($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $width / $w;
  $new_w = $width;
  $new_h = $h * $ratio;
  //if that created an image smaller than what we wanted, try the other way
  if ($new_h < $height) {
    $ratio = $height / $h;
    $new_h = $height;
    $new_w = $w * $ratio;
  }
  $image2 = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  //check to see if cropping needs to happen
  if (($new_h != $height) || ($new_w != $width)) {
    $image3 = imagecreatetruecolor($width, $height);
    if ($new_h > $height) {
      //crop vertically
      $extra = $new_h - $height;
      $x     = 0; //source x
      $y     = round($extra / 2); //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    } else {
      $extra = $new_w - $width;
      $x     = round($extra / 2); //source x
      $y     = 0; //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    }
    imagedestroy($image2);
    return $image3;
  } else {
    return $image2;
  }
}
function upload_image($file) {
  $targetDir      = wp_upload_dir()["basedir"] . '/image-files/';
  $allowTypes     = array('jpg', 'png', 'jpeg');
  $fileName       = round(microtime(true)) . "_" . basename($file['name']);
  $targetFilePath = $targetDir . $fileName;
  // Check whether file type is valid
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
  if (in_array($fileType, $allowTypes)) {
    if ($file["size"] > 10000000) {
      return array("status" => "error", "content" => "Maximum 10Mb");
    }
    if (move_uploaded_file($file['tmp_name'], $targetFilePath)) {
      resize_image('crop', $targetDir . $fileName, $targetDir . '200x200/' . $fileName, 200, 200);
      $file_id = umm_model_insert_img($fileName);
      return array("status" => "success", "content" => $file_id);
    }
  } else {
    return array("status" => "error", "content" => "Allow jpg, png, jpeg");
  }
}
function umm_model_insert_img($file_name) {
  global $wpdb;
  $table  = $wpdb->prefix . 'images';
  $data   = array('image_name' => $file_name, 'user_id' => get_current_user_id());
  $format = array('%s', '%d');
  $wpdb->insert($table, $data, $format);
  return $wpdb->insert_id;
}
function get_image_url_by_id($id, $size = "full") {
  $url = wp_get_upload_dir()["baseurl"] . "/image-files/";
  if ($size != "full") {
    $url = wp_get_upload_dir()["baseurl"] . "/image-files/200x200/";
  }
  global $wpdb;
  $table  = $wpdb->prefix . "images";
  $result = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $id), ARRAY_A, 1);
  return $url . $result[0]["image_name"];
}
/**
 *
 * Delete uploaded images file, database
 */
function delete_img_by_id($img_id) {
  global $wpdb;
  $table     = $wpdb->prefix . "images";
  $result    = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $img_id), ARRAY_A, 1);
  $file_name = $result[0]["image_name"];
  $folder    = wp_upload_dir()["basedir"] . '/image-files/';
  unlink($folder . $file_name);
  unlink($folder . "200x200/" . $file_name);
  $wpdb->delete($table, array('id' => $img_id), array('%d'));
}
/**
 *
 * Get image url avatar  by user id
 */
function get_url_avatar($user_id = '') {
  if ($user_id === '') {
    $user_id = get_current_user_id();
  }
  $id_avatar = get_user_meta($user_id, 'id_img_avatar', true);
  if ($id_avatar) {
    return get_image_url_by_id($id_avatar, 'thumbnail');
  }
  return AVATAR_DF;
}
/**
 *
 * Check user exists
 * @return boolean
 */
function is_user_exist($user_id) {
  $user       = get_userdata($user_id);
  $user_roles = !empty($user) ? $user->roles[0] : "";
  if ($user === false or $user_roles != USER) {
    return false;
  } else {
    return true;
  }
}
/**
 *
 * Check View other account
 * @return boolean
 */
function is_view_other_account() {
  if (is_page('account') && isset($_GET['id']) && intval($_GET['id']) !== get_current_user_id()) {
    return true;
  }
  return false;
}
/**
 *
 * Get list user follow
 * @return array
 */
function list_user_follow($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $list_user_follow = get_user_meta($user_id, 'list_user_follow', true);
  if (!$list_user_follow) {
    return array();
  }
  return json_decode($list_user_follow, true);
}
/**
 *
 * Nhận danh sách người theo dõi tôi
 * @return array
 */
function get_list_follower($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  $args              = array('role' => USER);
  $users             = get_users($args);
  $list_follower_arr = [];
  foreach ($users as $value) {
    $user_id         = $value->ID;
    $list_follow_arr = list_user_follow($user_id);
    if ($list_follow_arr):
      if (in_array($current_user_id, $list_follow_arr)) {
        $list_follower_arr[] = $user_id;
      }
    endif;
  }
  return $list_follower_arr;
}
/**
 *
 * Nhận tổng số người tôi đang theo dõi
 * @return int
 */
function get_total_following($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  return count(list_user_follow($current_user_id));
}
/**
 * tăng lên 1 so tổng thông báo mới hiện tại của user ID
 */
function update_total_notify_user($user_id){
  $total = (int)get_user_meta( $user_id, 'total_notify', true ) + 1;
  update_user_meta( $user_id, 'total_notify', $total);
}
// ==
function get_market_image_url($img_id){
  $url = wp_get_upload_dir()["baseurl"]."/market-images/";
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $result = $wpdb->get_results ( $wpdb->prepare(" SELECT image_name FROM  {$table} WHERE id = %d ",$img_id) ,ARRAY_A  );
  if(!empty($result)){
    return $url."__".$result[0]["image_name"];
  }else{
    return THEME_URL."assets/images/default.jpg";
  }
}
function market_upload_image($file){
  $targetDir = wp_upload_dir()["basedir"].'/market-images/'; 
  $allowTypes = array( 'jpg', 'png', 'jpeg'); 
  $fileName = round(microtime(true))."_".basename($file['name']);
  $targetFilePath = $targetDir.$fileName; 
    // Check whether file type is valid 
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
  if(in_array($fileType, $allowTypes)){ 
    if($file["size"] > 5000000) return array("status" => "error","content" => "Maximum 5Mb");
    if(move_uploaded_file($file['tmp_name'], $targetFilePath)){ 
      $result = resize_image('max',$targetDir.$fileName,$targetDir.'__'.$fileName,600,4000);
      if($result == true){
        $file_id = add_market_image_to_db($fileName);
        unlink($targetDir.$fileName);
        return array("status" => "success","content" => $file_id);
      }
    }else{
      return array("status" => "error","content" => "Unknow");
    } 
  }else{
    return array("status" => "error","content" => "Allow jpg, png, jpeg");
  }
}
function add_market_image_to_db($file_name){
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $wpdb->insert($table,
    array("image_name" => $file_name),
    array("%s")
  );
  return $wpdb->insert_id;
}
/**
 * 
 * Get role and check member group
 * @return int
 */
function is_member_of_group($group_id = 0,$user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $current_list_member_arr = json_decode(get_term_meta($group_id,"list_member",true),true);
  if(!empty($current_list_member_arr)){
    foreach ($current_list_member_arr as $value) {
      if(isset($value["user_id"]) && $value["user_id"] == $user_id){
        if (isset($value["role"])) return $value["role"];
      }
    }
  }else{
    return false;
  }
}
/**
 * 
 * Get all id group have join
 * @return array
 */
function all_groups_have_joined($user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $list_groups = array();
  $terms = get_terms( ['hide_empty' => false, 'taxonomy'  => 'group', 'meta_key'  => 'list_member'] );
  if ($terms) {
  foreach ($terms as $value) {
      $group_id = $value->term_id;
      $role = is_member_of_group($group_id, $user_id);
      if( $role ) $list_groups[] = $group_id;
    }
  }
  return $list_groups;
}
/**
 * 
 * Get banner group
 * @return string - banner
 */
function get_banner_group($id_gr, $size = 'thumbnail') {
  $id_banner_gr = get_term_meta($id_gr, 'image_cover_group');
  if( $id_banner_gr ) return get_image_url_by_id($id_banner_gr, $size);
  return BANNER_DF;
}
/**
 * Search Filters
 */
add_action( 'wp_ajax_search_by_filters', 'search_by_filters' );
function search_by_filters(){
  $current_user_id = get_current_user_id();
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'ajax-nonce'.$current_user_id)) wp_die();
  $key_word = sanitize_text_field($_POST['keyword']);
  $type = $_POST['type'];
  if ($type == 'people'){
    $args= array(
      'search' => '*'.$key_word.'*', 
      'search_columns' => array( 'display_name','user_email'),
      'exclude' => array($current_user_id),
      'role'  => USER,
    );
    $users = get_users($args); 
    foreach ($users as $value) {
      $data['link'] = SITE_URL."account/?id=".$value->ID."&appt=N";
      $data['name'] = $value->display_name;
      $data['avatar'] = get_url_avatar($value->ID);
      get_template_part( 'layout/searchs/item', 'account', $data);
    }
  } else if ( $type =='group' ) {
    $args = array(
      'taxonomy'      => 'group',
      'hide_empty'    => false,
      'name__like'    => $key_word,
    );
    $terms = get_terms( $args );
    foreach ($terms as $value) {
      $id_gr = $value->term_id;
      $data['id'] = $id_gr;
      $data['link'] = SITE_URL . "community/?action=view-group&id={$id_gr}&appt=N";
      $data['banner'] = get_banner_group($id_gr);
      $data['name'] = get_term($id_gr)->name;
      get_template_part( 'layout/searchs/item', 'group', $data);
    }
  }
  wp_die();
}
/**
 * Change language
 * 
 */
add_action( 'wp_ajax_nopriv_at_change_language', 'at_change_language' );
add_action( 'wp_ajax_at_change_language', 'at_change_language' );
function at_change_language(){
  $lang = sanitize_text_field($_POST['lang']);
  $cookie_name = "app_language";
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'language' )) die("Token");
  echo setcookie($cookie_name, $lang,time()+604800, "/","", 0);
  wp_die();
}
/**
 * Change nonce
 * 
 */
add_action( 'wp_ajax_nopriv_at_change_nonce', 'at_change_nonce' );
add_action( 'wp_ajax_at_change_nonce', 'at_change_nonce' );
function at_change_nonce(){
  $value = get_option('nonce_code','default_value');
  if($value == 'default_value') {
    echo add_option( 'nonce_code', true);
  }else {
    echo update_option('nonce_code',!get_option('nonce_code'));
  }
  wp_die();
}

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\views\account\setting-notifi.php

<style> 
  .switch {
    display: inline-block;
    height: 30px;
    position: relative;
    width: 60px;
  }
.switch input {
  display: none;
}
.slider {
  background-color: #ccc;
  bottom: 0;
  cursor: pointer;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transition: 0.4s;
}
.slider:before {
  background-color: #fff;
  bottom: 4px;
  content: "";
  height: 22px;
  left: 4px;
  position: absolute;
  transition: 0.4s;
  width: 22px;
}
input:checked+.slider {
  background-color: #F56B6B;
}
input:checked+.slider:before {
  transform: translateX(26px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}
</style>
<div class="page-setting-notifi container">
  <div class="box-update-setting mt-4">
    <div class="box-update-setting__item d-flex align-items-center justify-content-between">
      <div>
        <?php _e('Notification', 'umm'); ?>
      </div>
      <label class="switch" for="checkbox">
        <input type="checkbox" id="checkbox" <?php if(get_option('nonce_code',false)) {echo "checked"; } ?>/>
        <div class="slider round"></div>
      </label>
    </div>
  </div>
</div>
<?php wp_nonce_field(AT_NONCE_KEY.'language','language-nonce'); ?>

Change Password

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\controllers\Account.php

<?php
class BJ_Account_Controller extends Pv_Controller {
  function __construct() {
    if (isset($_GET['action'])):
      switch ($_GET['action']) {
      case "edit-info":
        $this->update_info();
        break;
      case "followers":
        $this->followers();
        break;
      case "following":
        $this->following();
        break;
      case "add-deal":
        $this->adddeal();
      break;
      case "add-event":
        $this->addevent();
      break;
      case "add-post":
        $this->addposts();
      break;
      case "settings":
        $this->settings();
      break;
      case "language":
        $this->language();
      break;
      case "setting-notifi":
        $this->setting_notifi();
      break;
      case "update-password":
        $this->update_password();
      break;
      default:
        $this->index();
      } else :
      $this->index();
    endif;
  }
  private function get_user_id() {
    if (isset($_GET["id"]) && is_user_exist(strip_tags($_GET["id"]))) {
      return $_GET["id"];
    } else {
      return get_current_user_id();
    }
  }
  public function index() {
    $data                         = array();
    $user_id                      = $this->get_user_id();
    $user_obj                     = get_userdata($user_id);
    $data['id']                   = $user_id;
    $data['display_name']         = $user_obj->display_name;
    $data['date_registered']      = date_i18n(__('jS F Y', 'umm'), strtotime($user_obj->user_registered));
    $data['avatar']               = get_url_avatar($user_id);
    $data['province_address_arr'] = atw_load_province_address($user_id);
    $this->load()->View("account", $data, "account");
  }
  public function update_info() {
    $data = array();
    $this->load()->View("update-info", $data, "account");
  }
  public function followers() {
    $current_user_id       = $this->get_user_id();
    $data                  = array();
    $data['list_follower'] = get_list_follower($current_user_id);
    $this->load()->View("followers", $data, "account");
  }
  public function following() {
    $user_id             = $this->get_user_id();
    $data                = array();
    $data['list_follow'] = list_user_follow($user_id);
    $this->load()->View("following", $data, "account");
  }
  public function adddeal() {
    $this->load()->View("add-deal", '', "deal"); 
  }
  public function addevent() {
    $this->load()->View("add-event", '', "event"); 
  }
  public function addposts() {
    $this->load()->View("add-post", '', "post"); 
  }
  public function settings() {
    $data = array();
    $this->load()->View("settings", $data, "account");
  }
  public function language(){
    $data = array();
    $this->load()->View("language", $data, "account");
  }
  public function setting_notifi(){
    $data = array();
    $this->load()->View("setting-notifi", $data, "account");
  }
  public function update_password(){
    $data = array();
    $this->load()->View("update-password", $data, "account");
  }
}
function render_province_option($default = ""){  
  $json = file_get_contents(get_stylesheet_directory()."/json/tinh_tp.json");
  $tinh_thanh = json_decode($json,true);
  foreach ($tinh_thanh as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name"]."</option>";
  }
}
function render_xa_phuong_option($quan_huyen,$default=""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/xa-phuong/".$quan_huyen.".json");
  $xa_phuong = json_decode($json,true);
  foreach ($xa_phuong as $key => $value) {
      if($key == $default){$select = "selected";}else{$select = "";}
      echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
    }
}
function render_quan_huyen_option($tinh_thanh,$default = ""){
  $default = intval($default);
  $json = file_get_contents(get_stylesheet_directory()."/json/quan-huyen/".$tinh_thanh.".json");
  $quan_huyen = json_decode($json,true);  
  foreach ($quan_huyen as $key => $value) {
    if($key == $default){$select = "selected";}else{$select = "";}
    echo "<option ".$select." value='".$key."'>".$value["name_with_type"]."</option>";
  }  
}

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\js\custom.js

jQuery(document).ready(function($) {
  function addLoading() {
    $('#page-load').css({ 'opacity': '1', 'visibility': 'visible' });
  }
  function unLoading() {
    $('#page-load').css({ 'opacity': '0', 'visibility': 'hidden' });
  }
  const boxMessage = $('.notifi__update');
  $("body").on("submit", "form#form-update-info", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-info"));
    fd.append('action', 'app_update_info');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var result = $.parseJSON(output);
        if (result.status === false) {
          setTimeout(() => {
            var currURL = window.location.href;
            var urlReload = replaceUrlParam(currURL, 'appt', 'C');
            window.location.replace(urlReload);
          }, 1500)
        } else {
          boxMessage.text(result.message);
        }
        boxMessage.removeClass('hidden');
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  $("input").blur(function() {
    boxMessage.addClass('hidden');
  });
  $("#event-datepicker").datepicker({
    onSelect: function() {
      let dateObject = $(this).datepicker('getDate');
      $("#date").val($.datepicker.formatDate("yy-mm-dd", dateObject));
    }
  });
  $("body").on("submit", "form#form-update-post", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-post"));
    fd.append('action', 'edit_post_single');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() {
        addLoading()
      },
      success: function(output) {
        unLoading();
        var currURL = window.location.href;
        currURL = currURL.split('?')[0];
        currURL = currURL + "?appt=C";
        window.location.replace(currURL);
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  // For Search
  var typeSearch = $('.filters__item.active').data('type');
  const boxResult = $('.box-results__list');
  $("body").on("click", ".filters__item", function(e) {
    $('.filters__item').removeClass('active');
    $(this).addClass('active');
    typeSearch = $('.filters__item.active').data('type');
    const keyWord = $('#search').val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  })
  $("#search").keyup(function() {
    const keyWord = $(this).val().trim();
    if (keyWord.length == 0) return;
    searchFilter(keyWord, typeSearch);
  });
  function searchFilter(keyWord, typeSearch) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'search_by_filters',
        keyword: keyWord,
        type: typeSearch,
        token: $('#nonce_token').val(),
      },
      beforeSend: function() {
        boxResult.css('opacity', '0.6');
      },
      success: function(output) {
        boxResult.css('opacity', '1');
        boxResult.html(output);
      },
      error: function() { alert('error'); }
    });
  }
  // For App Logout
  $("body").on("click", ".app_logout", function(e) {
    e.preventDefault();
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'app_logout',
        token: $('#nonce_token').val(),
      },
      success: function(output) {
        if (output == "success") {
          window.appBridge.clearCookie();
          var expire = new Date();
          expire.setDate(expire.getDate() + 1000);
          cookies = "APP_LOGIN" + '=' + escape('false') + ';'
          cookies += ';expires=' + expire.toGMTString() + ';';
          document.cookie = cookies;
          location.href = "/login"
        }
      },
    });
  });
  // For set Language
  $('input[type=radio][name=language]').change(function(e) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'at_change_language',
        lang: $(this).val(),
        token: $("#language-token").val(),
      },
      success: function(output) {
        if (output == "1") {
          location.reload(true);
        } else {
          alert('error');
        }
      },
    });
  });
  // For Change Nonce
  $('#checkbox').change(function(e) {
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      dataType: "text",
      data: {
        action: 'at_change_nonce',
        lang: $(this).val(),
        token: $("#language-nonce").val(),
      },
      success: function(output) {
        if (output == 1) {
          alert("Update Success");
        } else {
          alert("Update Error");
        }
      },
    });
  });
  // For Update Pass
  const btnUpdate = $('.btn__update');
  $("body").on("submit", "form#form-update-password", function(e) {
    e.preventDefault();
    var fd = new FormData(document.getElementById("form-update-password"));
    fd.append('action', 'app_update_password');
    $.ajax({
      url: app.ajaxUrl,
      type: "post",
      contentType: false,
      processData: false,
      data: fd,
      beforeSend: function() { 
        addLoading() 
      },
      success: function(output) {
        unLoading();
        var result = $.parseJSON(output);
        boxMessage.text(result.message);
        boxMessage.removeClass('hidden');
      },
      error: function(jqXHR, textStatus, errorThrown) {
        unLoading();
        alert('error');
      }
    });
  });
  $("input.verify-password").blur(function() {
    let newPassword = $('.new-password').val().trim();
    let verifyPassword = $(this).val().trim();
    if (newPassword != verifyPassword) {
      btnUpdate.attr('disabled', 'disabled');
      boxMessage.text('Password incorrect');
      boxMessage.removeClass('hidden');
    } else {
      btnUpdate.removeAttr("disabled");
      boxMessage.addClass('hidden');
    }
  });
});

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\inc\functions\function-global.php

<?php
/**
 *
 * @return HTML - option list tỉnh thành
 */
function reder_province_option($default = "") {
  $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $tinh_thanh = json_decode($json, true);
    foreach ($tinh_thanh as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list quận huyện
 */
function reder_quan_huyen_option($tinh_thanh, $default) {
  $default    = sprintf('%02d', intval($default));
  $tinh_thanh = sprintf('%02d', intval($tinh_thanh));
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    foreach ($quan_huyen as $key => $value) {
      if ($key == $default) {
        $select = "selected";
      } else {
        $select = "";
      }
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * @return HTML - option list xã phường
 */
function reder_xa_phuong_option($quan_huyen, $default) {
  $default    = intval($default);
  $quan_huyen = sprintf('%03d', intval($quan_huyen));
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      if ($key == $default) {$select = "selected";} else { $select = "";}
      echo "<option " . $select . " value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
}
/**
 * AJAX load quận huyện khi select tỉnh thành phố
 */
add_action('wp_ajax_load_quan_huyen', 'load_quan_huyen');
function load_quan_huyen() {
  $tinh_thanh = $_POST['id'];
  $type       = $_POST['type'];
  $json_file  = get_stylesheet_directory() . "/json/quan-huyen/" . $tinh_thanh . ".json";
  if (file_exists($json_file)) {
    $json       = file_get_contents($json_file);
    $quan_huyen = json_decode($json, true);
    echo '<option value="" disabled selected >' . __("Select", "golf") . '</option>';
    foreach ($quan_huyen as $key => $value) {
      if ($type) {
        echo "<option value='" . $value["name_with_type"] . "'>" . $value["name_with_type"] . "</option>";
      } else {
        echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
      }
    }
  }
  die();
}
/**
 * AJAX load danh sách xã phường khi select tỉnh thành phố
 */
add_action('wp_ajax_load_xa_phuong', 'load_xa_phuong');
function load_xa_phuong() {
  $quan_huyen = $_POST['id'];
  $json_file  = get_stylesheet_directory() . "/json/xa-phuong/" . $quan_huyen . ".json";
  if (file_exists($json_file)) {
    $json      = file_get_contents($json_file);
    $xa_phuong = json_decode($json, true);
    foreach ($xa_phuong as $key => $value) {
      echo "<option value='" . $key . "'>" . $value["name_with_type"] . "</option>";
    }
  }
  die();
}
/**
 *
 * Get địa chỉ của user bởi id
 * Nếu chưa update địa chỉ, thì gán mặc định là: '90 Đường Lê Lợi, Phường Bến Thành, Quận 1, Thành phố Hồ Chí Minh'
 */
function get_address_by_id_user($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_user_meta($user_id, "province_address", true);
  if ($province_address) {
    return json_decode($province_address, true);
  }
  return array(
    'province' => 79,
    'district' => 760,
    'ward'     => 26743,
    'street'   => '90 Đường Lê Lợi',
  );
}
/**
 * Get địa chỉ text
 * @return array
 */
function atw_load_province_address($user_id = null) {
  $province = '';
  $district = '';
  $ward     = '';
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $province_address = get_address_by_id_user($user_id);
  if ($province_address && is_array($province_address)) {
    $json_file = get_stylesheet_directory() . "/json/tinh_tp.json";
    if (file_exists($json_file)) {
      $json_tinh_tp = file_get_contents($json_file);
      $tinh_thanh   = json_decode($json_tinh_tp, true);
      foreach ($tinh_thanh as $key => $value) {
        if ($key == $province_address['province']) {
          $province = $tinh_thanh[$key]['name'];
          break;
        }
      }
    }
    if ($province_address['province']):
      $json_file = get_stylesheet_directory() . "/json/quan-huyen/" . $province_address['province'] . ".json";
      if (file_exists($json_file)) {
        $json_quan_huyen = file_get_contents($json_file);
        $quan_huyen      = json_decode($json_quan_huyen, true);
        foreach ($quan_huyen as $key => $value) {
          if ($key == $province_address['district']) {
            $district = $quan_huyen[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
    if ($province_address['district']):
      $json_file = get_stylesheet_directory() . "/json/xa-phuong/" . $province_address['district'] . ".json";
      if (file_exists($json_file)) {
        $json_xa_phuong = file_get_contents($json_file);
        $xa_phuong      = json_decode($json_xa_phuong, true);
        foreach ($xa_phuong as $key => $value) {
          if ($key == $province_address['ward']) {
            $ward = $xa_phuong[$key]['name_with_type'];
            break;
          }
        }
      }
    endif;
  }
  return array(
    'province' => $province,
    'district' => $district,
    'ward'     => $ward,
    'street'   => $province_address['street'],
  );
}
/**
 *
 * Crop image
 */
function resize_image($method, $image_loc, $new_loc, $width, $height) {
  $exif = exif_read_data($image_loc);
  if (isset($exif['Orientation']) && $exif['Orientation'] === 6) {
    $rotate = -90;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 3) {
    $rotate = 180;
  } else if (isset($exif['Orientation']) && $exif['Orientation'] === 8) {
    $rotate = 90;
  }
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array();}
  if (!in_array($method, array('force', 'max', 'crop'))) {$GLOBALS['errors'][] = 'Invalid method selected.';}
  if (!$image_loc) {$GLOBALS['errors'][] = 'No source image location specified.';} else {
    if ((substr(strtolower($image_loc), 0, 7) == 'http://') || (substr(strtolower($image_loc), 0, 7) == 'https://')) { /*don't check to see if file exists since it's not local*/} elseif (!file_exists($image_loc)) {$GLOBALS['errors'][] = 'Image source file does not exist.';}
    $extension = strtolower(substr($image_loc, strrpos($image_loc, '.')));
    if (!in_array($extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid source file extension!';}
  }
  if (!$new_loc) {$GLOBALS['errors'][] = 'No destination image location specified.';} else {
    $new_extension = strtolower(substr($new_loc, strrpos($new_loc, '.')));
    if (!in_array($new_extension, array('.jpg', '.jpeg', '.png', '.gif', '.bmp'))) {$GLOBALS['errors'][] = 'Invalid destination file extension!';}
  }
  $width = abs(intval($width));
  if (!$width) {$GLOBALS['errors'][] = 'No width specified!';}
  $height = abs(intval($height));
  if (!$height) {$GLOBALS['errors'][] = 'No height specified!';}
  if (count($GLOBALS['errors']) > 0) {echo_errors();return false;}
  if (in_array($extension, array('.jpg', '.jpeg'))) {$image = @imagecreatefromjpeg($image_loc);} elseif ($extension == '.png') {$image = @imagecreatefrompng($image_loc);} elseif ($extension == '.gif') {$image = @imagecreatefromgif($image_loc);} elseif ($extension == '.bmp') {$image = @imagecreatefromwbmp($image_loc);}
  if (!$image) {$GLOBALS['errors'][] = 'Image could not be generated!';} else {
    $current_width  = imagesx($image);
    $current_height = imagesy($image);
    if ((!$current_width) || (!$current_height)) {$GLOBALS['errors'][] = 'Generated image has invalid dimensions!';}
  }
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  if ($method == 'force') {$new_image = resize_image_force($image, $width, $height);} elseif ($method == 'max') {$new_image = resize_image_max($image, $width, $height);} elseif ($method == 'crop') {$new_image = resize_image_crop($image, $width, $height);}
  if ((!$new_image) && (count($GLOBALS['errors'] == 0))) {$GLOBALS['errors'][] = 'New image could not be generated!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);
    echo_errors();return false;}
  $save_error = false;
  if (in_array($extension, array('.jpg', '.jpeg'))) {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagejpeg($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.png') {
    if (isset($rotate)) {$new_image = imagerotate($new_image, $rotate, 0);}
    imagepng($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.gif') {imagegif($new_image, $new_loc) or ($save_error = true);} elseif ($extension == '.bmp') {imagewbmp($new_image, $new_loc) or ($save_error = true);}
  if ($save_error) {$GLOBALS['errors'][] = 'New image could not be saved!';}
  if (count($GLOBALS['errors']) > 0) {
    @imagedestroy($image);@imagedestroy($new_image);
    echo_errors();return false;}
  imagedestroy($image);
  imagedestroy($new_image);
  return true;
}
function echo_errors() {
  if (!is_array(@$GLOBALS['errors'])) {$GLOBALS['errors'] = array('Unknown error!');}
  foreach ($GLOBALS['errors'] as $error) {echo '<p style="color:red;font-weight:bold;">Error: ' . $error . '</p>';}
}
function resize_image_force($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  $image2 = imagecreatetruecolor($width, $height);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $width, $height, $w, $h);
  return $image2;
}
function resize_image_max($image, $max_width, $max_height) {
  $w = imagesx($image); //current width
  $h = imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w <= $max_width) && ($h <= $max_height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $max_width / $w;
  $new_w = $max_width;
  $new_h = $h * $ratio;
  //if that didn't work
  if ($new_h > $max_height) {
    $ratio = $max_height / $h;
    $new_h = $max_height;
    $new_w = $w * $ratio;
  }
  $new_image = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  return $new_image;
}
function resize_image_crop($image, $width, $height) {
  $w = @imagesx($image); //current width
  $h = @imagesy($image); //current height
  if ((!$w) || (!$h)) {$GLOBALS['errors'][] = 'Image couldn\'t be resized because it wasn\'t a valid image.';return false;}
  if (($w == $width) && ($h == $height)) {return $image;} //no resizing needed
  //try max width first...
  $ratio = $width / $w;
  $new_w = $width;
  $new_h = $h * $ratio;
  //if that created an image smaller than what we wanted, try the other way
  if ($new_h < $height) {
    $ratio = $height / $h;
    $new_h = $height;
    $new_w = $w * $ratio;
  }
  $image2 = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($image2, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h);
  //check to see if cropping needs to happen
  if (($new_h != $height) || ($new_w != $width)) {
    $image3 = imagecreatetruecolor($width, $height);
    if ($new_h > $height) {
      //crop vertically
      $extra = $new_h - $height;
      $x     = 0; //source x
      $y     = round($extra / 2); //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    } else {
      $extra = $new_w - $width;
      $x     = round($extra / 2); //source x
      $y     = 0; //source y
      imagecopyresampled($image3, $image2, 0, 0, $x, $y, $width, $height, $width, $height);
    }
    imagedestroy($image2);
    return $image3;
  } else {
    return $image2;
  }
}
function upload_image($file) {
  $targetDir      = wp_upload_dir()["basedir"] . '/image-files/';
  $allowTypes     = array('jpg', 'png', 'jpeg');
  $fileName       = round(microtime(true)) . "_" . basename($file['name']);
  $targetFilePath = $targetDir . $fileName;
  // Check whether file type is valid
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
  if (in_array($fileType, $allowTypes)) {
    if ($file["size"] > 10000000) {
      return array("status" => "error", "content" => "Maximum 10Mb");
    }
    if (move_uploaded_file($file['tmp_name'], $targetFilePath)) {
      resize_image('crop', $targetDir . $fileName, $targetDir . '200x200/' . $fileName, 200, 200);
      $file_id = umm_model_insert_img($fileName);
      return array("status" => "success", "content" => $file_id);
    }
  } else {
    return array("status" => "error", "content" => "Allow jpg, png, jpeg");
  }
}
function umm_model_insert_img($file_name) {
  global $wpdb;
  $table  = $wpdb->prefix . 'images';
  $data   = array('image_name' => $file_name, 'user_id' => get_current_user_id());
  $format = array('%s', '%d');
  $wpdb->insert($table, $data, $format);
  return $wpdb->insert_id;
}
function get_image_url_by_id($id, $size = "full") {
  $url = wp_get_upload_dir()["baseurl"] . "/image-files/";
  if ($size != "full") {
    $url = wp_get_upload_dir()["baseurl"] . "/image-files/200x200/";
  }
  global $wpdb;
  $table  = $wpdb->prefix . "images";
  $result = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $id), ARRAY_A, 1);
  return $url . $result[0]["image_name"];
}
/**
 *
 * Delete uploaded images file, database
 */
function delete_img_by_id($img_id) {
  global $wpdb;
  $table     = $wpdb->prefix . "images";
  $result    = $wpdb->get_results($wpdb->prepare(" SELECT image_name  FROM  {$table} WHERE id = %d ", $img_id), ARRAY_A, 1);
  $file_name = $result[0]["image_name"];
  $folder    = wp_upload_dir()["basedir"] . '/image-files/';
  unlink($folder . $file_name);
  unlink($folder . "200x200/" . $file_name);
  $wpdb->delete($table, array('id' => $img_id), array('%d'));
}
/**
 *
 * Get image url avatar  by user id
 */
function get_url_avatar($user_id = '') {
  if ($user_id === '') {
    $user_id = get_current_user_id();
  }
  $id_avatar = get_user_meta($user_id, 'id_img_avatar', true);
  if ($id_avatar) {
    return get_image_url_by_id($id_avatar, 'thumbnail');
  }
  return AVATAR_DF;
}
/**
 *
 * Check user exists
 * @return boolean
 */
function is_user_exist($user_id) {
  $user       = get_userdata($user_id);
  $user_roles = !empty($user) ? $user->roles[0] : "";
  if ($user === false or $user_roles != USER) {
    return false;
  } else {
    return true;
  }
}
/**
 *
 * Check View other account
 * @return boolean
 */
function is_view_other_account() {
  if (is_page('account') && isset($_GET['id']) && intval($_GET['id']) !== get_current_user_id()) {
    return true;
  }
  return false;
}
/**
 *
 * Get list user follow
 * @return array
 */
function list_user_follow($user_id = null) {
  if (!$user_id) {
    $user_id = get_current_user_id();
  }
  $list_user_follow = get_user_meta($user_id, 'list_user_follow', true);
  if (!$list_user_follow) {
    return array();
  }
  return json_decode($list_user_follow, true);
}
/**
 *
 * Nhận danh sách người theo dõi tôi
 * @return array
 */
function get_list_follower($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  $args              = array('role' => USER);
  $users             = get_users($args);
  $list_follower_arr = [];
  foreach ($users as $value) {
    $user_id         = $value->ID;
    $list_follow_arr = list_user_follow($user_id);
    if ($list_follow_arr):
      if (in_array($current_user_id, $list_follow_arr)) {
        $list_follower_arr[] = $user_id;
      }
    endif;
  }
  return $list_follower_arr;
}
/**
 *
 * Nhận tổng số người tôi đang theo dõi
 * @return int
 */
function get_total_following($current_user_id = null) {
  if (!$current_user_id) {
    $current_user_id = get_current_user_id();
  }
  return count(list_user_follow($current_user_id));
}
/**
 * tăng lên 1 so tổng thông báo mới hiện tại của user ID
 */
function update_total_notify_user($user_id){
  $total = (int)get_user_meta( $user_id, 'total_notify', true ) + 1;
  update_user_meta( $user_id, 'total_notify', $total);
}
// ==
function get_market_image_url($img_id){
  $url = wp_get_upload_dir()["baseurl"]."/market-images/";
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $result = $wpdb->get_results ( $wpdb->prepare(" SELECT image_name FROM  {$table} WHERE id = %d ",$img_id) ,ARRAY_A  );
  if(!empty($result)){
    return $url."__".$result[0]["image_name"];
  }else{
    return THEME_URL."assets/images/default.jpg";
  }
}
function market_upload_image($file){
  $targetDir = wp_upload_dir()["basedir"].'/market-images/'; 
  $allowTypes = array( 'jpg', 'png', 'jpeg'); 
  $fileName = round(microtime(true))."_".basename($file['name']);
  $targetFilePath = $targetDir.$fileName; 
    // Check whether file type is valid 
  $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
  if(in_array($fileType, $allowTypes)){ 
    if($file["size"] > 5000000) return array("status" => "error","content" => "Maximum 5Mb");
    if(move_uploaded_file($file['tmp_name'], $targetFilePath)){ 
      $result = resize_image('max',$targetDir.$fileName,$targetDir.'__'.$fileName,600,4000);
      if($result == true){
        $file_id = add_market_image_to_db($fileName);
        unlink($targetDir.$fileName);
        return array("status" => "success","content" => $file_id);
      }
    }else{
      return array("status" => "error","content" => "Unknow");
    } 
  }else{
    return array("status" => "error","content" => "Allow jpg, png, jpeg");
  }
}
function add_market_image_to_db($file_name){
  global $wpdb;
  $table = $wpdb->prefix."bj_market_image";
  $wpdb->insert($table,
    array("image_name" => $file_name),
    array("%s")
  );
  return $wpdb->insert_id;
}
/**
 * 
 * Get role and check member group
 * @return int
 */
function is_member_of_group($group_id = 0,$user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $current_list_member_arr = json_decode(get_term_meta($group_id,"list_member",true),true);
  if(!empty($current_list_member_arr)){
    foreach ($current_list_member_arr as $value) {
      if(isset($value["user_id"]) && $value["user_id"] == $user_id){
        if (isset($value["role"])) return $value["role"];
      }
    }
  }else{
    return false;
  }
}
/**
 * 
 * Get all id group have join
 * @return array
 */
function all_groups_have_joined($user_id = 0){
  if($user_id == 0) $user_id = get_current_user_id();
  $list_groups = array();
  $terms = get_terms( ['hide_empty' => false, 'taxonomy'  => 'group', 'meta_key'  => 'list_member'] );
  if ($terms) {
  foreach ($terms as $value) {
      $group_id = $value->term_id;
      $role = is_member_of_group($group_id, $user_id);
      if( $role ) $list_groups[] = $group_id;
    }
  }
  return $list_groups;
}
/**
 * 
 * Get banner group
 * @return string - banner
 */
function get_banner_group($id_gr, $size = 'thumbnail') {
  $id_banner_gr = get_term_meta($id_gr, 'image_cover_group');
  if( $id_banner_gr ) return get_image_url_by_id($id_banner_gr, $size);
  return BANNER_DF;
}
/**
 * Search Filters
 */
add_action( 'wp_ajax_search_by_filters', 'search_by_filters' );
function search_by_filters(){
  $current_user_id = get_current_user_id();
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'ajax-nonce'.$current_user_id)) wp_die();
  $key_word = sanitize_text_field($_POST['keyword']);
  $type = $_POST['type'];
  if ($type == 'people'){
    $args= array(
      'search' => '*'.$key_word.'*', 
      'search_columns' => array( 'display_name','user_email'),
      'exclude' => array($current_user_id),
      'role'  => USER,
    );
    $users = get_users($args); 
    foreach ($users as $value) {
      $data['link'] = SITE_URL."account/?id=".$value->ID."&appt=N";
      $data['name'] = $value->display_name;
      $data['avatar'] = get_url_avatar($value->ID);
      get_template_part( 'layout/searchs/item', 'account', $data);
    }
  } else if ( $type =='group' ) {
    $args = array(
      'taxonomy'      => 'group',
      'hide_empty'    => false,
      'name__like'    => $key_word,
    );
    $terms = get_terms( $args );
    foreach ($terms as $value) {
      $id_gr = $value->term_id;
      $data['id'] = $id_gr;
      $data['link'] = SITE_URL . "community/?action=view-group&id={$id_gr}&appt=N";
      $data['banner'] = get_banner_group($id_gr);
      $data['name'] = get_term($id_gr)->name;
      get_template_part( 'layout/searchs/item', 'group', $data);
    }
  }
  wp_die();
}
/**
 * Change language
 * 
 */
add_action( 'wp_ajax_nopriv_at_change_language', 'at_change_language' );
add_action( 'wp_ajax_at_change_language', 'at_change_language' );
function at_change_language(){
  $lang = sanitize_text_field($_POST['lang']);
  $cookie_name = "app_language";
  if( !isset( $_POST['token']) or !wp_verify_nonce($_POST['token'],AT_NONCE_KEY.'language' )) die("Token");
  echo setcookie($cookie_name, $lang,time()+604800, "/","", 0);
  wp_die();
}
/**
 * Change nonce
 * 
 */
add_action( 'wp_ajax_nopriv_at_change_nonce', 'at_change_nonce' );
add_action( 'wp_ajax_at_change_nonce', 'at_change_nonce' );
function at_change_nonce(){
  $value = get_option('nonce_code','default_value');
  if($value == 'default_value') {
    echo add_option( 'nonce_code', true);
  }else {
    echo update_option('nonce_code',!get_option('nonce_code'));
  }
  wp_die();
}
/**
 * App Update Password
 */
add_action( 'wp_ajax_app_update_password', 'app_update_password' );
function app_update_password(){
  check_ajax_referer( AT_NONCE_KEY.'update-pass', 'update-pass-token');
  $status = false; $message = '';
  $user = wp_get_current_user();
  $current_user_id = $user->ID;
  $old_password = strip_tags($_POST['old-password']);
  $new_password = strip_tags($_POST['new-password']);
  if (wp_check_password( $old_password, $user->user_pass, $user->data->ID) ) {
    $user->destroy_all();
    wp_set_password($new_password,$current_user_id);
    wp_signon( array( 'user_login' => $user->user_login, 'user_password' =>  $new_password ),true );
    $message = __("Update successful","umm");
  } else {
    $message = __("Old Password doesn't match","umm");
    $status = true;
  }
  echo json_encode(array(
    'status' => $status,
    'message' => $message)
  );
  wp_die();
}

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\views\account\update-password.php

<div class="page-update-password container">
  <div class="box-update-info mt-4">
    <form id="form-update-password" class="text-center form-update" action="" method="POST">
      <div class="form-group">
        <div class="position-relative">
          <input type="password" name="old-password" class="form-control old-password" id="old-password" pattern=".{8,}" title="<?php _e('8 characters minimum', 'cafe');  ?>" placeholder="<?php _e('Old password', 'cafe');  ?>" required autocomplete="off">
          <div class="btn show-hiden"> Show </div>
        </div>
      </div>
      <div class="form-group">
        <div class="position-relative">
          <input type="password" name="new-password" class="form-control new-password" id="new-password" pattern=".{8,}" title="<?php _e('8 characters minimum', 'cafe');  ?>" placeholder="<?php _e('New password', 'cafe');  ?>" required autocomplete="off">
          <div class="btn show-hiden"> Show </div>
        </div>
      </div>
      <div class="form-group">
        <div class="position-relative">
          <input type="password" name="verify-password" class="form-control verify-password" id="verify-password" pattern=".{8,}" title="<?php _e('8 characters minimum', 'cafe');  ?>" placeholder="<?php _e('Verify password', 'cafe');  ?>" required autocomplete="off">
          <div class="btn show-hiden"> Show </div>
        </div>
      </div>
      <div class="notifi__update my-3 alert alert-warning hidden" role="alert"></div>
      <div>
        <?php wp_nonce_field(AT_NONCE_KEY . 'update-pass', 'update-pass-token'); ?>
      </div>
      <button type="submit" class="btn btn__update w-100 at-rounded-14 bg-primary at-rounded-10 font-weight-500 text-white mt-3">
        <?php _e("Update", "cafe") ?></button>
    </form>
  </div>
</div>

Last updated