1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/****************************************************/
/**************** AJOUT DU CHAMP URL ****************/
/****************************************************/
/*D'abord masquer les champs personnalisés par défaut*/
function baw_remove_custom_field_meta_boxes() {
remove_post_type_support( 'carousel','custom-fields' );
}
add_action('init','baw_remove_custom_field_meta_boxes');
/*Ajouter le champ URL*/
function add_custom_meta_box()
{
add_meta_box("url-meta-box", "Adresse du site", "custom_meta_box_markup", "carousel", "side", "high", null);
}
add_action("add_meta_boxes", "add_custom_meta_box");
/*Affichage du Champ URL*/
function custom_meta_box_markup($object)
{
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<div>
<!-- <label for="url-box-text">URL</label> -->
<input style="width:100%" id="url_site_carousel" placeholder="Exemple: https://www.the-web.fr" name="url_site_carousel" type="text" value="<?php echo get_post_meta($object->ID, "url_site_carousel", true); ?>">
</div>
<?php
}
/*Enregistrement du champ URL*/
function save_custom_meta_box($post_id, $post, $update)
{
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
return $post_id;
if(!current_user_can("edit_post", $post_id))
return $post_id;
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
return $post_id;
$slug = "carousel";
if($slug != $post->post_type)
return $post_id;
$meta_box_text_value = "";
if(isset($_POST["url_site_carousel"]))
{
$meta_box_text_value = $_POST["url_site_carousel"];
}
update_post_meta($post_id, "Adresse du site", $meta_box_text_value);
}
add_action("save_post", "save_custom_meta_box", 10, 3); |
Partager