Created
February 3, 2012 01:10
-
-
Save fjarrett/1726870 to your computer and use it in GitHub Desktop.
Auto-Tagging with Author Username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :-)