Is no one else having this issue? It’s really odd. I have created 4 or 5 new documents and each one moved to wordpress with a different post author. Baffling.
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 me@myapps.domain, you’d want your WordPress username to be me. In my case, my email address is wdavis@bangordailynews.com, 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.
Well an email address is difficult to change and the WP user name is impossible to change. Given that I’m new to coding, I’m not confident about where to put the above snippet or what to do with it. (I don’t use the clean extender.)
In the meantime, we are manually changing the author of each post. (Not very efficient.)
If you, or someone, can give me the step-by-step, I’d be grateful. If not, I understand.
Thanks.