function trav_review_save_action()
 {
     if (!isset($_POST['review_save']) || !wp_verify_nonce($_POST['review_save'], 'trav_review_manage')) {
         print 'Sorry, your nonce did not verify.';
         exit;
     } else {
         global $wpdb;
         $default_review_data = array('post_id' => '', 'review_rating' => 0, 'review_rating_detail' => '', 'review_title' => '', 'review_text' => '', 'reviewer_ip' => '127.0.0.1', 'reviewer_email' => '', 'reviewer_name' => '', 'trip_type' => 0, 'status' => 0, 'date' => date('Y-m-d H:i:s'), 'user_id' => '');
         $table_fields = array('reviewer_name', 'reviewer_email', 'reviewer_ip', 'review_title', 'review_text', 'post_id', 'trip_type', 'status', 'date', 'user_id');
         //review_rating, review_rating_detail, date
         $data = array();
         foreach ($table_fields as $table_field) {
             if (!empty($_POST[$table_field])) {
                 $data[$table_field] = sanitize_text_field($_POST[$table_field]);
             }
         }
         $data['review_rating_detail'] = serialize($_POST['review_rating_detail']);
         $data['review_rating'] = round(array_sum($_POST['review_rating_detail']) / count($_POST['review_rating_detail']), 1);
         $data = array_replace($default_review_data, $data);
         $data['post_id'] = trav_post_org_id($data['post_id']);
         if (empty($_POST['id'])) {
             //insert
             $wpdb->insert(TRAV_REVIEWS_TABLE, $data);
             $id = $wpdb->insert_id;
         } else {
             //update
             $wpdb->update(TRAV_REVIEWS_TABLE, $data, array('id' => sanitize_text_field($_POST['id'])));
             $id = sanitize_text_field($_POST['id']);
         }
         if ($data['status'] == 1) {
             trav_acc_review_calculate_rating($data['post_id']);
         }
         wp_redirect(admin_url('edit.php?post_type=accommodation&page=reviews&action=edit&review_id=' . $id . '&updated=true'));
         exit;
     }
 }
Beispiel #2
0
 function trav_update_user_recent_activity($post_id)
 {
     if (is_user_logged_in()) {
         $post_id = trav_post_org_id($post_id);
         $user_id = get_current_user_id();
         $recent_activity_array = array();
         $recent_activity = get_user_meta($user_id, 'recent_activity', true);
         if (!empty($recent_activity)) {
             $recent_activity_array = unserialize($recent_activity);
             // add current acc id to recent activity
             if (($key = array_search($post_id, $recent_activity_array)) !== false) {
                 // if already exitst unset it first
                 unset($recent_activity_array[$key]);
             }
             array_unshift($recent_activity_array, $post_id);
             // make recent activity size smaller than 10
             $user_activity_maximum_len = 10;
             if (count($recent_activity_array) > $user_activity_maximum_len) {
                 $temp = array_chunk($recent_activity_array, $user_activity_maximum_len);
                 $recent_activity_array = $temp[0];
             }
         } else {
             $recent_activity_array = array($post_id);
         }
         update_user_meta($user_id, 'recent_activity', serialize($recent_activity_array));
     }
 }