Created
June 1, 2012 00:06
-
-
Save danielbachhuber/2847390 to your computer and use it in GitHub Desktop.
Automatically assign a co-author based on current user
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 | |
/** | |
* Automatically assign a co-author based on current user's usermeta value | |
* This code is untested and for demonstration purposes | |
* | |
* @see http://wordpress.org/support/topic/plugin-co-authors-plus-dynamically-assign-co-authors?replies=1 | |
*/ | |
add_action( 'save_post', 'capx_auto_assign_author' ); | |
function capx_auto_assign_author( $post_id ) { | |
global $coauthors_plus; | |
if ( !is_object( $coauthors_plus ) ) | |
return; | |
// Get the current user, see if they have a parent_user, | |
// and automatically assign the parent user if it exists | |
$current_user = wp_get_current_user(); | |
if ( $parent_user_login = get_user_meta( $current_user->ID, 'parent_user', true ) ) | |
$coauthors_plus->add_coauthors( $post_id, array( $parent_user_login ), true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment