updating post artisans admin columns
This commit is contained in:
parent
8c0c97dc9f
commit
ae8bd921a6
|
|
@ -17,12 +17,10 @@ function metiers_patrimoine_artisans_post_updater($post_id)
|
||||||
|
|
||||||
if ($address && isset($address['country'])) {
|
if ($address && isset($address['country'])) {
|
||||||
$stateGenericName = getGenericStateNameFromAcfStateName($address['state']) ?? "";
|
$stateGenericName = getGenericStateNameFromAcfStateName($address['state']) ?? "";
|
||||||
// write_log($stateGenericName);
|
|
||||||
// Met à jour le champ personnalisé 'country' avec la valeur du pays de l'adresse
|
// Met à jour le champ personnalisé 'country' avec la valeur du pays de l'adresse
|
||||||
update_post_meta($post_id, 'state', $stateGenericName);
|
update_post_meta($post_id, 'state', $stateGenericName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write_log($address);
|
|
||||||
wp_update_post($my_post);
|
wp_update_post($my_post);
|
||||||
}
|
}
|
||||||
add_action('acf/save_post', 'metiers_patrimoine_artisans_post_updater', 20);
|
add_action('acf/save_post', 'metiers_patrimoine_artisans_post_updater', 20);
|
||||||
|
|
@ -63,12 +61,35 @@ CUSTOM CODE FOR TITLE
|
||||||
add_action('edit_form_after_title', function () {
|
add_action('edit_form_after_title', function () {
|
||||||
// Vérifie si on est sur le bon post type
|
// Vérifie si on est sur le bon post type
|
||||||
$screen = get_current_screen();
|
$screen = get_current_screen();
|
||||||
|
$last_modified_date = get_the_modified_date('j F Y');
|
||||||
if ($screen && $screen->post_type === 'artisans') {
|
if ($screen && $screen->post_type === 'artisans') {
|
||||||
echo '<h1 class="admin-artisan-title">' . get_the_title() . '</h1>';
|
echo '<h1 class="admin-artisan-title">' . get_the_title() . '</h1>';
|
||||||
|
// echo '<p class="last-updated"> Dernière modification : ' . $last_modified_date . '</p>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function add_last_modified_date_to_publish_box()
|
||||||
|
{
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
// Vérifiez que vous êtes dans un post et que l'ID du post est valide
|
||||||
|
if ($post && $post->ID) {
|
||||||
|
// Récupérer la date de dernière modification
|
||||||
|
$dashicon = '<span class="dashicons dashicons-update"></span>';
|
||||||
|
$last_modified_date = get_the_modified_date('j F Y \à H:i', $post->ID);
|
||||||
|
|
||||||
|
// Afficher la date de dernière modification dans le panneau
|
||||||
|
echo '<div class="misc-pub-section">';
|
||||||
|
echo $dashicon . ' Dernière update : ';
|
||||||
|
echo $last_modified_date;
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('post_submitbox_start', 'add_last_modified_date_to_publish_box');
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------
|
/* ---------------------------
|
||||||
CUSTOM CHANTIER META BOX AT THE END OF THE PAGE
|
CUSTOM CHANTIER META BOX AT THE END OF THE PAGE
|
||||||
---------------------------*/
|
---------------------------*/
|
||||||
|
|
@ -125,13 +146,26 @@ function render_custom_chantier_box_content($post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
GESTION DE LA COLONNE METIERS DANS LA LISTE DES POSTS ARTISANS
|
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// AJOUT D'UNE COLONNE CUSTOM
|
function remove_rank_math_seo_column_for_artisans($columns)
|
||||||
|
{
|
||||||
|
if (isset($columns['rank_math_seo_details'])) {
|
||||||
|
unset($columns['rank_math_seo_details']);
|
||||||
|
}
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appliquer le filtre uniquement pour le post type "artisans"
|
||||||
|
add_filter('manage_artisans_posts_columns', 'remove_rank_math_seo_column_for_artisans', 20);
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// **** AJOUT DES COLONNES
|
||||||
function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
|
function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
|
||||||
{
|
{
|
||||||
global $current_screen;
|
global $current_screen;
|
||||||
|
|
@ -140,23 +174,42 @@ function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
|
||||||
if (isset($columns['date'])) {
|
if (isset($columns['date'])) {
|
||||||
unset($columns['date']);
|
unset($columns['date']);
|
||||||
}
|
}
|
||||||
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('metiers' => 'Métiers') + array_slice($columns, 2, count($columns) - 2, true);
|
$customColumns = array(
|
||||||
|
'metiers' => 'Métiers',
|
||||||
|
'elements' => 'Éléments du bâtiment',
|
||||||
|
'conseiller' => 'Conseiller',
|
||||||
|
'status' => 'Statut',
|
||||||
|
'lastmodified' => 'Dernière modification',
|
||||||
|
'onlinedate' => 'Mise en ligne'
|
||||||
|
);
|
||||||
|
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns + array_slice($columns, 2, count($columns) - 2, true);
|
||||||
return array_merge($new_admin_col_arrays);
|
return array_merge($new_admin_col_arrays);
|
||||||
}
|
}
|
||||||
add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns');
|
add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
GESTION DE LA VALEUR DE CHAQUE COLONNE
|
GESTION DE LA VALEUR DE CHAQUE COLONNE
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
||||||
{
|
{
|
||||||
|
|
||||||
$post_id = get_the_ID();
|
$post_id = get_the_ID();
|
||||||
|
|
||||||
|
if ($column == 'conseiller') {
|
||||||
|
$conseiller = get_field('conseiller', $post_id);
|
||||||
|
if (!$conseiller) return;
|
||||||
|
echo $conseiller['user_firstname'] . ' ' . $conseiller['user_lastname'];
|
||||||
|
}
|
||||||
|
if ($column == 'status') {
|
||||||
|
$status = get_field('mdp_status', $post_id);
|
||||||
|
if (!$status || !isset($status['label'])) return;
|
||||||
|
echo '<div class="status-state status-state--' . $status['value'] . '">' . $status['label'] . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($column == 'metiers') {
|
if ($column == 'metiers') {
|
||||||
$artisan = get_field('artisan', $post_id);
|
|
||||||
$terms = get_the_terms($post_id, 'metiers');
|
$terms = get_the_terms($post_id, 'metiers');
|
||||||
if ($terms) {
|
if ($terms) {
|
||||||
$parent_terms = array_filter($terms, function ($term) {
|
$parent_terms = array_filter($terms, function ($term) {
|
||||||
|
|
@ -168,7 +221,6 @@ function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
||||||
// }
|
// }
|
||||||
echo '<div class="admin-column-metiers-container">';
|
echo '<div class="admin-column-metiers-container">';
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
// write_log($term);
|
|
||||||
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
||||||
echo esc_html($term->name);
|
echo esc_html($term->name);
|
||||||
echo '</a>';
|
echo '</a>';
|
||||||
|
|
@ -178,15 +230,45 @@ function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
||||||
echo '<p class="no-results"> × </p>';
|
echo '<p class="no-results"> × </p>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($column == 'elements') {
|
||||||
|
$terms = get_the_terms($post_id, 'elementsbatiments');
|
||||||
|
if ($terms) {
|
||||||
|
$parent_terms = array_filter($terms, function ($term) {
|
||||||
|
return $term->parent == 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
echo '<div class="admin-column-metiers-container">';
|
||||||
|
foreach ($terms as $term) {
|
||||||
|
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
||||||
|
echo esc_html($term->name);
|
||||||
|
echo '</a>';
|
||||||
|
}
|
||||||
|
echo '</div >';
|
||||||
|
} else {
|
||||||
|
echo '<p class="no-results"> × </p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($column == 'lastmodified') {
|
||||||
|
// $last_modified_date = get_the_modified_date('j F Y \à H:i', $post_id);
|
||||||
|
$last_modified_date = get_the_modified_date('d/m/Y', $post_id);
|
||||||
|
if (!$last_modified_date) return;
|
||||||
|
echo $last_modified_date;
|
||||||
|
}
|
||||||
|
if ($column == 'onlinedate') {
|
||||||
|
$published_date = get_the_date('d/m/Y', $post_id);
|
||||||
|
if (!$published_date) return;
|
||||||
|
echo $published_date;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2);
|
add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2);
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
/* -------------------------------------------
|
GESTION DDU FILTRAGES PAR METIERS
|
||||||
CREATION DU DROPDOWN SELECT AVEC LES OPTIONS
|
------------------------------------------------------------------------*/
|
||||||
---------------------------------------------*/
|
// **** CREATION DU DROPDOWN SELECT AVEC LES OPTIONS
|
||||||
|
|
||||||
function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown()
|
function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown()
|
||||||
{
|
{
|
||||||
global $pagenow;
|
global $pagenow;
|
||||||
|
|
@ -218,11 +300,7 @@ function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown()
|
||||||
}
|
}
|
||||||
add_action('restrict_manage_posts', 'metiers_patrimoine_filter_posts_per_metiers_declare_dropdown');
|
add_action('restrict_manage_posts', 'metiers_patrimoine_filter_posts_per_metiers_declare_dropdown');
|
||||||
|
|
||||||
|
// **** FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
||||||
/* ------------------------------------------------------
|
|
||||||
FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
|
||||||
--------------------------------------------------------*/
|
|
||||||
|
|
||||||
function metiers_patrimoine_filter_post_by_metiers_query($query)
|
function metiers_patrimoine_filter_post_by_metiers_query($query)
|
||||||
{
|
{
|
||||||
global $pagenow;
|
global $pagenow;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user