Ajout d’une métabox, avec sauvegarde des méta-données

class produits{

	public static function hooks(){
		add_action('add_meta_boxes',  array(__CLASS__, 'add_meta_boxes'));
		add_action('save_post',  array(__CLASS__, 'save_post'));
	}

	public static function add_meta_boxes(){

		add_meta_box('produit_metabox_id',
			'Fournisseur',
			array(__CLASS__, 'meta_box_content'),
			'post', //any post_type
			'normal',
			'high'
		);

	}

	public static function meta_box_content($post,$current_metabox){
		?>
		<!-- Contenu de la métabox (formulaire...) -->	
		<input type="text" name="ma_donnee" value="" />
		<?php
		wp_nonce_field('produit_meta_box_action','produit_meta_box_nonce_field');
	}

	public static function save_post($post_id) {
	
		// verify this came from the our screen and with proper authorization,
		// because save_post can be triggered at other times
		
		if ( !isset($_POST['produit_meta_box_nonce_field']) 
		     || !wp_verify_nonce( $_POST['produit_meta_box_nonce_field'], 'produit_meta_box_action') 
		){
			return $post_id;
		}
		
		// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
		// to do anything
		if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
			return $post_id;
		}
		
		// Check permissions and post type
		if ( !isset($_POST['post_type']) 
		     || $_POST['post_type'] != 'le-post-type' 
		     || !current_user_can('edit_post', $post_id)
		){
			return $post_id;
		}
	
		// Handle the case where we are dealing with a revision
		if( $parent_post_id = wp_is_post_revision($post_id) ){
			$post_id = $parent_post_id;
		}
		
		// OK, we're authenticated: we need to find and save the data
	
		if( isset($_POST['ma_donnee']) ){
			add_post_meta($post_id,'_ma_meta',$_POST['ma_donnee'],true) 
			or update_post_meta($post_id, '_ma_meta', $_POST['ma_donnee']);
		}
			
	}

}

produits::hooks();

http://codex.wordpress.org/Function_Reference/add_meta_box
http://codex.wordpress.org/Plugin_API/Action_Reference/save_post