Compare commits

..

15 Commits

Author SHA1 Message Date
f0781cd77d CHORE updated .gitignore to include vendor directory
All checks were successful
continuous-integration/drone/push Build is passing
2025-04-07 12:22:11 +02:00
dc7284218b FEAT added styles to hide element and custom button on editor and author profile 2025-04-07 12:21:32 +02:00
7d2de1fe6d FEAT Styling the custom save post button 2025-04-07 12:21:08 +02:00
b1cac05b3c FEAT added styles to hidden element and custom button on editor and author profile 2025-04-07 12:20:40 +02:00
d41ec9fa73 FIX updated query logic to handle 'conseiller' key checks for both non-existence and empty values 2025-04-07 12:19:42 +02:00
ae7be6a78a FIX updated permissions for 'Gestion' page to allow authors access 2025-04-07 12:19:15 +02:00
68d9462d22 FEAT commenting code due to return button handled elsewhere 2025-04-07 12:18:55 +02:00
33c6139a0e FEAT handling return to button 2025-04-07 12:18:16 +02:00
51312bf17a FEAT handling return to button 2025-04-07 12:17:46 +02:00
1773c57871 FEAT Developping a custom save post button on top of the page 2025-04-07 12:16:51 +02:00
54f4505480 FIX Optimising comments 2025-04-07 12:15:55 +02:00
d97b5d9f3c FIX Optimising comments 2025-04-07 12:15:46 +02:00
d531a46fad FEAT Handling conseiller custom role 2025-04-07 12:14:52 +02:00
9a87cfb024 FIX handling permissions for the screen export des donnees 2025-04-07 12:14:08 +02:00
7baece3f6b CLEAN cleaning unused commented code 2025-04-07 12:13:14 +02:00
10 changed files with 187 additions and 54 deletions

3
.gitignore vendored
View File

@ -13,4 +13,5 @@ init_script.sh
.env-prod
.env_dev
.env_prod
Makefile
Makefile
/vendor/

View File

@ -4,6 +4,7 @@
require_once(__DIR__ . '/includes/errorlog.php');
require_once(__DIR__ . '/includes/init.php');
require_once(__DIR__ . '/includes/roles.php');
require_once(__DIR__ . '/includes/post_types.php');
require_once(__DIR__ . '/includes/artisans.php');
require_once(__DIR__ . '/includes/artisans-columns-filters.php');

View File

@ -26,19 +26,6 @@ function save_acf_post_mdp_status($post_id)
}
add_action('acf/save_post', 'save_acf_post_mdp_status');
// // apply the abose meta setting for all posts
// function apply_acf_post_mdp_status_for_all_posts()
// {
// $posts = get_posts(array(
// 'post_type' => 'artisans',
// 'numberposts' => -1
// ));
// foreach ($posts as $post) {
// save_acf_post_mdp_status($post->ID);
// }
// }
// add_action('init', 'apply_acf_post_mdp_status_for_all_posts');
/* ----------------------------------------------------------------------
DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
@ -166,21 +153,11 @@ function metiers_patrimoine_filter_posts_declare_dropdowns()
$metiers_by_parent = getAllMetiersTermsByParents();
$batiments_by_parent = getAllBatimentsTermsByParents();
$conseillers = get_users();
// $mdp_status_field = get_field_object('mdp_status');
// $mdp_status_choices = isset($mdp_status_field['choices']) ? $mdp_status_field['choices'] : array();
$mdp_status_datar = acf_get_field("mdp_status",);
$mdp_status_datas = get_field_object("mdp_status");
// write_log($typenow);
// write_log($mdp_status_datar);
// write_log($mdp_status_datas);
$mdp_status_choices = isset($mdp_status_datas['choices']) ? $mdp_status_datas['choices'] : null;
// write_log($mdp_status_choices);
$meta_key = 'mdp_status';
$values = get_posts([
'post_type' => 'artisans',
@ -250,7 +227,7 @@ function metiers_patrimoine_filter_posts_declare_dropdowns()
?>
</select>
<select name="mdpstatus">
<option value="" class="please-select"><?php _e('Statut', 'metiers-patrimoine-theme'); ?></option>
<option value="" class="please-select"><?php _e('Statut de travail', 'metiers-patrimoine-theme'); ?></option>
<?php
$is_current = isset($_GET['mdpstatus']) ? $_GET['mdpstatus'] : '';

View File

@ -1,8 +1,9 @@
<?php
/* ---------------------------------------
ARTISANS POST TITLE & ADRESS STATE UPDATER
------------------------------------------*/
function metiers_patrimoine_artisans_post_updater($post_id)
{
if (!$post_id) return;
$my_post = array();
@ -17,7 +18,6 @@ function metiers_patrimoine_artisans_post_updater($post_id)
if ($address && isset($address['country'])) {
$stateGenericName = getGenericStateNameFromAcfStateName($address['state']) ?? "";
// Met à jour le champ personnalisé 'country' avec la valeur du pays de l'adresse
update_post_meta($post_id, 'state', $stateGenericName);
}
@ -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,20 +87,30 @@ 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>
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');
$('#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');
});
});
@ -117,6 +159,10 @@ function render_custom_chantier_box_content($post)
if ($chantiers->have_posts()) {
$artisan_id = get_the_ID();
$return_to = get_edit_post_link($artisan_id);
echo '<h3> Chantiers réalisé par l\'entreprise </h3>';
echo '<ul>';
while ($chantiers->have_posts()) {
@ -125,11 +171,11 @@ function render_custom_chantier_box_content($post)
echo '<li><a href="' . get_edit_post_link() . '"> <img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/document-inspect.svg' . ' /> ' . $chantier_name . '</a></li>';
}
echo '</ul>';
echo '<a href="' . admin_url('post-new.php?post_type=chantiers') . '" class="new-chantier">Ajouter un chantier</a>';
echo '<a href="' . admin_url('post-new.php?post_type=chantiers&return_to=' . urlencode($return_to)) . '" class="new-chantier">Ajouter un chantier</a>';
} else {
echo '<h3> Chantiers réalisés</h3>';
echo '<p class="no-results">Aucun chantier pour cette entreprise</p>';
echo '<a href="' . admin_url('post-new.php?post_type=chantiers') . '" class="new-chantier">Ajouter un chantier</a>';
echo '<a href="' . admin_url('post-new.php?post_type=chantiers&return_to=' . urlencode($return_to)) . '" class="new-chantier">Ajouter un chantier</a>';
}
}

View File

@ -32,22 +32,22 @@ add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
EDIT ARTISAN LINK ON CHANTIER EDIT PAGE
-----------------------------------------*/
add_action('acf/render_field', function ($field) {
// Vérifiez si le champ est celui que vous voulez personnaliser
if ($field['key'] === 'field_6719065f58122') {
if (did_action('acf/render_field/key=field_6719065f58122') % 2 === 0) {
return;
}
$field['rendered'] = true;
// add_action('acf/render_field', function ($field) {
// // Vérifiez si le champ est celui que vous voulez personnaliser
// if ($field['key'] === 'field_6719065f58122') {
// if (did_action('acf/render_field/key=field_6719065f58122') % 2 === 0) {
// return;
// }
// $field['rendered'] = true;
$linked_post_id = get_field($field['key']);
// $linked_post_id = get_field($field['key']);
if ($linked_post_id) {
$edit_link = get_edit_post_link($linked_post_id);
echo '<a href="' . esc_url($edit_link) . '" class="edit-fiche-artisan-link"><img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' . ' /> Voir la fiche de l\'artisan </a>';
}
}
}, 10, 1);
// if ($linked_post_id) {
// $edit_link = get_edit_post_link($linked_post_id);
// echo '<a href="' . esc_url($edit_link) . '" class="edit-fiche-artisan-link"><img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' . ' /> Voir la fiche de l\'artisan </a>';
// }
// }
// }, 10, 1);
@ -119,3 +119,25 @@ function metiers_patrimoine_orderby($query)
}
}
add_action('pre_get_posts', 'metiers_patrimoine_orderby');
/* ---------------------------------------
CUSTOM CONTENT AFTER POST TYPE TITLE
------------------------------------------*/
add_action('edit_form_after_title', function () {
$screen = get_current_screen();
if ($screen && $screen->post_type === 'chantiers') {
$linked_artisan_id = get_field('artisan');
$return_to = isset($_GET['return_to']) ? $_GET['return_to'] : '';
$edit_artisan_link = get_edit_post_link($linked_artisan_id);
?>
<?php if ($return_to) : ?>
<a href="<?php echo esc_url($return_to) ?>" class="edit-fiche-artisan-link"><img src='<?php echo get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' ?>' /> Voir la fiche de l'artisan </a>
<?php elseif ($linked_artisan_id) : ?>
<a href="<?php echo esc_url($edit_artisan_link) ?>" class="edit-fiche-artisan-link"><img src='<?php echo get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' ?>' /> Voir la fiche de l'artisan </a>
<?php endif; ?>
<?php
}
});

View File

@ -8,7 +8,7 @@ function export_datas_page_in_menu()
add_menu_page(
'Export de données', // page <title>Title</title>
'Export', // link text
'edit_posts', // user capabilities
'export_artisans_datas', // user capabilities - changé pour n'autoriser que les éditeurs et supérieurs
'export_datas', // page slug
'export_datas_page_callback', // this function prints the page content
'dashicons-external', // icon (from Dashicons for example)

View File

@ -10,7 +10,7 @@ function add_page_gestion()
add_menu_page(
'Gestion', // Titre de la page
'Gestion', // Titre dans le menu
'edit_pages',
'edit_posts', // Changé de edit_pages à edit_posts pour permettre aux auteurs d'accéder
'gestion-artisans', // Slug du menu
'afficher_page_gestion_artisans', // Fonction de callback
$icon, // Icône

54
includes/roles.php Normal file
View File

@ -0,0 +1,54 @@
<?php
/* -----------------------------------------------------------
Création du rôle conseiller
-----------------------------------------------------------*/
function create_conseiller_role()
{
// Récupérer les capacités du rôle author
$author_role = get_role('author');
$capabilities = $author_role->capabilities;
$capabilities['export_artisans_datas'] = false;
$capabilities['edit_others_posts'] = true;
$capabilities['publish_posts'] = true;
$capabilities['read'] = true;
$capabilities['upload_files'] = true;
// Capacités pour la gestion des médias
// $capabilities['edit_posts'] = true;
// $capabilities['delete_posts'] = true;
// $capabilities['edit_published_posts'] = true;
// $capabilities['delete_published_posts'] = true;
// $capabilities['edit_others_posts'] = false; // Ne peut pas éditer les posts des autres
// $capabilities['delete_others_posts'] = false; // Ne peut pas supprimer les posts des autres
// $capabilities['edit_attachments'] = true; // Peut éditer ses propres médias
// $capabilities['delete_attachments'] = true; // Peut supprimer ses propres médias
// $capabilities['edit_others_attachments'] = false; // Ne peut pas éditer les médias des autres
// $capabilities['delete_others_attachments'] = false; // Ne peut pas supprimer les médias des autres
add_role('conseiller', 'Conseiller', $capabilities);
}
add_action('init', 'create_conseiller_role');
/* -----------------------------------------------------------
Masquer les widgets du tableau de bord pour le rôle conseiller
-----------------------------------------------------------*/
function hide_dashboard_widgets_for_conseiller()
{
$user = wp_get_current_user();
if (in_array('conseiller', (array) $user->roles)) {
remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
remove_meta_box('dashboard_activity', 'dashboard', 'normal');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
remove_meta_box('dashboard_primary', 'dashboard', 'side');
remove_meta_box('dashboard_secondary', 'dashboard', 'side');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
}
}
add_action('wp_dashboard_setup', 'hide_dashboard_widgets_for_conseiller');

View File

@ -602,7 +602,10 @@ select[data-enpassusermodified='yes'] {
#submitdiv .handle-order-higher,
#submitdiv .handle-order-lower,
#submitdiv #preview-action,
#footer-left {
#footer-left,
.tablenav .bulkactions,
.check-column,
.row-actions {
@apply !hidden;
}
.post-type-artisans #post-body {
@ -610,6 +613,16 @@ select[data-enpassusermodified='yes'] {
}
}
.role-conseiller {
#menu-media,
#menu-tools,
#toplevel_page_edit-tags-taxonomy-metiers-post_type-artisans,
#toplevel_page_edit-tags-taxonomy-elementsbatiments-post_type-artisans,
li a[href='my-sites.php'] {
@apply !hidden;
}
}
.subsubsub .mine,
.subsubsub .pillar_content {
@apply hidden;
@ -640,6 +653,9 @@ select[data-enpassusermodified='yes'] {
#set-online-status {
@apply text-white border-none rounded-xl px-4 !py-1 ml-auto;
}
#save-post-custom {
@apply ml-auto rounded-xl bg-amber-600 border-none text-white px-4 !py-1;
}
#set-offline-status {
@apply bg-neutral-600;
@ -661,3 +677,11 @@ select[data-enpassusermodified='yes'] {
@apply hidden;
}
}
/* -----------------------------------------------------------
Admin styles
-----------------------------------------------------------*/
/* Masquer le lien "Mes sites" dans le menu */
li a[href='my-sites.php'] {
@apply !hidden;
}

View File

@ -30,8 +30,16 @@ $queryAllUnaffectedArtisansByStatus = array(
'compare' => '='
),
array(
'key' => 'conseiller',
'compare' => 'NOT EXISTS'
'relation' => 'OR',
array(
'key' => 'conseiller',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'conseiller',
'value' => '',
'compare' => '='
)
)
)
);