Hi Nadine!
The plugin should look for a username in WordPress that matches the username in docs. This works best with Google Apps. So if your email address is [email protected], you’d want your WordPress username to be me. In my case, my email address is [email protected], so my WordPress username is wdavis.
You can modify the default behavior in a few ways, though.
I should warn you these code snippets are untested, but they should get you pointed in the right direction.
You can set a default author for each post like so:
add_filter( 'pre_docs_to_wp_insert', 'dtwp_fix_author' );
function dtwp_fix_author( $post_array = array() ) {
//Where post_author equals the ID of the default author
$post_array[ 'post_author' ] = 1;
return $post_array;
}
At the BDN, we use a comment to override the default author. We simply leave a comment like this:
byline:username
You can do that if you’re using the clean extender like so:
add_filter( 'pre_docs_to_wp_insert', 'dtwp_byline_from_comments', 25, 1 );
function dtwp_byline_from_comments( $post_array ) {
$comments = explode( "</span>", $post_array[ 'custom_fields' ][ '_gdocs_comments' ] );
foreach( $comments as $line ) {
if( substr( trim( strip_tags( strtolower( $line ) ) ), 0, 7 ) == "byline:" )
$post_array[ 'custom_fields' ][ 'byline' ] = trim( str_ireplace( 'byline:', '', strip_tags( $line ) ) );
}
if( !empty( $post_array[ 'custom_fields' ][ 'byline' ] ) && false != ( $user = get_user_by( 'login', $post_array[ 'custom_fields' ][ 'byline' ] ) && is_object( $user ) ) ) {
$post_array[ 'post_author' ] = $user->ID;
unset( $post_array[ 'custom_fields' ][ 'byline' ] );
}
return $post_array;
}
Let me know if you have any questions.