/** * Save post metadata when a post is saved. * * @param int $post_id The post ID. * @param post $post The post object. * @param bool $update Whether this is an existing post being updated or not. */ public static function save($post_id, $post, $update) { if (!isset($_REQUEST[Akses_Visit::VISIT_NONCE])) { return; } if (!wp_verify_nonce($_REQUEST[Akses_Visit::ASSIGNMENT_NONCE], Akses_Visit::get_nonce_context($post_id))) { error_log("Nonce error! Akses could not save " . Akses_Visit::POST_TYPE_ID . " id '{$post_id}' because nonce variable '" . Akses_Visit::ASSIGNMENT_NONCE . " can not be verified."); return; } if (!wp_verify_nonce($_REQUEST[Akses_Visit::VISIT_NONCE], Akses_Visit::get_nonce_context($post_id))) { error_log("Nonce error! Akses could not save " . Akses_Visit::POST_TYPE_ID . " id '{$post_id}' because nonce variable '" . Akses_Visit::VISIT_NONCE . " can not be verified."); return; } // ----------------------------- // Set data for the visit $visit = Akses_Visit::get_visit($post_id); $visit["user_id"] = $_REQUEST[ARG_AKSES_MEMBER_ID]; $visit["in_at"] = Akses_Visit::parse_datetime($_REQUEST[ARG_AKSES_IN_AT]); $visit["out_at"] = Akses_Visit::parse_datetime($_REQUEST[ARG_AKSES_OUT_AT]); Akses_Visit::save_visit($visit); // ----------------------------- // Update the post title and URL $updated_post_values = array('ID' => $post_id, 'post_name' => "{$post_id}", 'post_title' => trim($visit["in_at"] . " - " . $visit["out_at"])); // Check if post values has been changed. Update the title etc. // This conditional check is needed since wp_update_post will trigger // a call to this action hook again. foreach ($updated_post_values as $key => $value) { if ($post->{$key} != $value) { wp_update_post($updated_post_values); break; } } }