Skip to content

Instantly share code, notes, and snippets.

@fjarrett
Created February 3, 2012 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarrett/1726870 to your computer and use it in GitHub Desktop.
Save fjarrett/1726870 to your computer and use it in GitHub Desktop.
Auto-Tagging with Author Username
<?php
function wpized_tag_post_with_author_username($post_id) {
if($parent = wp_is_post_revision($post_id)) {
$post_id = $parent;
}
$post = get_post($post_id);
if($post->post_type != 'post') {
return;
}
$user = new WP_User($post->post_author);
if(!in_array('administrator', $user->roles)) {
wp_set_post_terms($post_id, $user->user_login, 'post_tag', true);
}
}
add_action('save_post', 'wpized_tag_post_with_author_username');
?>
@westonruter
Copy link

Might want to do if( !in_array('administrator', $user->roles) ) just in case they have more than one role, which I've never seen, but still :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment