WP save_post_{$post->post_type} with ACF custom post type leads to infinite loop

I’m using ACF Pro to easily register a custom post type for an internal use purpose (no frontend). Every feature is disabled (content, title, slug, …) as I need to set a UUID as the post_title and post_name, and every other bit of data is handled by ACF.

I used the save_post_{$post->post_type} hook, with a priority of 25, in order to hook into the post save and format the title to a UUIDv4 string, and came with the code below :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
// ...
public function wprc_set_post_title_to_uuid4($post_id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (wp_is_post_revision($post_id)) return;
$post_type = get_post_type($post_id);
if ($post_type != 'wprc_machinery_fleet') return;
remove_action('save_post', 'wpse51363_save_post', 10);
wp_update_post(array('ID' => $post_id, 'post_title' => uuidv4()));
add_action('save_post', 'wpse51363_save_post', 10);
}
add_action('save_post', array($this, 'wprc_set_post_title_to_uuid4'), 10);
</code>
<code><?php // ... public function wprc_set_post_title_to_uuid4($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (wp_is_post_revision($post_id)) return; $post_type = get_post_type($post_id); if ($post_type != 'wprc_machinery_fleet') return; remove_action('save_post', 'wpse51363_save_post', 10); wp_update_post(array('ID' => $post_id, 'post_title' => uuidv4())); add_action('save_post', 'wpse51363_save_post', 10); } add_action('save_post', array($this, 'wprc_set_post_title_to_uuid4'), 10); </code>
<?php 
// ...
public function wprc_set_post_title_to_uuid4($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;

    if (wp_is_post_revision($post_id)) return;

    $post_type = get_post_type($post_id);
    if ($post_type != 'wprc_machinery_fleet') return;

    remove_action('save_post', 'wpse51363_save_post', 10);
    wp_update_post(array('ID' => $post_id, 'post_title' => uuidv4()));
    add_action('save_post', 'wpse51363_save_post', 10);
}
add_action('save_post', array($this, 'wprc_set_post_title_to_uuid4'), 10);

I’m now turning mad not being able to figure out why I trigger an infinite loop upon post creation (add new) and post update (edit).

As soon as I hit the Add New button, a post is effectively created in the DB with the auto-draft status, but instantly loops: post_title is constantly updated (checked with PHPMyAdmin). Same effect runs on an existing post update.

I checked so many times, did use the remove_action() and add_action() hooks, but this seems ignored …

What am I doing wrong here ?
Is there a way to achieve this by other means ?
I imagined creating a text field with ACF and dynamically inserting a UUID in it and using this to edit my post title, but I would face the same issue?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật