[FRAMEWORK] Xây dựng page Account Phần 7 (ok)

Like Event, Unlike Event

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\ajax\event.php

<?php
add_action('wp_ajax_event_favorite_process', 'event_favorite_process');
function event_favorite_process() {
  if (!isset($_POST['token']) or !is_numeric($_POST["id"]) or !wp_verify_nonce($_POST['token'], BJ_NONCE_KEY . 'event' . $_POST["id"])) {
    die(json_encode(["error"]));
  }
  $type            = isset($_POST["type"]) && in_array($_POST["type"], ["going", "maybe"]) ? $_POST['type'] : "maybe";
  $current_user_id = get_current_user_id();
  global $bj_controller;
  $model  = $bj_controller->Model("event");
  $result = $model->event_favorite_process_user($_POST["id"], $current_user_id, $type);
  if ($result != false) {
    if (isset($_POST['page']) && $_POST['page'] == "single") {
      die(json_encode(["success", count($model->get_event_list_user($_POST["id"])), count($model->get_event_list_user($_POST["id"], "maybe"))]));
    } else {
      die(json_encode(["success"]));
    }
  }
  die(json_encode(["error"]));
}
?>

C:\xampp\htdocs\wordpress8\wp-content\themes\addframwork\framework\models\event.php

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

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

Last updated

Was this helpful?