Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Automatically assign a co-author based on current user
<?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
Something went wrong with that request. Please try again.