Skip to content

Instantly share code, notes, and snippets.

@diije
Created June 12, 2013 12:54
Show Gist options
  • Save diije/5764998 to your computer and use it in GitHub Desktop.
Save diije/5764998 to your computer and use it in GitHub Desktop.
WordPress : metabox d'information sur l'auteur d'un article
<?php
if (is_admin()) {
//création de la metabox (id css, titre, fonction contenu, type de page, contexte, priorité)
function dfr_author_metabox() {
add_meta_box( 'dfr_author_metabox', 'Auteur', 'dfr_author_metabox_callback', 'post', 'side', 'high');
}
//affichage de la metabox
if (current_user_can('manage_options')) {
add_action('admin_init', 'dfr_author_metabox', 1);
}
//contenu de la metabox (html)
function dfr_author_metabox_callback() {
global $wpdb;
$author_ID = get_post($post->ID)->post_author;
$role = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} WHERE meta_key = '{$wpdb->prefix}capabilities' AND user_id = {$author_ID}");
$rarr = unserialize($role);
$roles = is_array($rarr) ? array_keys($rarr) : array('non-user');
?><ul>
<li><?php the_author_meta('nickname',$author_ID); ?> (<?php echo $roles[0]; ?>)</li>
<li><a href="<?php echo get_author_posts_url($author_ID); ?>"><?php the_author_posts(); ?> article(s) publié(s)</a></li>
<?php
if( function_exists( 'get_compteur' )) {
?><li><?php echo get_compteur($author_ID); ?> article(s) refusé(s)</li><?php
}
?>
<li><a href="<?php echo get_bloginfo('url'); ?>/wp-admin/user-edit.php?user_id=<?php echo $author_ID; ?>">Editer le profil</a></li>
</ul><?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment