45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
|
|
add_action('acf/save_post', 'carhop_save_auteurs_post');
|
|
|
|
function carhop_save_auteurs_post($post_id)
|
|
{
|
|
$post_type = get_post_type($post_id);
|
|
|
|
if ($post_type !== 'auteurs') return;
|
|
|
|
$is_carhop_member = $_POST['acf']['field_6997373d4aacd'];
|
|
$carhop_member_id = $_POST['acf']['field_6997373d4aad1'] ?? null;
|
|
|
|
if ($carhop_member_id === 0) return;
|
|
|
|
$first_name = null;
|
|
$last_name = null;
|
|
|
|
if (!$is_carhop_member) {
|
|
$first_name = get_field('first_name', $post_id);
|
|
$last_name = get_field('last_name', $post_id);
|
|
}
|
|
|
|
if (isset($is_carhop_member) && isset($carhop_member_id)) {
|
|
switch_to_blog(1);
|
|
$first_name = get_field('first_name', $carhop_member_id);
|
|
$last_name = get_field('last_name', $carhop_member_id);
|
|
restore_current_blog();
|
|
|
|
update_field('first_name', $first_name, $post_id);
|
|
update_field('last_name', $last_name, $post_id);
|
|
}
|
|
$full_name = $first_name . ' ' . $last_name;
|
|
|
|
if (isset($first_name) && isset($last_name) && isset($full_name) && $full_name != '') {
|
|
$post_slug = sanitize_title($full_name);
|
|
wp_update_post(array(
|
|
'ID' => $post_id,
|
|
'post_title' => $full_name,
|
|
'post_name' => $post_slug
|
|
));
|
|
}
|
|
}
|