FEAT Developping a custom save post button on top of the page
This commit is contained in:
parent
54f4505480
commit
1773c57871
|
|
@ -25,6 +25,38 @@ function metiers_patrimoine_artisans_post_updater($post_id)
|
|||
}
|
||||
add_action('acf/save_post', 'metiers_patrimoine_artisans_post_updater', 20);
|
||||
|
||||
/* -----------------------------------------------
|
||||
AUTOMATIZE POST STATUS DEPENDING ON MDP STATUS
|
||||
--------------------------------------------------*/
|
||||
function update_post_status_based_on_mdp_status($post_id)
|
||||
{
|
||||
if (get_post_type($post_id) !== 'artisans') return;
|
||||
|
||||
$mdp_status = get_field('mdp_status', $post_id);
|
||||
$post_update = array(
|
||||
'ID' => $post_id
|
||||
);
|
||||
// Définir le statut en fonction de la valeur du statut de travail mdp_status
|
||||
if ($mdp_status && isset($mdp_status['value'])) {
|
||||
switch ($mdp_status['value']) {
|
||||
case 'ok':
|
||||
case 'to_actualize':
|
||||
$post_update['post_status'] = 'publish';
|
||||
break;
|
||||
case 'to_contact':
|
||||
case 'deleted':
|
||||
case 'rejected':
|
||||
case 'none':
|
||||
$post_update['post_status'] = 'offline';
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
wp_update_post($post_update);
|
||||
}
|
||||
}
|
||||
add_action('acf/save_post', 'update_post_status_based_on_mdp_status', 20);
|
||||
|
||||
/* ---------------------------------------
|
||||
CUSTOM CONTENT AFTER POST TYPE TITLE
|
||||
|
|
@ -55,8 +87,9 @@ add_action('edit_form_after_title', function () {
|
|||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<button id="set-offline-status" class="button button-secondary">Mettre Hors Ligne</button>
|
||||
<button id="set-online-status" class="button button-secondary">Mettre En Ligne</button>
|
||||
<!-- <button id="set-offline-status" class="button button-secondary">Mettre Hors Ligne</button>
|
||||
<button id="set-online-status" class="button button-secondary">Mettre En Ligne</button> -->
|
||||
<button id="save-post-custom" class="button button-primary">Sauvegarder</button>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
|
|
@ -67,8 +100,19 @@ add_action('edit_form_after_title', function () {
|
|||
// Mettre à jour le champ caché du statut du post
|
||||
$('#post_status').val('offline');
|
||||
$('#post-status-display').text('Hors ligne');
|
||||
$('#publish').trigger('click');
|
||||
});
|
||||
|
||||
// Sauvegarder immédiatement sans recharger
|
||||
$('#set-online-status').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$('#post_status').val('publish');
|
||||
$('#post-status-display').text('En ligne');
|
||||
$('#publish').trigger('click');
|
||||
});
|
||||
|
||||
$('#save-post-status').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
// Déclencher la sauvegarde du post
|
||||
$('#publish').trigger('click');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user