refactoring and cleaning
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
24e3725354
commit
dab69b5ab9
|
|
@ -43,13 +43,13 @@ add_action('admin_init', 'metiers_remove_meta_boxes');
|
|||
|
||||
|
||||
/* ---------------------------
|
||||
CUSTOM POST STATUS
|
||||
OFFLINE POST STATUS
|
||||
---------------------------*/
|
||||
|
||||
function custom_post_status()
|
||||
{
|
||||
register_post_status('offline', array(
|
||||
'label' => __('offline', 'metiers-patrimoine-theme'),
|
||||
'label' => __('Hors ligne', 'metiers-patrimoine-theme'),
|
||||
'public' => true,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => true,
|
||||
|
|
@ -79,7 +79,55 @@ jQuery(document).ready(function() {
|
|||
});
|
||||
</script>";
|
||||
}
|
||||
add_action('post_submitbox_misc_actions', 'add_to_post_status_dropdown');
|
||||
// add_action('post_submitbox_misc_actions', 'add_to_post_status_dropdown');
|
||||
|
||||
|
||||
|
||||
add_action('admin_footer-post.php', function () {
|
||||
|
||||
?><script>
|
||||
jQuery(function($) {
|
||||
$('#post_status').append('<option value="offline">Hors ligne</option>')
|
||||
|
||||
$('#post_status option[value="publish"]').text('En ligne');
|
||||
$('#post_status option[value="pending"], #post_status option[value="draft"], #post_status option[value="private"]').remove();
|
||||
|
||||
|
||||
|
||||
<?php if ('offline' === get_post_status()) : ?>
|
||||
$('#post-status-display').text('Hors ligne')
|
||||
$('#post_status').val('offline')
|
||||
|
||||
<?php endif; ?>
|
||||
})
|
||||
</script>
|
||||
<?php
|
||||
|
||||
});
|
||||
|
||||
add_action('admin_footer-edit.php', function () {
|
||||
?>
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('#bulk-edit select[name="_status"]').append('<option value="offline">Hors ligne</option>');
|
||||
$('#bulk-edit select[name="_status"] option[value="publish"]').text('En ligne');
|
||||
$('#bulk-edit select[name="_status"] option[value="offline"]').text('Hors ligne');
|
||||
$('#bulk-edit select[name="_status"] option[value="pending"], #bulk-edit select[name="_status"] option[value="draft"], #bulk-edit select[name="_status"] option[value="private"]').remove();
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Ajouter un filtre pour afficher les posts avec le statut 'offline'
|
||||
|
|
@ -113,6 +161,71 @@ add_filter('views_edit-artisans', function ($views) {
|
|||
|
||||
|
||||
|
||||
// Ajouter le statut personnalisé aux actions de groupe
|
||||
function add_custom_bulk_actions($actions)
|
||||
{
|
||||
$actions['mark_offline'] = __('Mettre hors ligne', 'metiers-patrimoine-theme');
|
||||
$actions['mark_online'] = __('Mettre en ligne', 'metiers-patrimoine-theme');
|
||||
|
||||
return $actions;
|
||||
}
|
||||
add_filter('bulk_actions-edit-artisans', 'add_custom_bulk_actions');
|
||||
|
||||
// Gérer l'action de groupe pour appliquer le statut 'offline'
|
||||
function handle_custom_bulk_actions($redirect_to, $doaction, $post_ids)
|
||||
{
|
||||
if ($doaction === 'mark_offline') {
|
||||
foreach ($post_ids as $post_id) {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'offline'
|
||||
));
|
||||
}
|
||||
$redirect_to = add_query_arg('bulk_online_updated', count($post_ids), $redirect_to);
|
||||
}
|
||||
if ($doaction === 'mark_online') {
|
||||
foreach ($post_ids as $post_id) {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'published'
|
||||
));
|
||||
}
|
||||
$redirect_to = add_query_arg('bulk_offline_updated', count($post_ids), $redirect_to);
|
||||
}
|
||||
return $redirect_to;
|
||||
}
|
||||
add_filter('handle_bulk_actions-edit-artisans', 'handle_custom_bulk_actions', 10, 3);
|
||||
|
||||
// Ajouter un message d'administration pour confirmer l'action de groupe
|
||||
function custom_bulk_admin_notices()
|
||||
{
|
||||
if (!empty($_REQUEST['bulk_online_updated'])) {
|
||||
$message = sprintf(__('%d artisan(s) mis en ligne', 'metiers-patrimoine-theme'), intval($_REQUEST['bulk_online_updated']));
|
||||
echo "<div class=\"updated\"><p>{$message}</p></div>";
|
||||
}
|
||||
if (!empty($_REQUEST['bulk_offline_updated'])) {
|
||||
$message = sprintf(__('%d artisans mis hors ligne', 'metiers-patrimoine-theme'), intval($_REQUEST['bulk_offline_updated']));
|
||||
echo "<div class=\"updated\"><p>{$message}</p></div>";
|
||||
}
|
||||
}
|
||||
add_action('admin_notices', 'custom_bulk_admin_notices');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------
|
||||
POST STATUS AFTER TITLE ON EDIT PAGE WITH ALL POSTS
|
||||
-----------------------------------------------------*/
|
||||
|
||||
|
||||
// Ajouter un statut personnalisé dans la colonne des statuts, uniquement dans la vue "Tous"
|
||||
function add_custom_post_status($post_states, $post)
|
||||
|
|
@ -126,12 +239,12 @@ function add_custom_post_status($post_states, $post)
|
|||
|
||||
// Ajouter le statut "Publié" si l'article est publié
|
||||
if ('publish' === $post->post_status) {
|
||||
$post_states[] = __('Publié', 'metiers-patrimoine-theme'); // Affiche "Publié"
|
||||
$post_states[] = __('En ligne', 'metiers-patrimoine-theme'); // Affiche "Publié"
|
||||
}
|
||||
|
||||
// Ajouter votre statut personnalisé (ex : "offline") si c'est le cas
|
||||
if ('offline' === get_post_status($post->ID)) {
|
||||
$post_states[] = __('Offline', 'metiers-patrimoine-theme'); // Affiche "En attente"
|
||||
$post_states[] = __('Hors ligne', 'metiers-patrimoine-theme'); // Affiche "En attente"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -145,10 +258,6 @@ add_filter('display_post_states', 'add_custom_post_status', 10, 2);
|
|||
/* ----------------------------------------------------------------------
|
||||
REORDER ADMIN MENU & POST TYPE ORDER ON MENU BAR
|
||||
------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Activates the 'menu_order' filter and then hooks into 'menu_order'
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters WordPress' default menu order
|
||||
*/
|
||||
|
|
@ -247,57 +356,82 @@ function hide_wpml_language_metabox()
|
|||
// Applique la fonction pour masquer la meta box "Langue"
|
||||
// add_action('admin_menu', 'hide_wpml_language_metabox');
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
BODY CLASS
|
||||
------------------------------------------------------------------------*/
|
||||
|
||||
//** BODY CLASS FOR USER ROLE *//
|
||||
function add_user_role_to_admin_body_class($classes)
|
||||
{
|
||||
$current_user = wp_get_current_user();
|
||||
if (!empty($current_user->roles)) {
|
||||
foreach ($current_user->roles as $role) {
|
||||
$classes .= ' role-' . $role;
|
||||
$classes .= ' salut fred';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
// Applique le filtre pour ajouter la classe au corps de l'interface admin
|
||||
add_filter('admin_body_class', 'add_user_role_to_admin_body_class');
|
||||
|
||||
|
||||
//** BODY CLASS FOR POST STATUS *//
|
||||
function add_post_status_to_body_class($classes)
|
||||
{
|
||||
global $post;
|
||||
|
||||
if ($post && isset($post->post_status)) {
|
||||
$post_status = $post->post_status;
|
||||
$classes .= ' post-status-' . $post_status;
|
||||
// $classes[] = 'post-status-' . $post_status; // Ajoute une classe pour le statut du post
|
||||
write_log($post_status);
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
add_filter('admin_body_class', 'add_post_status_to_body_class');
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------
|
||||
RÉ-AJOUT DES ITEMS DE TAXONOMY DANS LE MENU, MAIS PAS SOUS ARTISANS MAIS À PART
|
||||
-----------------------------------------------------------------------------------*/
|
||||
|
||||
function add_custom_taxonomy_menu_item()
|
||||
{
|
||||
add_menu_page(
|
||||
'Métiers', // Titre de la page dans le navigateur
|
||||
'Métiers', // Texte à afficher dans le menu
|
||||
'edit_others_posts', // Capacité requise pour voir le menu
|
||||
'edit-tags.php?taxonomy=metiers&post_type=artisans', // URL de la taxonomie
|
||||
'', // Pas de fonction de rappel, car nous redirigeons
|
||||
'dashicons-tag', // Icône (facultatif)
|
||||
50 // Position dans le menu (facultatif)
|
||||
'Métiers',
|
||||
'Métiers',
|
||||
'edit_others_posts',
|
||||
'edit-tags.php?taxonomy=metiers&post_type=artisans',
|
||||
'',
|
||||
'dashicons-tag',
|
||||
50
|
||||
);
|
||||
add_menu_page(
|
||||
'Éléments du batiment', // Titre de la page dans le navigateur
|
||||
'Éléments du batiment', // Texte à afficher dans le menu
|
||||
'edit_others_posts', // Capacité requise pour voir le menu
|
||||
'edit-tags.php?taxonomy=elementsbatiments&post_type=artisans', // URL de la taxonomie
|
||||
'', // Pas de fonction de rappel, car nous redirigeons
|
||||
'dashicons-tag', // Icône (facultatif)
|
||||
58 // Position dans le menu (facultatif)
|
||||
'Éléments du batiment',
|
||||
'Éléments du batiment',
|
||||
'edit_others_posts',
|
||||
'edit-tags.php?taxonomy=elementsbatiments&post_type=artisans',
|
||||
'',
|
||||
'dashicons-tag',
|
||||
58
|
||||
);
|
||||
}
|
||||
|
||||
// Ajoute l'élément de menu lors de l'initialisation de l'admin
|
||||
add_action('admin_menu', 'add_custom_taxonomy_menu_item');
|
||||
|
||||
|
||||
function add_custom_update_button()
|
||||
{
|
||||
global $post;
|
||||
// function add_custom_update_button()
|
||||
// {
|
||||
// global $post;
|
||||
|
||||
if ($post->post_status === 'publish') {
|
||||
$update_url = admin_url('post.php?post=' . $post->ID . '&action=edit');
|
||||
echo '<a href="' . esc_url($update_url) . '" class="button button-secondary" style="margin-left:10px;">Mettre à jour l\'article</a>';
|
||||
}
|
||||
}
|
||||
add_action('post_submitbox_misc_actions', 'add_custom_update_button');
|
||||
// if ($post->post_status === 'publish') {
|
||||
// $update_url = admin_url('post.php?post=' . $post->ID . '&action=edit');
|
||||
// echo '<a href="' . esc_url($update_url) . '" class="button button-secondary" style="margin-left:10px;">Mettre à jour l\'article</a>';
|
||||
// }
|
||||
// }
|
||||
// add_action('post_submitbox_misc_actions', 'add_custom_update_button');
|
||||
|
|
|
|||
|
|
@ -26,33 +26,6 @@ function metiers_patrimoine_artisans_post_updater($post_id)
|
|||
add_action('acf/save_post', 'metiers_patrimoine_artisans_post_updater', 20);
|
||||
|
||||
|
||||
function metiers_patrimoine_chantiers_post_updater($post_id)
|
||||
{
|
||||
if (!$post_id || get_post_type() !== 'chantiers') return;
|
||||
|
||||
$my_post = array();
|
||||
$my_post['ID'] = $post_id;
|
||||
|
||||
$artisan = get_field("artisan", $post_id) ?? "";
|
||||
$chantier_name = get_field("chantier_name", $post_id) ?? "";
|
||||
$date = get_field("date", $post_id) ?? "";
|
||||
$localisation = get_field("localisation", $post_id) ?? "";
|
||||
|
||||
if (!$artisan || !$chantier_name) return;
|
||||
|
||||
$title = $artisan->post_title . " | " . $chantier_name;
|
||||
|
||||
if ($localisation && isset($localisation['city'])) {
|
||||
$title .= " | " . $localisation['city'];
|
||||
}
|
||||
if ($date) {
|
||||
$title .= " | " . $date;
|
||||
}
|
||||
$my_post['post_title'] = $title;
|
||||
wp_update_post($my_post);
|
||||
}
|
||||
add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
|
||||
|
||||
/* ---------------------------------------
|
||||
CUSTOM CONTENT AFTER POST TYPE TITLE
|
||||
------------------------------------------*/
|
||||
|
|
@ -77,9 +50,25 @@ add_action('edit_form_after_title', function () {
|
|||
<p>Statut :</p>
|
||||
<span class="status-state status-state--<?php echo $status_mdp['value']; ?> "><?php echo $status_mdp['label']; ?></span>
|
||||
</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>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('#set-offline-status').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Mettre à jour le champ caché du statut du post
|
||||
$('#post_status').val('offline');
|
||||
$('#post-status-display').text('Hors ligne');
|
||||
|
||||
// Sauvegarder immédiatement sans recharger
|
||||
$('#publish').trigger('click');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
});
|
||||
|
|
@ -94,9 +83,9 @@ add_action('add_meta_boxes', function () {
|
|||
'admin_artisan_chantier_list',
|
||||
'Chantiers réalisé par l\'entreprise',
|
||||
'render_custom_chantier_box_content',
|
||||
'artisans', // Post type
|
||||
'normal', // Contexte
|
||||
'default' // Priorité
|
||||
'artisans',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -140,7 +129,6 @@ function render_custom_chantier_box_content($post)
|
|||
}
|
||||
|
||||
/** REMOVE SUBMITDIV METABOX **/
|
||||
|
||||
add_action('admin_menu', 'remove_submit_div');
|
||||
function remove_submit_div()
|
||||
{
|
||||
|
|
@ -209,75 +197,18 @@ function prevent_meta_box_order($action)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------
|
||||
DELETE USER PREFERENCES
|
||||
------------------------------------------*/
|
||||
// function reset_user_metabox_order()
|
||||
// {
|
||||
// write_log('#############reset_user_metabox_order');
|
||||
// $user_id = get_current_user_id();
|
||||
// if ($user_id) {
|
||||
// delete_user_meta($user_id, 'meta-box-order_artisans');
|
||||
// }
|
||||
// }
|
||||
// add_action('load-post.php', 'reset_user_metabox_order');
|
||||
// add_action('load-post-new.php', 'reset_user_metabox_order');
|
||||
|
||||
|
||||
|
||||
|
||||
function my_custom_admin_button()
|
||||
function reset_user_metabox_order()
|
||||
{
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field('my_custom_action', 'my_custom_nonce'); ?>
|
||||
<input type="submit" name="my_custom_button" class="button button-primary" value="Exécuter l'action">
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function my_custom_options_page()
|
||||
{
|
||||
add_menu_page(
|
||||
'Options personnaliséessssssss',
|
||||
'Mes Optionsssssssssssssss',
|
||||
'manage_options',
|
||||
'my-custom-options',
|
||||
'my_custom_options_callback'
|
||||
);
|
||||
}
|
||||
|
||||
function my_custom_options_callback()
|
||||
{
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Page d’options personnalisée</h1>
|
||||
<?php my_custom_admin_button(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action('admin_menu', 'my_custom_options_page');
|
||||
|
||||
function my_custom_handle_button_action()
|
||||
{
|
||||
if (isset($_POST['my_custom_button']) && check_admin_referer('my_custom_action', 'my_custom_nonce')) {
|
||||
error_log('#############yalaa');
|
||||
// Mettre ici l’action à exécuter
|
||||
// update_option('my_custom_message', 'L\'action a été exécutée avec succès !');
|
||||
|
||||
|
||||
// Rediriger pour éviter la soumission multiple
|
||||
// wp_redirect(admin_url('admin.php?page=my-custom-options&action=success'));
|
||||
exit;
|
||||
$user_id = get_current_user_id();
|
||||
if ($user_id && !current_user_can('administrator')) {
|
||||
delete_user_meta($user_id, 'meta-box-order_artisans');
|
||||
}
|
||||
}
|
||||
add_action('admin_init', 'my_custom_handle_button_action');
|
||||
|
||||
|
||||
add_action('load-post.php', 'reset_user_metabox_order');
|
||||
add_action('load-post-new.php', 'reset_user_metabox_order');
|
||||
|
||||
|
||||
/* -------------------------------------------------
|
||||
|
|
@ -307,7 +238,6 @@ function add_last_modified_date_to_publish_box()
|
|||
// post_submit_meta_box($post, array('side' => 'core'));
|
||||
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
||||
------------------------------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,33 @@
|
|||
<?php
|
||||
|
||||
function metiers_patrimoine_chantiers_post_updater($post_id)
|
||||
{
|
||||
if (!$post_id || get_post_type() !== 'chantiers') return;
|
||||
|
||||
$my_post = array();
|
||||
$my_post['ID'] = $post_id;
|
||||
|
||||
$artisan = get_field("artisan", $post_id) ?? "";
|
||||
$chantier_name = get_field("chantier_name", $post_id) ?? "";
|
||||
$date = get_field("date", $post_id) ?? "";
|
||||
$localisation = get_field("localisation", $post_id) ?? "";
|
||||
|
||||
if (!$artisan || !$chantier_name) return;
|
||||
|
||||
$title = $artisan->post_title . " | " . $chantier_name;
|
||||
|
||||
if ($localisation && isset($localisation['city'])) {
|
||||
$title .= " | " . $localisation['city'];
|
||||
}
|
||||
if ($date) {
|
||||
$title .= " | " . $date;
|
||||
}
|
||||
$my_post['post_title'] = $title;
|
||||
wp_update_post($my_post);
|
||||
}
|
||||
add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
|
||||
|
||||
|
||||
/* -----------------------------------------
|
||||
EDIT ARTISAN LINK ON CHANTIER EDIT PAGE
|
||||
-----------------------------------------*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user