working on metaboxes
This commit is contained in:
parent
1d9494b97d
commit
c6ea399704
|
|
@ -53,61 +53,54 @@ function metiers_patrimoine_chantiers_post_updater($post_id)
|
||||||
}
|
}
|
||||||
add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
|
add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
|
||||||
|
|
||||||
|
/* ---------------------------------------
|
||||||
|
CUSTOM CONTENT AFTER POST TYPE TITLE
|
||||||
/* ---------------------------
|
------------------------------------------*/
|
||||||
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
|
|
||||||
$screen = get_current_screen();
|
$screen = get_current_screen();
|
||||||
$last_modified_date = get_the_modified_date('j F Y');
|
|
||||||
|
$status_mdp = get_field('mdp_status', get_the_ID());
|
||||||
|
$post_status = get_post_status();
|
||||||
|
$translatedStatus = translate_wordpress_online_statuses($post_status);
|
||||||
|
|
||||||
if ($screen && $screen->post_type === 'artisans') {
|
if ($screen && $screen->post_type === 'artisans') {
|
||||||
echo '<h1 class="admin-artisan-title">' . get_the_title() . '</h1>';
|
?>
|
||||||
// echo '<p class="last-updated"> Dernière modification : ' . $last_modified_date . '</p>';
|
<h1 class="admin-artisan-title"><?php echo get_the_title() ?></h1>
|
||||||
|
<div id="top-status" class="top-status">
|
||||||
|
|
||||||
|
<div class="state-container">
|
||||||
|
<p>État :</p>
|
||||||
|
<span class="post-state post-state--<?php echo $post_status; ?>"><?php echo $translatedStatus; ?></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="state-container">
|
||||||
|
<p>Statut :</p>
|
||||||
|
<span class="status-state status-state--<?php echo $status_mdp['value']; ?> "><?php echo $status_mdp['label']; ?></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------
|
||||||
function add_last_modified_date_to_publish_box()
|
METABOXES
|
||||||
{
|
------------------------------------------*/
|
||||||
global $post;
|
/** ENQUEUE CUSTOM CHANTIER META BOX AT THE END OF THE PAGE **/
|
||||||
|
|
||||||
// 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
|
|
||||||
---------------------------*/
|
|
||||||
add_action('add_meta_boxes', function () {
|
add_action('add_meta_boxes', function () {
|
||||||
// Ajout de la metabox uniquement pour le post type 'artisans'
|
|
||||||
add_meta_box(
|
add_meta_box(
|
||||||
'admin_artisan_chantier_list', // ID de la metabox
|
'admin_artisan_chantier_list',
|
||||||
'Chantiers réalisé par l\'entreprise', // Titre de la metabox
|
'Chantiers réalisé par l\'entreprise',
|
||||||
'render_custom_chantier_box_content', // Fonction de rendu
|
'render_custom_chantier_box_content',
|
||||||
'artisans', // Post type
|
'artisans', // Post type
|
||||||
'normal', // Contexte
|
'normal', // Contexte
|
||||||
'low' // Priorité
|
'default' // Priorité
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/** RENDER CHANTIER METABOX **/
|
||||||
* Fonction de rendu du contenu de la metabox.
|
|
||||||
*/
|
|
||||||
function render_custom_chantier_box_content($post)
|
function render_custom_chantier_box_content($post)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -146,6 +139,175 @@ function render_custom_chantier_box_content($post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** REMOVE SUBMITDIV METABOX **/
|
||||||
|
|
||||||
|
add_action('admin_menu', 'remove_submit_div');
|
||||||
|
function remove_submit_div()
|
||||||
|
{
|
||||||
|
remove_meta_box('submitdiv', 'artisans', 'side');
|
||||||
|
remove_meta_box('postimagediv', 'artisans', 'normal');
|
||||||
|
remove_meta_box('postimagediv', 'artisans', 'side');
|
||||||
|
remove_meta_box('postimagediv', 'artisans', 'advanced');
|
||||||
|
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
$metaboxes = get_user_meta($user->ID, 'metaboxhidden_artisans', true);
|
||||||
|
$metabox_order = get_user_meta($user->ID, 'meta-box-order_artisans', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** UPDATE USER METABOX PREFERENCES WITH MANUAL ARRAY **/
|
||||||
|
function set_user_metabox_order($user_id)
|
||||||
|
{
|
||||||
|
$new_order = [
|
||||||
|
'acf_after_title' => '',
|
||||||
|
'side' => 'postimagediv,icl_div',
|
||||||
|
'normal' => 'acf-group_670d265c6ec0e,admin_artisan_chantier_list,acf-group_67581cdaf3262,acf-group_672358433051b,submitdiv,slugdiv,revisionsdiv',
|
||||||
|
'advanced' => 'rank_math_metabox',
|
||||||
|
];
|
||||||
|
update_user_meta($user_id, 'meta-box-order_artisans', $new_order);
|
||||||
|
|
||||||
|
$metaboxes_hidden = get_user_meta($user_id, 'metaboxhidden_artisans', true);
|
||||||
|
if ($metaboxes_hidden === false) return;
|
||||||
|
|
||||||
|
$newArrray = array_merge($metaboxes_hidden, ['postimagediv', 'icldiv']);
|
||||||
|
update_user_meta($user_id, 'metaboxhidden_artisans', $newArrray);
|
||||||
|
}
|
||||||
|
// set_user_metabox_order(get_current_user_id());
|
||||||
|
add_action('admin_init', 'set_user_metabox_order');
|
||||||
|
|
||||||
|
/** RE-ENQUEUE SUBMITDIV METABOX **/
|
||||||
|
add_action('do_meta_boxes', 'reinsert_submitdiv_meta_box');
|
||||||
|
function reinsert_submitdiv_meta_box()
|
||||||
|
{
|
||||||
|
add_meta_box(
|
||||||
|
'submitdiv',
|
||||||
|
__('Sauver'),
|
||||||
|
'post_submit_meta_box',
|
||||||
|
'artisans',
|
||||||
|
'normal',
|
||||||
|
'low'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** DE ACTIVATE SCREEN OPTIONS **/
|
||||||
|
function de_activite_screen_options()
|
||||||
|
{
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
if ($current_user->roles[0] !== 'administrator') {
|
||||||
|
add_filter('screen_options_show_screen', '__return_false');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('admin_init', 'de_activite_screen_options');
|
||||||
|
|
||||||
|
|
||||||
|
/** FORBID SAVING USER REORGANISATION ON DRAG **/
|
||||||
|
add_action('check_ajax_referer', 'prevent_meta_box_order');
|
||||||
|
function prevent_meta_box_order($action)
|
||||||
|
{
|
||||||
|
if ('meta-box-order' == $action /* && $wp_user == 'santa claus' */) {
|
||||||
|
die('-1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('admin_init', 'my_custom_handle_button_action');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------------------
|
||||||
|
ADD LAST MODIFIED DATE TO SUBMIT DIV PUBLISH BOX
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
|
||||||
|
// post_submit_meta_box($post, array('side' => 'core'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
@ -266,7 +428,7 @@ add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_h
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
GESTION DDU FILTRAGES PAR METIERS
|
GESTION DU 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()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user